MCPcopy Create free account
hub / github.com/daodst/chat / emitDeviceKeyChanges

Function emitDeviceKeyChanges

keyserver/internal/internal.go:756–778  ·  view source on GitHub ↗
(producer KeyChangeProducer, existing, new []api.DeviceMessage, onlyUpdateDisplayName bool)

Source from the content-addressed store, hash-verified

754}
755
756func emitDeviceKeyChanges(producer KeyChangeProducer, existing, new []api.DeviceMessage, onlyUpdateDisplayName bool) error {
757 // if we only want to update the display names, we can skip the checks below
758 if onlyUpdateDisplayName {
759 return producer.ProduceKeyChanges(new)
760 }
761 // find keys in new that are not in existing
762 var keysAdded []api.DeviceMessage
763 for _, newKey := range new {
764 exists := false
765 for _, existingKey := range existing {
766 // Do not treat the absence of keys as equal, or else we will not emit key changes
767 // when users delete devices which never had a key to begin with as both KeyJSONs are nil.
768 if existingKey.DeviceKeysEqual(&newKey) {
769 exists = true
770 break
771 }
772 }
773 if !exists {
774 keysAdded = append(keysAdded, newKey)
775 }
776 }
777 return producer.ProduceKeyChanges(keysAdded)
778}

Callers 3

uploadLocalDeviceKeysMethod · 0.85
updateMethod · 0.85
updateDeviceListMethod · 0.85

Calls 2

DeviceKeysEqualMethod · 0.80
ProduceKeyChangesMethod · 0.65

Tested by

no test coverage detected