mirror of
https://github.com/matrix-org/dendrite.git
synced 2026-01-01 03:03:10 -06:00
Fix UserExists flag, device check
This commit is contained in:
parent
fee6d342d2
commit
1357ae5248
|
|
@ -558,6 +558,12 @@ func (a *KeyInternalAPI) uploadLocalDeviceKeys(ctx context.Context, req *api.Per
|
||||||
}
|
}
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
if !uapidevices.UserExists {
|
||||||
|
res.Error = &api.KeyError{
|
||||||
|
Err: fmt.Sprintf("user %q does not exist", req.UserID),
|
||||||
|
}
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
// Get all of the user existing device keys so we can check for changes.
|
// Get all of the user existing device keys so we can check for changes.
|
||||||
existingKeys, err := a.DB.DeviceKeysForUser(ctx, req.UserID, nil)
|
existingKeys, err := a.DB.DeviceKeysForUser(ctx, req.UserID, nil)
|
||||||
|
|
@ -568,8 +574,8 @@ func (a *KeyInternalAPI) uploadLocalDeviceKeys(ctx context.Context, req *api.Per
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
existingDeviceMap := make(map[string]struct{}, len(existingKeys))
|
existingDeviceMap := make(map[string]struct{}, len(existingKeys))
|
||||||
for _, k := range existingKeys {
|
for _, key := range uapidevices.Devices {
|
||||||
existingDeviceMap[k.DeviceID] = struct{}{}
|
existingDeviceMap[key.ID] = struct{}{}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Work out whether we have device keys in the keyserver for devices that
|
// Work out whether we have device keys in the keyserver for devices that
|
||||||
|
|
@ -577,13 +583,7 @@ func (a *KeyInternalAPI) uploadLocalDeviceKeys(ctx context.Context, req *api.Per
|
||||||
// that we keep some integrity between the two.
|
// that we keep some integrity between the two.
|
||||||
var toClean []gomatrixserverlib.KeyID
|
var toClean []gomatrixserverlib.KeyID
|
||||||
for _, k := range existingKeys {
|
for _, k := range existingKeys {
|
||||||
found := false
|
if _, ok := existingDeviceMap[k.DeviceID]; !ok {
|
||||||
for _, d := range uapidevices.Devices {
|
|
||||||
if k.UserID == d.UserID && k.DeviceID == d.ID {
|
|
||||||
found = true
|
|
||||||
}
|
|
||||||
}
|
|
||||||
if !found {
|
|
||||||
toClean = append(toClean, gomatrixserverlib.KeyID(k.DeviceID))
|
toClean = append(toClean, gomatrixserverlib.KeyID(k.DeviceID))
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
@ -613,13 +613,7 @@ func (a *KeyInternalAPI) uploadLocalDeviceKeys(ctx context.Context, req *api.Per
|
||||||
}
|
}
|
||||||
// check that the device in question actually exists in the user
|
// check that the device in question actually exists in the user
|
||||||
// API before we try and store a key for it
|
// API before we try and store a key for it
|
||||||
foundDevice := false
|
if _, ok := existingDeviceMap[key.DeviceID]; !ok {
|
||||||
for _, d := range uapidevices.Devices {
|
|
||||||
if d.ID == key.DeviceID {
|
|
||||||
foundDevice = true
|
|
||||||
}
|
|
||||||
}
|
|
||||||
if !foundDevice {
|
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
gotUserID := gjson.GetBytes(key.KeyJSON, "user_id").Str
|
gotUserID := gjson.GetBytes(key.KeyJSON, "user_id").Str
|
||||||
|
|
|
||||||
|
|
@ -315,6 +315,7 @@ func (a *UserInternalAPI) QueryDevices(ctx context.Context, req *api.QueryDevice
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
res.UserExists = true
|
||||||
res.Devices = devs
|
res.Devices = devs
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue