~emersion/soju-dev

service: user status: accept username filter v2 APPLIED

delthas: 1
 service: user status: accept username filter

 1 files changed, 21 insertions(+), 9 deletions(-)
Export patchset (mbox)
How do I use this?

Copy & paste the following snippet into your terminal to import this patchset into git:

curl -s https://lists.sr.ht/~emersion/soju-dev/patches/53204/mbox | git am -3
Learn more about email & git

[PATCH v2] service: user status: accept username filter Export this patch

This is useful for getting information about a particular user,
especially when the server has more than the max amount of users
returned by the command.
---
 service.go | 30 +++++++++++++++++++++---------
 1 file changed, 21 insertions(+), 9 deletions(-)

diff --git a/service.go b/service.go
index a39b276..cda7eec 100644
--- a/service.go
+++ b/service.go
@@ -279,6 +279,7 @@ func init() {
		"user": {
			children: serviceCommandSet{
				"status": {
					usage:  "[username]",
					desc:   "show a list of users and their current status",
					handle: handleUserStatus,
					admin:  true,
@@ -900,23 +901,34 @@ func handleServiceSASLReset(ctx *serviceContext, params []string) error {
}

func handleUserStatus(ctx *serviceContext, params []string) error {
	if len(params) != 0 {
		return fmt.Errorf("expected no argument")
	if len(params) > 1 {
		return fmt.Errorf("expected 0 or 1 argument")
	}

	// Limit to a small amount of users to avoid sending
	// thousands of messages on large instances.
	users := make([]database.User, 0, 50)
	var n int

	ctx.srv.lock.Lock()
	n := len(ctx.srv.users)
	for _, user := range ctx.srv.users {
		if len(users) == cap(users) {
			break
	if len(params) == 0 {
		ctx.srv.lock.Lock()
		n = len(ctx.srv.users)
		for _, user := range ctx.srv.users {
			if len(users) == cap(users) {
				break
			}
			users = append(users, user.User)
		}
		ctx.srv.lock.Unlock()
	} else {
		username := params[0]
		u := ctx.srv.getUser(username)
		if u == nil {
			return fmt.Errorf("unknown username %q", username)
		}
		users = append(users, user.User)
		users = append(users, u.User)
		n = 1
	}
	ctx.srv.lock.Unlock()

	for _, user := range users {
		var attrs []string

base-commit: 3a4e54bc45bdd85e5173f5c945d5554573d6d89d
-- 
2.38.0
Pushed, thanks!