mirror of
https://github.com/matrix-org/dendrite.git
synced 2024-11-29 09:41:57 -06:00
bugfix: when a user's key changes, don't notify everyone on the server (#1253)
* bugfix: when a user's key changes, don't notify everyone on the server Instead just notify the users you share a room with. * Update whitelist
This commit is contained in:
parent
58998e9874
commit
fdabba1851
|
@ -95,6 +95,8 @@ func DeviceListCatchup(
|
||||||
util.GetLogger(ctx).WithError(queryRes.Error).Error("QueryKeyChanges failed")
|
util.GetLogger(ctx).WithError(queryRes.Error).Error("QueryKeyChanges failed")
|
||||||
return hasNew, nil
|
return hasNew, nil
|
||||||
}
|
}
|
||||||
|
// QueryKeyChanges gets ALL users who have changed keys, we want the ones who share rooms with the user.
|
||||||
|
queryRes.UserIDs = filterSharedUsers(ctx, stateAPI, userID, queryRes.UserIDs)
|
||||||
util.GetLogger(ctx).Debugf(
|
util.GetLogger(ctx).Debugf(
|
||||||
"QueryKeyChanges request p=%d,off=%d,to=%d response p=%d off=%d uids=%v",
|
"QueryKeyChanges request p=%d,off=%d,to=%d response p=%d off=%d uids=%v",
|
||||||
partition, offset, toOffset, queryRes.Partition, queryRes.Offset, queryRes.UserIDs,
|
partition, offset, toOffset, queryRes.Partition, queryRes.Offset, queryRes.UserIDs,
|
||||||
|
@ -217,6 +219,31 @@ func TrackChangedUsers(
|
||||||
return changed, left, nil
|
return changed, left, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func filterSharedUsers(
|
||||||
|
ctx context.Context, stateAPI currentstateAPI.CurrentStateInternalAPI, userID string, usersWithChangedKeys []string,
|
||||||
|
) []string {
|
||||||
|
var result []string
|
||||||
|
var sharedUsersRes currentstateAPI.QuerySharedUsersResponse
|
||||||
|
err := stateAPI.QuerySharedUsers(ctx, ¤tstateAPI.QuerySharedUsersRequest{
|
||||||
|
UserID: userID,
|
||||||
|
}, &sharedUsersRes)
|
||||||
|
if err != nil {
|
||||||
|
// default to all users so we do needless queries rather than miss some important device update
|
||||||
|
return usersWithChangedKeys
|
||||||
|
}
|
||||||
|
// We forcibly put ourselves in this list because we should be notified about our own device updates
|
||||||
|
// and if we are in 0 rooms then we don't technically share any room with ourselves so we wouldn't
|
||||||
|
// be notified about key changes.
|
||||||
|
sharedUsersRes.UserIDsToCount[userID] = 1
|
||||||
|
|
||||||
|
for _, uid := range usersWithChangedKeys {
|
||||||
|
if sharedUsersRes.UserIDsToCount[uid] > 0 {
|
||||||
|
result = append(result, uid)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return result
|
||||||
|
}
|
||||||
|
|
||||||
func joinedRooms(res *types.Response, userID string) []string {
|
func joinedRooms(res *types.Response, userID string) []string {
|
||||||
var roomIDs []string
|
var roomIDs []string
|
||||||
for roomID, join := range res.Rooms.Join {
|
for roomID, join := range res.Rooms.Join {
|
||||||
|
|
|
@ -138,7 +138,7 @@ Users receive device_list updates for their own devices
|
||||||
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
|
||||||
Local device key changes get to remote servers
|
Local device key changes get to remote servers
|
||||||
Local device key changes get to remote servers with correct prev_id
|
Local device key changes get to remote servers with correct prev_id
|
||||||
#Server correctly handles incoming m.device_list_update
|
Server correctly handles incoming m.device_list_update
|
||||||
Can add account data
|
Can add account data
|
||||||
Can add account data to room
|
Can add account data to room
|
||||||
Can get account data without syncing
|
Can get account data without syncing
|
||||||
|
|
|
@ -31,6 +31,7 @@ import (
|
||||||
"github.com/matrix-org/dendrite/userapi/storage/devices"
|
"github.com/matrix-org/dendrite/userapi/storage/devices"
|
||||||
"github.com/matrix-org/gomatrixserverlib"
|
"github.com/matrix-org/gomatrixserverlib"
|
||||||
"github.com/matrix-org/util"
|
"github.com/matrix-org/util"
|
||||||
|
"github.com/sirupsen/logrus"
|
||||||
)
|
)
|
||||||
|
|
||||||
type UserInternalAPI struct {
|
type UserInternalAPI struct {
|
||||||
|
@ -98,6 +99,11 @@ func (a *UserInternalAPI) PerformAccountCreation(ctx context.Context, req *api.P
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
func (a *UserInternalAPI) PerformDeviceCreation(ctx context.Context, req *api.PerformDeviceCreationRequest, res *api.PerformDeviceCreationResponse) error {
|
func (a *UserInternalAPI) PerformDeviceCreation(ctx context.Context, req *api.PerformDeviceCreationRequest, res *api.PerformDeviceCreationResponse) error {
|
||||||
|
util.GetLogger(ctx).WithFields(logrus.Fields{
|
||||||
|
"localpart": req.Localpart,
|
||||||
|
"device_id": req.DeviceID,
|
||||||
|
"display_name": req.DeviceDisplayName,
|
||||||
|
}).Info("PerformDeviceCreation")
|
||||||
dev, err := a.DeviceDB.CreateDevice(ctx, req.Localpart, req.DeviceID, req.AccessToken, req.DeviceDisplayName)
|
dev, err := a.DeviceDB.CreateDevice(ctx, req.Localpart, req.DeviceID, req.AccessToken, req.DeviceDisplayName)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
|
|
Loading…
Reference in a new issue