Update contact sync to match iOS behavior

This commit is contained in:
Fedor Indutny 2022-12-23 09:45:00 -08:00 committed by GitHub
parent 01cbdd18bf
commit 2ffea11bdb
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

View file

@ -13,7 +13,6 @@ import type { ConversationModel } from '../models/conversations';
import { validateConversation } from '../util/validateConversation'; import { validateConversation } from '../util/validateConversation';
import { strictAssert } from '../util/assert'; import { strictAssert } from '../util/assert';
import { isDirectConversation, isMe } from '../util/whatTypeOfConversation'; import { isDirectConversation, isMe } from '../util/whatTypeOfConversation';
import { normalizeUuid } from '../util/normalizeUuid';
import * as log from '../logging/log'; import * as log from '../logging/log';
// When true - we are running the very first storage and contact sync after // When true - we are running the very first storage and contact sync after
@ -78,24 +77,13 @@ const queue = new PQueue({ concurrency: 1 });
async function doContactSync({ async function doContactSync({
contacts, contacts,
complete, complete: isFullSync,
receivedAtCounter, receivedAtCounter,
sentAt, sentAt,
}: ContactSyncEvent): Promise<void> { }: ContactSyncEvent): Promise<void> {
// iOS sets `syncMessage.contacts.complete` flag to `true` unconditionally const logId =
// and so we have to employ tricks to figure out whether the sync is full or `doContactSync(sent=${sentAt}, ` +
// partial. Thankfully, iOS sends only two kinds of contact syncs: full or `receivedAt=${receivedAtCounter}, isFullSync=${isFullSync})`;
// local sync. Local sync is always a single our own contact so we can do an
// UUID check.
const isFullSync =
complete &&
!(
contacts.length === 1 &&
normalizeUuid(contacts[0].uuid, 'doContactSync') ===
window.storage.user.getUuid()?.toString()
);
const logId = `doContactSync(sent=${sentAt}, receivedAt=${receivedAtCounter}, isFullSync=${isFullSync})`;
log.info(`${logId}: got ${contacts.length} contacts`); log.info(`${logId}: got ${contacts.length} contacts`);
const updatedConversations = new Set<ConversationModel>(); const updatedConversations = new Set<ConversationModel>();
@ -157,6 +145,8 @@ async function doContactSync({
const notUpdated = isFullSync const notUpdated = isFullSync
? window.ConversationController.getAll().filter( ? window.ConversationController.getAll().filter(
convo => convo =>
(convo.get('name') !== undefined ||
convo.get('inbox_position') !== undefined) &&
!updatedConversations.has(convo) && !updatedConversations.has(convo) &&
isDirectConversation(convo.attributes) && isDirectConversation(convo.attributes) &&
!isMe(convo.attributes) !isMe(convo.attributes)