mirror of
https://github.com/hoernschen/dendrite.git
synced 2025-07-31 21:32:46 +00:00
Fix issue where device keys are removed if a device ID is reused (#2982)
Fixes https://github.com/matrix-org/dendrite/issues/2980
This commit is contained in:
parent
4594233f89
commit
7f114cc538
2 changed files with 55 additions and 16 deletions
|
@ -254,6 +254,17 @@ func (a *UserInternalAPI) PerformDeviceCreation(ctx context.Context, req *api.Pe
|
|||
if !a.Config.Matrix.IsLocalServerName(serverName) {
|
||||
return fmt.Errorf("server name %s is not local", serverName)
|
||||
}
|
||||
// If a device ID was specified, check if it already exists and
|
||||
// avoid sending an empty device list update which would remove
|
||||
// existing device keys.
|
||||
isExisting := false
|
||||
if req.DeviceID != nil && *req.DeviceID != "" {
|
||||
existingDev, err := a.DB.GetDeviceByID(ctx, req.Localpart, req.ServerName, *req.DeviceID)
|
||||
if err != nil && !errors.Is(err, sql.ErrNoRows) {
|
||||
return err
|
||||
}
|
||||
isExisting = existingDev.ID == *req.DeviceID
|
||||
}
|
||||
util.GetLogger(ctx).WithFields(logrus.Fields{
|
||||
"localpart": req.Localpart,
|
||||
"device_id": req.DeviceID,
|
||||
|
@ -265,7 +276,7 @@ func (a *UserInternalAPI) PerformDeviceCreation(ctx context.Context, req *api.Pe
|
|||
}
|
||||
res.DeviceCreated = true
|
||||
res.Device = dev
|
||||
if req.NoDeviceListUpdate {
|
||||
if req.NoDeviceListUpdate || isExisting {
|
||||
return nil
|
||||
}
|
||||
// create empty device keys and upload them to trigger device list changes
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue