Skip to content

Commit

Permalink
Fix accountRecord.e164 deprecation
Browse files Browse the repository at this point in the history
  • Loading branch information
indutny-signal committed Nov 15, 2023
1 parent 7b62576 commit 337d3f8
Show file tree
Hide file tree
Showing 3 changed files with 34 additions and 17 deletions.
19 changes: 10 additions & 9 deletions ts/services/storageRecordOps.ts
Expand Up @@ -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 {
Expand Down Expand Up @@ -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;
}

Expand Down Expand Up @@ -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)) {
Expand Down
24 changes: 24 additions & 0 deletions 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;
}
8 changes: 0 additions & 8 deletions ts/util/isPnpEnabled.ts

This file was deleted.

0 comments on commit 337d3f8

Please sign in to comment.