2021-04-08 19:27:20 +00:00
|
|
|
// Copyright 2021 Signal Messenger, LLC
|
|
|
|
// SPDX-License-Identifier: AGPL-3.0-only
|
|
|
|
|
2021-07-13 18:54:53 +00:00
|
|
|
import * as Bytes from '../Bytes';
|
|
|
|
|
|
|
|
import { SignalService as Proto } from '../protobuf';
|
|
|
|
|
|
|
|
import PinnedConversation = Proto.AccountRecord.IPinnedConversation;
|
2021-04-08 19:27:20 +00:00
|
|
|
|
|
|
|
export function arePinnedConversationsEqual(
|
2021-07-13 18:54:53 +00:00
|
|
|
localValue: Array<PinnedConversation>,
|
|
|
|
remoteValue: Array<PinnedConversation>
|
2021-04-08 19:27:20 +00:00
|
|
|
): boolean {
|
|
|
|
if (localValue.length !== remoteValue.length) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
return localValue.every(
|
2021-07-13 18:54:53 +00:00
|
|
|
(localPinnedConversation: PinnedConversation, index: number) => {
|
2021-04-08 19:27:20 +00:00
|
|
|
const remotePinnedConversation = remoteValue[index];
|
2021-07-13 18:54:53 +00:00
|
|
|
|
2021-11-11 22:43:05 +00:00
|
|
|
const { contact, groupMasterKey, legacyGroupId } =
|
|
|
|
localPinnedConversation;
|
2021-07-13 18:54:53 +00:00
|
|
|
|
|
|
|
if (contact) {
|
|
|
|
return (
|
|
|
|
remotePinnedConversation.contact &&
|
|
|
|
contact.uuid === remotePinnedConversation.contact.uuid
|
|
|
|
);
|
2021-04-08 19:27:20 +00:00
|
|
|
}
|
2021-07-13 18:54:53 +00:00
|
|
|
|
|
|
|
if (groupMasterKey && groupMasterKey.length) {
|
|
|
|
return Bytes.areEqual(
|
|
|
|
groupMasterKey,
|
|
|
|
remotePinnedConversation.groupMasterKey
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (legacyGroupId && legacyGroupId.length) {
|
|
|
|
return Bytes.areEqual(
|
|
|
|
legacyGroupId,
|
|
|
|
remotePinnedConversation.legacyGroupId
|
|
|
|
);
|
2021-04-08 19:27:20 +00:00
|
|
|
}
|
2021-07-13 18:54:53 +00:00
|
|
|
|
|
|
|
return false;
|
2021-04-08 19:27:20 +00:00
|
|
|
}
|
|
|
|
);
|
|
|
|
}
|