Fully move to protobufjs

This commit is contained in:
Fedor Indutny 2021-07-13 11:54:53 -07:00 committed by GitHub
parent 20ea409d9e
commit 570fb182d4
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
46 changed files with 1133 additions and 12401 deletions

View file

@ -1,46 +1,51 @@
// Copyright 2021 Signal Messenger, LLC
// SPDX-License-Identifier: AGPL-3.0-only
import { arrayBufferToBase64 } from '../Crypto';
import { PinnedConversationClass } from '../textsecure.d';
import * as Bytes from '../Bytes';
import { SignalService as Proto } from '../protobuf';
import PinnedConversation = Proto.AccountRecord.IPinnedConversation;
export function arePinnedConversationsEqual(
localValue: Array<PinnedConversationClass>,
remoteValue: Array<PinnedConversationClass>
localValue: Array<PinnedConversation>,
remoteValue: Array<PinnedConversation>
): boolean {
if (localValue.length !== remoteValue.length) {
return false;
}
return localValue.every(
(localPinnedConversation: PinnedConversationClass, index: number) => {
(localPinnedConversation: PinnedConversation, index: number) => {
const remotePinnedConversation = remoteValue[index];
if (
localPinnedConversation.identifier !==
remotePinnedConversation.identifier
) {
return false;
const {
contact,
groupMasterKey,
legacyGroupId,
} = localPinnedConversation;
if (contact) {
return (
remotePinnedConversation.contact &&
contact.uuid === remotePinnedConversation.contact.uuid
);
}
switch (localPinnedConversation.identifier) {
case 'contact':
return (
localPinnedConversation.contact &&
remotePinnedConversation.contact &&
localPinnedConversation.contact.uuid ===
remotePinnedConversation.contact.uuid
);
case 'groupMasterKey':
return (
arrayBufferToBase64(localPinnedConversation.groupMasterKey) ===
arrayBufferToBase64(remotePinnedConversation.groupMasterKey)
);
case 'legacyGroupId':
return (
arrayBufferToBase64(localPinnedConversation.legacyGroupId) ===
arrayBufferToBase64(remotePinnedConversation.legacyGroupId)
);
default:
return false;
if (groupMasterKey && groupMasterKey.length) {
return Bytes.areEqual(
groupMasterKey,
remotePinnedConversation.groupMasterKey
);
}
if (legacyGroupId && legacyGroupId.length) {
return Bytes.areEqual(
legacyGroupId,
remotePinnedConversation.legacyGroupId
);
}
return false;
}
);
}