diff --git a/ts/services/storageRecordOps.ts b/ts/services/storageRecordOps.ts index e6dc4560dc2..f85620256b6 100644 --- a/ts/services/storageRecordOps.ts +++ b/ts/services/storageRecordOps.ts @@ -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)) { diff --git a/ts/util/isPnpCapable.ts b/ts/util/isPnpCapable.ts new file mode 100644 index 00000000000..a73efb226df --- /dev/null +++ b/ts/util/isPnpCapable.ts @@ -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; +} diff --git a/ts/util/isPnpEnabled.ts b/ts/util/isPnpEnabled.ts deleted file mode 100644 index e79569a52f2..00000000000 --- a/ts/util/isPnpEnabled.ts +++ /dev/null @@ -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); -}