Request contact sync before importing backup

This commit is contained in:
trevor-signal 2024-11-11 14:32:48 -05:00 committed by GitHub
parent 2bf34fbf1e
commit 44fcf915de
No known key found for this signature in database
GPG key ID: B5690EEEBB952194

View file

@ -1742,9 +1742,33 @@ export async function startApp(): Promise<void> {
strictAssert(server !== undefined, 'WebAPI not connected');
let contactSyncComplete: Promise<void> | undefined;
const areWePrimaryDevice =
window.ConversationController.areWePrimaryDevice();
const waitForEvent = createTaskWithTimeout(
(event: string): Promise<void> => {
const { promise, resolve } = explodePromise<void>();
window.Whisper.events.once(event, () => resolve());
return promise;
},
'connect:waitForEvent',
{ timeout: 2 * durations.MINUTE }
);
try {
connectPromise = explodePromise();
if (firstRun === true && !areWePrimaryDevice) {
contactSyncComplete = waitForEvent('contactSync:complete');
// Send the contact sync message immediately (don't wait until after backup is
// downloaded & imported)
await singleProtoJobQueue.add(
MessageSender.getRequestContactSyncMessage()
);
}
// Wait for backup to be downloaded
try {
await backupReady.promise;
@ -1831,7 +1855,7 @@ export async function startApp(): Promise<void> {
!firstRun &&
connectCount === 1 &&
newVersion &&
window.textsecure.storage.user.getDeviceId() !== 1
!areWePrimaryDevice
) {
log.info('Boot after upgrading. Requesting contact sync');
@ -1854,8 +1878,6 @@ export async function startApp(): Promise<void> {
}
}
const deviceId = window.textsecure.storage.user.getDeviceId();
if (!window.textsecure.storage.user.getAci()) {
log.error('UUID not captured during registration, unlinking');
return unlinkAndDisconnect();
@ -1883,7 +1905,7 @@ export async function startApp(): Promise<void> {
return unlinkAndDisconnect();
}
if (firstRun === true && deviceId !== 1) {
if (firstRun === true && !areWePrimaryDevice) {
if (!window.storage.get('accountEntropyPool')) {
const lastSent =
window.storage.get('accountEntropyPoolLastRequestTime') ?? 0;
@ -1904,17 +1926,6 @@ export async function startApp(): Promise<void> {
);
}
}
const waitForEvent = createTaskWithTimeout(
(event: string): Promise<void> => {
const { promise, resolve } = explodePromise<void>();
window.Whisper.events.once(event, () => resolve());
return promise;
},
'firstRun:waitForEvent',
{ timeout: 2 * durations.MINUTE }
);
let storageServiceSyncComplete: Promise<void>;
if (window.ConversationController.areWePrimaryDevice()) {
storageServiceSyncComplete = Promise.resolve();
@ -1924,8 +1935,6 @@ export async function startApp(): Promise<void> {
);
}
const contactSyncComplete = waitForEvent('contactSync:complete');
log.info('firstRun: requesting initial sync');
setIsInitialSync(true);
@ -1938,9 +1947,6 @@ export async function startApp(): Promise<void> {
),
singleProtoJobQueue.add(MessageSender.getRequestBlockSyncMessage()),
runStorageService({ reason: 'firstRun/initialSync' }),
singleProtoJobQueue.add(
MessageSender.getRequestContactSyncMessage()
),
]);
} catch (error) {
log.error(
@ -1950,7 +1956,10 @@ export async function startApp(): Promise<void> {
}
log.info('firstRun: waiting for storage service and contact sync');
strictAssert(
contactSyncComplete,
'contact sync is awaited during first run'
);
try {
await Promise.all([storageServiceSyncComplete, contactSyncComplete]);
} catch (error) {