(producer KeyChangeProducer, existing, new []api.DeviceMessage, onlyUpdateDisplayName bool)
| 754 | } |
| 755 | |
| 756 | func 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 | } |
no test coverage detected