aboutsummaryrefslogtreecommitdiff
path: root/userapi/internal
diff options
context:
space:
mode:
authorTill <2353100+S7evinK@users.noreply.github.com>2023-02-20 15:26:09 +0100
committerGitHub <noreply@github.com>2023-02-20 15:26:09 +0100
commit7f114cc5387f04d748270d48f92708f137df38a7 (patch)
tree6ade197dd74999c3661486b632789f938f2a4b7b /userapi/internal
parent4594233f89f8531fca8f696ab0ece36909130c2a (diff)
Fix issue where device keys are removed if a device ID is reused (#2982)
Fixes https://github.com/matrix-org/dendrite/issues/2980
Diffstat (limited to 'userapi/internal')
-rw-r--r--userapi/internal/user_api.go13
1 files changed, 12 insertions, 1 deletions
diff --git a/userapi/internal/user_api.go b/userapi/internal/user_api.go
index 1cbd9719..8977697b 100644
--- a/userapi/internal/user_api.go
+++ b/userapi/internal/user_api.go
@@ -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