diff options
author | Kegsay <kegan@matrix.org> | 2020-07-24 10:33:41 +0100 |
---|---|---|
committer | GitHub <noreply@github.com> | 2020-07-24 10:33:41 +0100 |
commit | af5b4d1f6bb0c3479331da965211d6175b012c9e (patch) | |
tree | dab3f5299cbdb5dd3a8a4e11daaea4c54b206e02 /currentstateserver/internal | |
parent | 98f2f09bb46f8bd126214f7874065d6b311bdeba (diff) |
Modify QuerySharedUsers to handle counts/include/exclude (#1219)
* Modify QuerySharedUsers to handle counts/include/exclude
We will need this functionality when working out whether to
send device list changes to users who have joined/left a room.
* Linting
Diffstat (limited to 'currentstateserver/internal')
-rw-r--r-- | currentstateserver/internal/api.go | 19 |
1 files changed, 18 insertions, 1 deletions
diff --git a/currentstateserver/internal/api.go b/currentstateserver/internal/api.go index e945d0c1..c581c524 100644 --- a/currentstateserver/internal/api.go +++ b/currentstateserver/internal/api.go @@ -74,10 +74,27 @@ func (a *CurrentStateInternalAPI) QuerySharedUsers(ctx context.Context, req *api if err != nil { return err } + roomIDs = append(roomIDs, req.IncludeRoomIDs...) + excludeMap := make(map[string]bool) + for _, roomID := range req.ExcludeRoomIDs { + excludeMap[roomID] = true + } + // filter out excluded rooms + j := 0 + for i := range roomIDs { + // move elements to include to the beginning of the slice + // then trim elements on the right + if !excludeMap[roomIDs[i]] { + roomIDs[j] = roomIDs[i] + j++ + } + } + roomIDs = roomIDs[:j] + users, err := a.DB.JoinedUsersSetInRooms(ctx, roomIDs) if err != nil { return err } - res.UserIDs = users + res.UserIDsToCount = users return nil } |