Request contact sync before importing backup
This commit is contained in:
parent
2bf34fbf1e
commit
44fcf915de
1 changed files with 30 additions and 21 deletions
|
@ -1742,9 +1742,33 @@ export async function startApp(): Promise<void> {
|
||||||
|
|
||||||
strictAssert(server !== undefined, 'WebAPI not connected');
|
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 {
|
try {
|
||||||
connectPromise = explodePromise();
|
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
|
// Wait for backup to be downloaded
|
||||||
try {
|
try {
|
||||||
await backupReady.promise;
|
await backupReady.promise;
|
||||||
|
@ -1831,7 +1855,7 @@ export async function startApp(): Promise<void> {
|
||||||
!firstRun &&
|
!firstRun &&
|
||||||
connectCount === 1 &&
|
connectCount === 1 &&
|
||||||
newVersion &&
|
newVersion &&
|
||||||
window.textsecure.storage.user.getDeviceId() !== 1
|
!areWePrimaryDevice
|
||||||
) {
|
) {
|
||||||
log.info('Boot after upgrading. Requesting contact sync');
|
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()) {
|
if (!window.textsecure.storage.user.getAci()) {
|
||||||
log.error('UUID not captured during registration, unlinking');
|
log.error('UUID not captured during registration, unlinking');
|
||||||
return unlinkAndDisconnect();
|
return unlinkAndDisconnect();
|
||||||
|
@ -1883,7 +1905,7 @@ export async function startApp(): Promise<void> {
|
||||||
return unlinkAndDisconnect();
|
return unlinkAndDisconnect();
|
||||||
}
|
}
|
||||||
|
|
||||||
if (firstRun === true && deviceId !== 1) {
|
if (firstRun === true && !areWePrimaryDevice) {
|
||||||
if (!window.storage.get('accountEntropyPool')) {
|
if (!window.storage.get('accountEntropyPool')) {
|
||||||
const lastSent =
|
const lastSent =
|
||||||
window.storage.get('accountEntropyPoolLastRequestTime') ?? 0;
|
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>;
|
let storageServiceSyncComplete: Promise<void>;
|
||||||
if (window.ConversationController.areWePrimaryDevice()) {
|
if (window.ConversationController.areWePrimaryDevice()) {
|
||||||
storageServiceSyncComplete = Promise.resolve();
|
storageServiceSyncComplete = Promise.resolve();
|
||||||
|
@ -1924,8 +1935,6 @@ export async function startApp(): Promise<void> {
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
const contactSyncComplete = waitForEvent('contactSync:complete');
|
|
||||||
|
|
||||||
log.info('firstRun: requesting initial sync');
|
log.info('firstRun: requesting initial sync');
|
||||||
setIsInitialSync(true);
|
setIsInitialSync(true);
|
||||||
|
|
||||||
|
@ -1938,9 +1947,6 @@ export async function startApp(): Promise<void> {
|
||||||
),
|
),
|
||||||
singleProtoJobQueue.add(MessageSender.getRequestBlockSyncMessage()),
|
singleProtoJobQueue.add(MessageSender.getRequestBlockSyncMessage()),
|
||||||
runStorageService({ reason: 'firstRun/initialSync' }),
|
runStorageService({ reason: 'firstRun/initialSync' }),
|
||||||
singleProtoJobQueue.add(
|
|
||||||
MessageSender.getRequestContactSyncMessage()
|
|
||||||
),
|
|
||||||
]);
|
]);
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
log.error(
|
log.error(
|
||||||
|
@ -1950,7 +1956,10 @@ export async function startApp(): Promise<void> {
|
||||||
}
|
}
|
||||||
|
|
||||||
log.info('firstRun: waiting for storage service and contact sync');
|
log.info('firstRun: waiting for storage service and contact sync');
|
||||||
|
strictAssert(
|
||||||
|
contactSyncComplete,
|
||||||
|
'contact sync is awaited during first run'
|
||||||
|
);
|
||||||
try {
|
try {
|
||||||
await Promise.all([storageServiceSyncComplete, contactSyncComplete]);
|
await Promise.all([storageServiceSyncComplete, contactSyncComplete]);
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
|
|
Loading…
Reference in a new issue