Fix accountRecord.e164 deprecation

This commit is contained in:
Fedor Indutny 2023-11-15 02:29:04 +01:00 committed by GitHub
parent 7b62576def
commit 337d3f8490
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
3 changed files with 34 additions and 17 deletions

View file

@ -24,7 +24,7 @@ import {
PhoneNumberDiscoverability,
parsePhoneNumberDiscoverability,
} from '../util/phoneNumberDiscoverability';
import { isPnpEnabled } from '../util/isPnpEnabled';
import { isPnpCapable } from '../util/isPnpCapable';
import { arePinnedConversationsEqual } from '../util/arePinnedConversationsEqual';
import type { ConversationModel } from '../models/conversations';
import {
@ -281,7 +281,10 @@ export function toAccountRecord(
}
const accountE164 = window.storage.get('accountE164');
if (accountE164 !== undefined) {
// Once account becomes PNP capable - we want to stop populating this field
// because it is deprecated in PNP world and we don't want to cause storage
// service thrashing.
if (accountE164 !== undefined && !isPnpCapable()) {
accountRecord.e164 = accountE164;
}
@ -1234,15 +1237,13 @@ export async function mergeAccountRecord(
await window.storage.put('primarySendsSms', primarySendsSms);
}
// Store AccountRecord.e164 in an auxiliary field that isn't used for any
// other purpose in the app. This is required only while we are deprecating
// the AccountRecord.e164.
if (typeof accountE164 === 'string') {
await window.storage.put('accountE164', accountE164);
if (
!RemoteConfig.isEnabled('desktop.pnp') &&
!RemoteConfig.isEnabled('desktop.pnp.accountE164Deprecation') &&
!isPnpEnabled()
) {
await window.storage.user.setNumber(accountE164);
}
} else {
await window.storage.remove('accountE164');
}
if (preferredReactionEmoji.canBeSynced(rawPreferredReactionEmoji)) {

24
ts/util/isPnpCapable.ts Normal file
View file

@ -0,0 +1,24 @@
// Copyright 2023 Signal Messenger, LLC
// SPDX-License-Identifier: AGPL-3.0-only
import * as log from '../logging/log';
export function isPnpCapable(): boolean {
const me = window.ConversationController.getOurConversation();
if (!me) {
log.warn('isPnpCapable: missing our conversation');
return false;
}
// These capabilities are filled by a periodic background check for our
// account.
const capabilities = me.get('capabilities');
if (!capabilities) {
log.warn('isPnpCapable: no cached capabilities');
return false;
}
// `capabilities.pni` becomes true once all linked devices and the primary
// advertise this capability.
return capabilities.pni === true;
}

View file

@ -1,8 +0,0 @@
// Copyright 2022 Signal Messenger, LLC
// SPDX-License-Identifier: AGPL-3.0-only
import { isStaging } from './version';
export function isPnpEnabled(version = window.getVersion()): boolean {
return isStaging(version);
}