mirror of
https://github.com/matrix-org/dendrite.git
synced 2025-12-21 05:43:09 -06:00
Fix New users appear in /keys/changes
This commit is contained in:
parent
a7e67e65a8
commit
b672915ba0
|
|
@ -16,6 +16,7 @@ package internal
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"context"
|
"context"
|
||||||
|
"strings"
|
||||||
|
|
||||||
"github.com/Shopify/sarama"
|
"github.com/Shopify/sarama"
|
||||||
currentstateAPI "github.com/matrix-org/dendrite/currentstateserver/api"
|
currentstateAPI "github.com/matrix-org/dendrite/currentstateserver/api"
|
||||||
|
|
@ -88,6 +89,16 @@ func DeviceListCatchup(
|
||||||
if !userSet[userID] {
|
if !userSet[userID] {
|
||||||
res.DeviceLists.Changed = append(res.DeviceLists.Changed, userID)
|
res.DeviceLists.Changed = append(res.DeviceLists.Changed, userID)
|
||||||
hasNew = true
|
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
|
return hasNew, nil
|
||||||
|
|
@ -219,3 +230,25 @@ func membershipEventPresent(events []gomatrixserverlib.ClientEvent, userID strin
|
||||||
}
|
}
|
||||||
return false
|
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
|
||||||
|
}
|
||||||
|
|
|
||||||
|
|
@ -168,7 +168,7 @@ func (rp *RequestPool) OnIncomingKeyChangeRequest(req *http.Request, device *use
|
||||||
}
|
}
|
||||||
// work out room joins/leaves
|
// work out room joins/leaves
|
||||||
res, err := rp.db.IncrementalSync(
|
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 {
|
if err != nil {
|
||||||
util.GetLogger(req.Context()).WithError(err).Error("Failed to IncrementalSync")
|
util.GetLogger(req.Context()).WithError(err).Error("Failed to IncrementalSync")
|
||||||
|
|
|
||||||
|
|
@ -129,6 +129,7 @@ Can claim one time key using POST
|
||||||
Can claim remote one time key using POST
|
Can claim remote one time key using POST
|
||||||
Local device key changes appear in v2 /sync
|
Local device key changes appear in v2 /sync
|
||||||
Local device key changes appear in /keys/changes
|
Local device key changes appear in /keys/changes
|
||||||
|
New users appear in /keys/changes
|
||||||
Local delete device changes appear in v2 /sync
|
Local delete device changes appear in v2 /sync
|
||||||
Get left notifs for other users in sync and /keys/changes when user leaves
|
Get left notifs for other users in sync and /keys/changes when user leaves
|
||||||
Can add account data
|
Can add account data
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue