mirror of
https://github.com/hoernschen/dendrite.git
synced 2025-07-31 13:22:46 +00:00
Add DeviceKeysEqual
(#2219)
* Add `DeviceKeysEqual` * Update check order * Fix check * Tweak conditions again * One more time * Single return value
This commit is contained in:
parent
34116178e8
commit
c7811e9d71
2 changed files with 22 additions and 1 deletions
|
@ -15,6 +15,7 @@
|
|||
package api
|
||||
|
||||
import (
|
||||
"bytes"
|
||||
"context"
|
||||
"encoding/json"
|
||||
"strings"
|
||||
|
@ -73,6 +74,26 @@ type DeviceMessage struct {
|
|||
DeviceChangeID int64
|
||||
}
|
||||
|
||||
// DeviceKeysEqual returns true if the device keys updates contain the
|
||||
// same display name and key JSON. This will return false if either of
|
||||
// the updates is not a device keys update, or if the user ID/device ID
|
||||
// differ between the two.
|
||||
func (m1 *DeviceMessage) DeviceKeysEqual(m2 *DeviceMessage) bool {
|
||||
if m1.DeviceKeys == nil || m2.DeviceKeys == nil {
|
||||
return false
|
||||
}
|
||||
if m1.UserID != m2.UserID || m1.DeviceID != m2.DeviceID {
|
||||
return false
|
||||
}
|
||||
if m1.DisplayName != m2.DisplayName {
|
||||
return false // different display names
|
||||
}
|
||||
if len(m1.KeyJSON) == 0 || len(m2.KeyJSON) == 0 {
|
||||
return false // either is empty
|
||||
}
|
||||
return bytes.Equal(m1.KeyJSON, m2.KeyJSON)
|
||||
}
|
||||
|
||||
// DeviceKeys represents a set of device keys for a single device
|
||||
// https://matrix.org/docs/spec/client_server/r0.6.1#post-matrix-client-r0-keys-upload
|
||||
type DeviceKeys struct {
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue