Don't always show an error on manual contact sync

This commit is contained in:
Scott Nonnenberg 2021-04-08 10:09:54 -07:00 committed by Josh Perez
parent a82fa86176
commit e0415de893
5 changed files with 60 additions and 31 deletions

View file

@ -312,6 +312,10 @@
await window.makeSyncRequest();
this.onsuccess();
} catch (error) {
window.log.error(
'settings sync timeout error:',
error && error.stack ? error.stack : error
);
this.ontimeout();
}
},

View file

@ -365,7 +365,7 @@ export async function startApp(): Promise<void> {
onChangeTheme();
},
getHideMenuBar: () => window.storage.get('hide-menu-bar'),
setHideMenuBar: (value: WhatIsThis) => {
setHideMenuBar: (value: boolean) => {
window.storage.put('hide-menu-bar', value);
window.setAutoHideMenuBar(value);
window.setMenuBarVisibility(!value);
@ -373,53 +373,56 @@ export async function startApp(): Promise<void> {
getNotificationSetting: () =>
window.storage.get('notification-setting', 'message'),
setNotificationSetting: (value: WhatIsThis) =>
setNotificationSetting: (value: 'message' | 'name' | 'count' | 'off') =>
window.storage.put('notification-setting', value),
getNotificationDrawAttention: () =>
window.storage.get('notification-draw-attention', true),
setNotificationDrawAttention: (value: WhatIsThis) =>
setNotificationDrawAttention: (value: boolean) =>
window.storage.put('notification-draw-attention', value),
getAudioNotification: () => window.storage.get('audio-notification'),
setAudioNotification: (value: WhatIsThis) =>
setAudioNotification: (value: boolean) =>
window.storage.put('audio-notification', value),
getCountMutedConversations: () =>
window.storage.get('badge-count-muted-conversations', false),
setCountMutedConversations: (value: WhatIsThis) => {
setCountMutedConversations: (value: boolean) => {
window.storage.put('badge-count-muted-conversations', value);
window.Whisper.events.trigger('updateUnreadCount');
},
getCallRingtoneNotification: () =>
window.storage.get('call-ringtone-notification', true),
setCallRingtoneNotification: (value: WhatIsThis) =>
setCallRingtoneNotification: (value: boolean) =>
window.storage.put('call-ringtone-notification', value),
getCallSystemNotification: () =>
window.storage.get('call-system-notification', true),
setCallSystemNotification: (value: WhatIsThis) =>
setCallSystemNotification: (value: boolean) =>
window.storage.put('call-system-notification', value),
getIncomingCallNotification: () =>
window.storage.get('incoming-call-notification', true),
setIncomingCallNotification: (value: WhatIsThis) =>
setIncomingCallNotification: (value: boolean) =>
window.storage.put('incoming-call-notification', value),
getSpellCheck: () => window.storage.get('spell-check', true),
setSpellCheck: (value: WhatIsThis) => {
setSpellCheck: (value: boolean) => {
window.storage.put('spell-check', value);
},
getAlwaysRelayCalls: () => window.storage.get('always-relay-calls'),
setAlwaysRelayCalls: (value: WhatIsThis) =>
setAlwaysRelayCalls: (value: boolean) =>
window.storage.put('always-relay-calls', value),
// eslint-disable-next-line eqeqeq
isPrimary: () => window.textsecure.storage.user.getDeviceId() == '1',
getSyncRequest: () =>
new Promise((resolve, reject) => {
const syncRequest = window.getSyncRequest();
syncRequest.addEventListener('success', resolve);
syncRequest.addEventListener('timeout', reject);
new Promise<void>((resolve, reject) => {
const FIVE_MINUTES = 5 * 60 * 60 * 1000;
const syncRequest = window.getSyncRequest(FIVE_MINUTES);
syncRequest.addEventListener('success', () => resolve());
syncRequest.addEventListener('timeout', () =>
reject(new Error('timeout'))
);
}),
getLastSyncTime: () => window.storage.get('synced_at'),
setLastSyncTime: (value: WhatIsThis) =>
setLastSyncTime: (value: number) =>
window.storage.put('synced_at', value),
addDarkOverlay: () => {
@ -1602,10 +1605,11 @@ export async function startApp(): Promise<void> {
);
}
window.getSyncRequest = () => {
window.getSyncRequest = (timeoutMillis?: number) => {
const syncRequest = new window.textsecure.SyncRequest(
window.textsecure.messaging,
messageReceiver
messageReceiver,
timeoutMillis
);
syncRequest.start();
return syncRequest;
@ -1822,7 +1826,9 @@ export async function startApp(): Promise<void> {
addQueuedEventListener('message', onMessageReceived);
addQueuedEventListener('delivery', onDeliveryReceipt);
addQueuedEventListener('contact', onContactReceived);
addQueuedEventListener('contactsync', onContactSyncComplete);
addQueuedEventListener('group', onGroupReceived);
addQueuedEventListener('groupsync', onGroupSyncComplete);
addQueuedEventListener('sent', onSentMessage);
addQueuedEventListener('readSync', onReadSync);
addQueuedEventListener('read', onReadReceipt);
@ -2334,6 +2340,11 @@ export async function startApp(): Promise<void> {
});
}
async function onContactSyncComplete() {
window.log.info('onContactSyncComplete');
await window.storage.put('synced_at', Date.now());
}
async function onContactReceived(ev: WhatIsThis) {
const details = ev.contactDetails;
@ -2466,6 +2477,11 @@ export async function startApp(): Promise<void> {
}
}
async function onGroupSyncComplete() {
window.log.info('onGroupSyncComplete');
await window.storage.put('synced_at', Date.now());
}
// Note: this handler is only for v1 groups received via 'group sync' messages
async function onGroupReceived(ev: WhatIsThis) {
const details = ev.groupDetails;

View file

@ -24,9 +24,12 @@ class SyncRequestInner extends EventTarget {
ongroup: Function;
timeoutMillis: number;
constructor(
private sender: MessageSender,
private receiver: MessageReceiver
private receiver: MessageReceiver,
timeoutMillis?: number
) {
super();
@ -44,6 +47,8 @@ class SyncRequestInner extends EventTarget {
this.ongroup = this.onGroupSyncComplete.bind(this);
receiver.addEventListener('groupsync', this.ongroup);
this.timeoutMillis = timeoutMillis || 60000;
}
async start(): Promise<void> {
@ -81,7 +86,7 @@ class SyncRequestInner extends EventTarget {
error && error.stack ? error.stack : error
);
});
this.timeout = setTimeout(this.onTimeout.bind(this), 60000);
this.timeout = setTimeout(this.onTimeout.bind(this), this.timeoutMillis);
}
onContactSyncComplete() {
@ -125,8 +130,12 @@ export default class SyncRequest {
removeEventListener: (name: string, handler: Function) => void;
constructor(sender: MessageSender, receiver: MessageReceiver) {
const inner = new SyncRequestInner(sender, receiver);
constructor(
sender: MessageSender,
receiver: MessageReceiver,
timeoutMillis?: number
) {
const inner = new SyncRequestInner(sender, receiver, timeoutMillis);
this.inner = inner;
this.addEventListener = inner.addEventListener.bind(inner);
this.removeEventListener = inner.removeEventListener.bind(inner);

View file

@ -17100,7 +17100,7 @@
"rule": "jQuery-wrap(",
"path": "ts/textsecure/SyncRequest.js",
"line": " wrap(sender.sendRequestConfigurationSyncMessage(sendOptions));",
"lineNumber": 43,
"lineNumber": 44,
"reasonCategory": "falseMatch",
"updated": "2020-04-05T23:45:16.746Z"
},
@ -17108,7 +17108,7 @@
"rule": "jQuery-wrap(",
"path": "ts/textsecure/SyncRequest.js",
"line": " wrap(sender.sendRequestBlockSyncMessage(sendOptions));",
"lineNumber": 45,
"lineNumber": 46,
"reasonCategory": "falseMatch",
"updated": "2020-04-05T23:45:16.746Z"
},
@ -17116,7 +17116,7 @@
"rule": "jQuery-wrap(",
"path": "ts/textsecure/SyncRequest.js",
"line": " wrap(sender.sendRequestContactSyncMessage(sendOptions))",
"lineNumber": 47,
"lineNumber": 48,
"reasonCategory": "falseMatch",
"updated": "2020-04-05T23:45:16.746Z"
},
@ -17124,7 +17124,7 @@
"rule": "jQuery-wrap(",
"path": "ts/textsecure/SyncRequest.js",
"line": " return wrap(sender.sendRequestGroupSyncMessage(sendOptions));",
"lineNumber": 50,
"lineNumber": 51,
"reasonCategory": "falseMatch",
"updated": "2020-04-05T23:45:16.746Z"
},
@ -17132,7 +17132,7 @@
"rule": "jQuery-wrap(",
"path": "ts/textsecure/SyncRequest.ts",
"line": " wrap(sender.sendRequestConfigurationSyncMessage(sendOptions));",
"lineNumber": 67,
"lineNumber": 72,
"reasonCategory": "falseMatch",
"updated": "2020-04-05T23:45:16.746Z"
},
@ -17140,7 +17140,7 @@
"rule": "jQuery-wrap(",
"path": "ts/textsecure/SyncRequest.ts",
"line": " wrap(sender.sendRequestBlockSyncMessage(sendOptions));",
"lineNumber": 70,
"lineNumber": 75,
"reasonCategory": "falseMatch",
"updated": "2020-04-05T23:45:16.746Z"
},
@ -17148,7 +17148,7 @@
"rule": "jQuery-wrap(",
"path": "ts/textsecure/SyncRequest.ts",
"line": " wrap(sender.sendRequestContactSyncMessage(sendOptions))",
"lineNumber": 73,
"lineNumber": 78,
"reasonCategory": "falseMatch",
"updated": "2020-04-05T23:45:16.746Z"
},
@ -17156,7 +17156,7 @@
"rule": "jQuery-wrap(",
"path": "ts/textsecure/SyncRequest.ts",
"line": " return wrap(sender.sendRequestGroupSyncMessage(sendOptions));",
"lineNumber": 76,
"lineNumber": 81,
"reasonCategory": "falseMatch",
"updated": "2020-04-05T23:45:16.746Z"
},

2
ts/window.d.ts vendored
View file

@ -170,7 +170,7 @@ declare global {
getServerPublicParams: () => string;
getSfuUrl: () => string;
getSocketStatus: () => number;
getSyncRequest: () => SyncRequest;
getSyncRequest: (timeoutMillis?: number) => SyncRequest;
getTitle: () => string;
waitForEmptyEventQueue: () => Promise<void>;
getVersion: () => string;