Request Configuration Sync After Relink (#2218)
Users lose their read receipt setting after relinking their app. See: https://github.com/signalapp/Signal-Android/issues/7535 - [x] Request configuration sync after relink, not just on first run. - [x] Minor: Add `is` dependency as discussed. - [x] Unit tests!! Started a pattern where functions return their status that can be logged instead of logging themselves. Makes for great tests and might also help us debug user logs as the status will always be logged (with `reason` field) whether it was done or not. Otherwise, we have to look for the presence or absence of a log line. Of course, we have to be careful about log noise, but I thought this was a nice fit here. **Manual Tests** - Started app and set read receipts on iOS. - Sent message from another device with read receipts enabled. - Confirmed messages were marked read on both sides. - Unlinked primary device. - Relinked primary device. - Sent messages between primary and other device. - Confirmed read receipts are still shown. - Confirmed logs show configuration sync.pull/1/head
commit
18dddfe436
@ -0,0 +1,55 @@
|
||||
const is = require('@sindresorhus/is');
|
||||
|
||||
const Errors = require('./types/errors');
|
||||
const Settings = require('./settings');
|
||||
|
||||
|
||||
exports.syncReadReceiptConfiguration = async ({
|
||||
deviceId,
|
||||
sendRequestConfigurationSyncMessage,
|
||||
storage,
|
||||
}) => {
|
||||
if (!is.string(deviceId)) {
|
||||
throw new TypeError('"deviceId" is required');
|
||||
}
|
||||
|
||||
if (!is.function(sendRequestConfigurationSyncMessage)) {
|
||||
throw new TypeError('"sendRequestConfigurationSyncMessage" is required');
|
||||
}
|
||||
|
||||
if (!is.object(storage)) {
|
||||
throw new TypeError('"storage" is required');
|
||||
}
|
||||
|
||||
const isPrimaryDevice = deviceId === '1';
|
||||
if (isPrimaryDevice) {
|
||||
return {
|
||||
status: 'skipped',
|
||||
reason: 'isPrimaryDevice',
|
||||
};
|
||||
}
|
||||
|
||||
const settingName = Settings.READ_RECEIPT_CONFIGURATION_SYNC;
|
||||
const hasPreviouslySynced = Boolean(storage.get(settingName));
|
||||
if (hasPreviouslySynced) {
|
||||
return {
|
||||
status: 'skipped',
|
||||
reason: 'hasPreviouslySynced',
|
||||
};
|
||||
}
|
||||
|
||||
try {
|
||||
await sendRequestConfigurationSyncMessage();
|
||||
storage.put(settingName, true);
|
||||
} catch (error) {
|
||||
return {
|
||||
status: 'error',
|
||||
reason: 'failedToSendSyncMessage',
|
||||
error: Errors.toLogFormat(error),
|
||||
};
|
||||
}
|
||||
|
||||
return {
|
||||
status: 'complete',
|
||||
};
|
||||
};
|
Loading…
Reference in New Issue