mirror of
https://github.com/matrix-org/dendrite.git
synced 2025-12-31 18:53:10 -06:00
Single return value
This commit is contained in:
parent
b323318ae9
commit
2022f3f874
|
|
@ -18,7 +18,6 @@ import (
|
||||||
"bytes"
|
"bytes"
|
||||||
"context"
|
"context"
|
||||||
"encoding/json"
|
"encoding/json"
|
||||||
"fmt"
|
|
||||||
"strings"
|
"strings"
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
|
|
@ -75,20 +74,24 @@ type DeviceMessage struct {
|
||||||
DeviceChangeID int64
|
DeviceChangeID int64
|
||||||
}
|
}
|
||||||
|
|
||||||
func (m1 *DeviceMessage) DeviceKeysEqual(m2 *DeviceMessage) (bool, error) {
|
// 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 {
|
if m1.DeviceKeys == nil || m2.DeviceKeys == nil {
|
||||||
return false, fmt.Errorf("not device keys")
|
return false
|
||||||
}
|
}
|
||||||
if m1.UserID != m2.UserID || m1.DeviceID != m2.DeviceID {
|
if m1.UserID != m2.UserID || m1.DeviceID != m2.DeviceID {
|
||||||
return false, fmt.Errorf("different user ID or device ID")
|
return false
|
||||||
}
|
}
|
||||||
if m1.DisplayName != m2.DisplayName {
|
if m1.DisplayName != m2.DisplayName {
|
||||||
return false, nil // different display names
|
return false // different display names
|
||||||
}
|
}
|
||||||
if len(m1.KeyJSON) == 0 || len(m2.KeyJSON) == 0 {
|
if len(m1.KeyJSON) == 0 || len(m2.KeyJSON) == 0 {
|
||||||
return false, nil // either is empty
|
return false // either is empty
|
||||||
}
|
}
|
||||||
return bytes.Equal(m1.KeyJSON, m2.KeyJSON), nil
|
return bytes.Equal(m1.KeyJSON, m2.KeyJSON)
|
||||||
}
|
}
|
||||||
|
|
||||||
// DeviceKeys represents a set of device keys for a single device
|
// DeviceKeys represents a set of device keys for a single device
|
||||||
|
|
|
||||||
|
|
@ -718,10 +718,7 @@ func emitDeviceKeyChanges(producer KeyChangeProducer, existing, new []api.Device
|
||||||
for _, existingKey := range existing {
|
for _, existingKey := range existing {
|
||||||
// Do not treat the absence of keys as equal, or else we will not emit key changes
|
// Do not treat the absence of keys as equal, or else we will not emit key changes
|
||||||
// when users delete devices which never had a key to begin with as both KeyJSONs are nil.
|
// when users delete devices which never had a key to begin with as both KeyJSONs are nil.
|
||||||
if equal, err := existingKey.DeviceKeysEqual(&newKey); err != nil {
|
if existingKey.DeviceKeysEqual(&newKey) {
|
||||||
// One of the keys was not a DeviceKeys or the user ID/device ID did not match.
|
|
||||||
continue
|
|
||||||
} else if equal {
|
|
||||||
exists = true
|
exists = true
|
||||||
break
|
break
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue