mirror of
https://github.com/1f349/dendrite.git
synced 2024-11-22 11:41:38 +00:00
Device list display name fixes (#2405)
* Get device names from `unsigned` in `/user/devices` * Fix display name updates * Fix bug * Fix another bug
This commit is contained in:
parent
d28d0ee66e
commit
31799a3b2a
@ -20,6 +20,7 @@ import (
|
||||
keyapi "github.com/matrix-org/dendrite/keyserver/api"
|
||||
"github.com/matrix-org/gomatrixserverlib"
|
||||
"github.com/matrix-org/util"
|
||||
"github.com/tidwall/gjson"
|
||||
)
|
||||
|
||||
// GetUserDevices for the given user id
|
||||
@ -69,9 +70,14 @@ func GetUserDevices(
|
||||
continue
|
||||
}
|
||||
|
||||
displayName := dev.DisplayName
|
||||
if displayName == "" {
|
||||
displayName = gjson.GetBytes(dev.DeviceKeys.KeyJSON, "unsigned.device_display_name").Str
|
||||
}
|
||||
|
||||
device := gomatrixserverlib.RespUserDevice{
|
||||
DeviceID: dev.DeviceID,
|
||||
DisplayName: dev.DisplayName,
|
||||
DisplayName: displayName,
|
||||
Keys: key,
|
||||
}
|
||||
|
||||
|
@ -632,6 +632,22 @@ func (a *KeyInternalAPI) uploadLocalDeviceKeys(ctx context.Context, req *api.Per
|
||||
}
|
||||
|
||||
var keysToStore []api.DeviceMessage
|
||||
|
||||
if req.OnlyDisplayNameUpdates {
|
||||
for _, existingKey := range existingKeys {
|
||||
for _, newKey := range req.DeviceKeys {
|
||||
switch {
|
||||
case existingKey.UserID != newKey.UserID:
|
||||
continue
|
||||
case existingKey.DeviceID != newKey.DeviceID:
|
||||
continue
|
||||
case existingKey.DisplayName != newKey.DisplayName:
|
||||
existingKey.DisplayName = newKey.DisplayName
|
||||
}
|
||||
}
|
||||
keysToStore = append(keysToStore, existingKey)
|
||||
}
|
||||
} else {
|
||||
// assert that the user ID / device ID are not lying for each key
|
||||
for _, key := range req.DeviceKeys {
|
||||
var serverName gomatrixserverlib.ServerName
|
||||
@ -665,10 +681,6 @@ func (a *KeyInternalAPI) uploadLocalDeviceKeys(ctx context.Context, req *api.Per
|
||||
),
|
||||
})
|
||||
}
|
||||
|
||||
if req.OnlyDisplayNameUpdates {
|
||||
// add the display name field from keysToStore into existingKeys
|
||||
keysToStore = appendDisplayNames(existingKeys, keysToStore)
|
||||
}
|
||||
|
||||
// store the device keys and emit changes
|
||||
@ -764,16 +776,3 @@ func emitDeviceKeyChanges(producer KeyChangeProducer, existing, new []api.Device
|
||||
}
|
||||
return producer.ProduceKeyChanges(keysAdded)
|
||||
}
|
||||
|
||||
func appendDisplayNames(existing, new []api.DeviceMessage) []api.DeviceMessage {
|
||||
for i, existingDevice := range existing {
|
||||
for _, newDevice := range new {
|
||||
if existingDevice.DeviceID != newDevice.DeviceID {
|
||||
continue
|
||||
}
|
||||
existingDevice.DisplayName = newDevice.DisplayName
|
||||
existing[i] = existingDevice
|
||||
}
|
||||
}
|
||||
return existing
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user