aboutsummaryrefslogtreecommitdiff
path: root/syncapi
diff options
context:
space:
mode:
authorKegsay <kegan@matrix.org>2020-07-31 14:40:45 +0100
committerGitHub <noreply@github.com>2020-07-31 14:40:45 +0100
commitb5cb1d153458ad83abdfbebed7405dd9da159cb8 (patch)
tree5b5a35ff4805c2f2f071c6c51d095492406db750 /syncapi
parenta7e67e65a8662387f1a5ba6860698743f9dbd60f (diff)
Fix edge cases around device lists (#1234)
* Fix New users appear in /keys/changes * Create blank device keys when logging in on a new device * Add PerformDeviceUpdate and fix a few bugs - Correct device deletion query on sqlite - Return no keys on /keys/query rather than an empty key * Unbreak sqlite properly * Use a real DB for currentstateserver integration tests * Race fix
Diffstat (limited to 'syncapi')
-rw-r--r--syncapi/internal/keychange.go33
-rw-r--r--syncapi/sync/requestpool.go2
2 files changed, 34 insertions, 1 deletions
diff --git a/syncapi/internal/keychange.go b/syncapi/internal/keychange.go
index cb4fca7d..0272ffc0 100644
--- a/syncapi/internal/keychange.go
+++ b/syncapi/internal/keychange.go
@@ -16,6 +16,7 @@ package internal
import (
"context"
+ "strings"
"github.com/Shopify/sarama"
currentstateAPI "github.com/matrix-org/dendrite/currentstateserver/api"
@@ -88,6 +89,16 @@ func DeviceListCatchup(
if !userSet[userID] {
res.DeviceLists.Changed = append(res.DeviceLists.Changed, userID)
hasNew = true
+ userSet[userID] = true
+ }
+ }
+ // if the response has any join/leave events, add them now.
+ // TODO: This is sub-optimal because we will add users to `changed` even if we already shared a room with them.
+ for _, userID := range membershipEvents(res) {
+ if !userSet[userID] {
+ res.DeviceLists.Changed = append(res.DeviceLists.Changed, userID)
+ hasNew = true
+ userSet[userID] = true
}
}
return hasNew, nil
@@ -219,3 +230,25 @@ func membershipEventPresent(events []gomatrixserverlib.ClientEvent, userID strin
}
return false
}
+
+// returns the user IDs of anyone joining or leaving a room in this response. These users will be added to
+// the 'changed' property because of https://matrix.org/docs/spec/client_server/r0.6.1#id84
+// "For optimal performance, Alice should be added to changed in Bob's sync only when she adds a new device,
+// or when Alice and Bob now share a room but didn't share any room previously. However, for the sake of simpler
+// logic, a server may add Alice to changed when Alice and Bob share a new room, even if they previously already shared a room."
+func membershipEvents(res *types.Response) (userIDs []string) {
+ for _, room := range res.Rooms.Join {
+ for _, ev := range room.Timeline.Events {
+ if ev.Type == gomatrixserverlib.MRoomMember && ev.StateKey != nil {
+ if strings.Contains(string(ev.Content), `"join"`) {
+ userIDs = append(userIDs, *ev.StateKey)
+ } else if strings.Contains(string(ev.Content), `"leave"`) {
+ userIDs = append(userIDs, *ev.StateKey)
+ } else if strings.Contains(string(ev.Content), `"ban"`) {
+ userIDs = append(userIDs, *ev.StateKey)
+ }
+ }
+ }
+ }
+ return
+}
diff --git a/syncapi/sync/requestpool.go b/syncapi/sync/requestpool.go
index f817f098..b530b34d 100644
--- a/syncapi/sync/requestpool.go
+++ b/syncapi/sync/requestpool.go
@@ -168,7 +168,7 @@ func (rp *RequestPool) OnIncomingKeyChangeRequest(req *http.Request, device *use
}
// work out room joins/leaves
res, err := rp.db.IncrementalSync(
- req.Context(), types.NewResponse(), *device, fromToken, toToken, 0, false,
+ req.Context(), types.NewResponse(), *device, fromToken, toToken, 10, false,
)
if err != nil {
util.GetLogger(req.Context()).WithError(err).Error("Failed to IncrementalSync")