Storage service: save new AccountRecord fields to disk
This commit is contained in:
parent
6cfb3c9867
commit
a7c78b3b23
5 changed files with 141 additions and 13 deletions
|
@ -93,6 +93,12 @@ message GroupV2Record {
|
||||||
}
|
}
|
||||||
|
|
||||||
message AccountRecord {
|
message AccountRecord {
|
||||||
|
enum PhoneNumberSharingMode {
|
||||||
|
EVERYBODY = 0;
|
||||||
|
CONTACTS_ONLY = 1;
|
||||||
|
NOBODY = 2;
|
||||||
|
}
|
||||||
|
|
||||||
message PinnedConversation {
|
message PinnedConversation {
|
||||||
message Contact {
|
message Contact {
|
||||||
optional string uuid = 1;
|
optional string uuid = 1;
|
||||||
|
@ -106,16 +112,18 @@ message AccountRecord {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
optional bytes profileKey = 1;
|
optional bytes profileKey = 1;
|
||||||
optional string givenName = 2;
|
optional string givenName = 2;
|
||||||
optional string familyName = 3;
|
optional string familyName = 3;
|
||||||
optional string avatarUrl = 4;
|
optional string avatarUrl = 4;
|
||||||
optional bool noteToSelfArchived = 5;
|
optional bool noteToSelfArchived = 5;
|
||||||
optional bool readReceipts = 6;
|
optional bool readReceipts = 6;
|
||||||
optional bool sealedSenderIndicators = 7;
|
optional bool sealedSenderIndicators = 7;
|
||||||
optional bool typingIndicators = 8;
|
optional bool typingIndicators = 8;
|
||||||
optional bool proxiedLinkPreviews = 9;
|
optional bool proxiedLinkPreviews = 9;
|
||||||
optional bool noteToSelfMarkedUnread = 10;
|
optional bool noteToSelfMarkedUnread = 10;
|
||||||
optional bool linkPreviews = 11;
|
optional bool linkPreviews = 11;
|
||||||
repeated PinnedConversation pinnedConversations = 14;
|
optional PhoneNumberSharingMode phoneNumberSharingMode = 12;
|
||||||
|
optional bool notDiscoverableByPhoneNumber = 13;
|
||||||
|
repeated PinnedConversation pinnedConversations = 14;
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,4 +1,4 @@
|
||||||
// Copyright 2020 Signal Messenger, LLC
|
// Copyright 2020-2021 Signal Messenger, LLC
|
||||||
// SPDX-License-Identifier: AGPL-3.0-only
|
// SPDX-License-Identifier: AGPL-3.0-only
|
||||||
|
|
||||||
import { isNumber } from 'lodash';
|
import { isNumber } from 'lodash';
|
||||||
|
@ -22,6 +22,16 @@ import {
|
||||||
waitThenMaybeUpdateGroup,
|
waitThenMaybeUpdateGroup,
|
||||||
waitThenRespondToGroupV2Migration,
|
waitThenRespondToGroupV2Migration,
|
||||||
} from '../groups';
|
} from '../groups';
|
||||||
|
import { assert } from '../util/assert';
|
||||||
|
import { missingCaseError } from '../util/missingCaseError';
|
||||||
|
import {
|
||||||
|
PhoneNumberSharingMode,
|
||||||
|
parsePhoneNumberSharingMode,
|
||||||
|
} from '../util/phoneNumberSharingMode';
|
||||||
|
import {
|
||||||
|
PhoneNumberDiscoverability,
|
||||||
|
parsePhoneNumberDiscoverability,
|
||||||
|
} from '../util/phoneNumberDiscoverability';
|
||||||
import { ConversationModel } from '../models/conversations';
|
import { ConversationModel } from '../models/conversations';
|
||||||
import { ConversationAttributesTypeType } from '../model-types.d';
|
import { ConversationAttributesTypeType } from '../model-types.d';
|
||||||
|
|
||||||
|
@ -158,6 +168,43 @@ export async function toAccountRecord(
|
||||||
window.storage.get('typingIndicators')
|
window.storage.get('typingIndicators')
|
||||||
);
|
);
|
||||||
accountRecord.linkPreviews = Boolean(window.storage.get('linkPreviews'));
|
accountRecord.linkPreviews = Boolean(window.storage.get('linkPreviews'));
|
||||||
|
|
||||||
|
const PHONE_NUMBER_SHARING_MODE_ENUM =
|
||||||
|
window.textsecure.protobuf.AccountRecord.PhoneNumberSharingMode;
|
||||||
|
const phoneNumberSharingMode = parsePhoneNumberSharingMode(
|
||||||
|
window.storage.get('phoneNumberSharingMode')
|
||||||
|
);
|
||||||
|
switch (phoneNumberSharingMode) {
|
||||||
|
case PhoneNumberSharingMode.Everybody:
|
||||||
|
accountRecord.phoneNumberSharingMode =
|
||||||
|
PHONE_NUMBER_SHARING_MODE_ENUM.EVERYBODY;
|
||||||
|
break;
|
||||||
|
case PhoneNumberSharingMode.ContactsOnly:
|
||||||
|
accountRecord.phoneNumberSharingMode =
|
||||||
|
PHONE_NUMBER_SHARING_MODE_ENUM.CONTACTS_ONLY;
|
||||||
|
break;
|
||||||
|
case PhoneNumberSharingMode.Nobody:
|
||||||
|
accountRecord.phoneNumberSharingMode =
|
||||||
|
PHONE_NUMBER_SHARING_MODE_ENUM.NOBODY;
|
||||||
|
break;
|
||||||
|
default:
|
||||||
|
throw missingCaseError(phoneNumberSharingMode);
|
||||||
|
}
|
||||||
|
|
||||||
|
const phoneNumberDiscoverability = parsePhoneNumberDiscoverability(
|
||||||
|
window.storage.get('phoneNumberDiscoverability')
|
||||||
|
);
|
||||||
|
switch (phoneNumberDiscoverability) {
|
||||||
|
case PhoneNumberDiscoverability.Discoverable:
|
||||||
|
accountRecord.notDiscoverableByPhoneNumber = false;
|
||||||
|
break;
|
||||||
|
case PhoneNumberDiscoverability.NotDiscoverable:
|
||||||
|
accountRecord.notDiscoverableByPhoneNumber = true;
|
||||||
|
break;
|
||||||
|
default:
|
||||||
|
throw missingCaseError(phoneNumberDiscoverability);
|
||||||
|
}
|
||||||
|
|
||||||
const pinnedConversations = window.storage
|
const pinnedConversations = window.storage
|
||||||
.get<Array<string>>('pinnedConversationIds', [])
|
.get<Array<string>>('pinnedConversationIds', [])
|
||||||
.map(id => {
|
.map(id => {
|
||||||
|
@ -655,8 +702,10 @@ export async function mergeAccountRecord(
|
||||||
const {
|
const {
|
||||||
avatarUrl,
|
avatarUrl,
|
||||||
linkPreviews,
|
linkPreviews,
|
||||||
|
notDiscoverableByPhoneNumber,
|
||||||
noteToSelfArchived,
|
noteToSelfArchived,
|
||||||
noteToSelfMarkedUnread,
|
noteToSelfMarkedUnread,
|
||||||
|
phoneNumberSharingMode,
|
||||||
pinnedConversations: remotelyPinnedConversationClasses,
|
pinnedConversations: remotelyPinnedConversationClasses,
|
||||||
profileKey,
|
profileKey,
|
||||||
readReceipts,
|
readReceipts,
|
||||||
|
@ -678,6 +727,36 @@ export async function mergeAccountRecord(
|
||||||
window.storage.put('linkPreviews', linkPreviews);
|
window.storage.put('linkPreviews', linkPreviews);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
const PHONE_NUMBER_SHARING_MODE_ENUM =
|
||||||
|
window.textsecure.protobuf.AccountRecord.PhoneNumberSharingMode;
|
||||||
|
let phoneNumberSharingModeToStore: PhoneNumberSharingMode;
|
||||||
|
switch (phoneNumberSharingMode) {
|
||||||
|
case undefined:
|
||||||
|
case null:
|
||||||
|
case PHONE_NUMBER_SHARING_MODE_ENUM.EVERYBODY:
|
||||||
|
phoneNumberSharingModeToStore = PhoneNumberSharingMode.Everybody;
|
||||||
|
break;
|
||||||
|
case PHONE_NUMBER_SHARING_MODE_ENUM.CONTACTS_ONLY:
|
||||||
|
phoneNumberSharingModeToStore = PhoneNumberSharingMode.ContactsOnly;
|
||||||
|
break;
|
||||||
|
case PHONE_NUMBER_SHARING_MODE_ENUM.NOBODY:
|
||||||
|
phoneNumberSharingModeToStore = PhoneNumberSharingMode.Nobody;
|
||||||
|
break;
|
||||||
|
default:
|
||||||
|
assert(
|
||||||
|
false,
|
||||||
|
`storageService.mergeAccountRecord: Got an unexpected phone number sharing mode: ${phoneNumberSharingMode}. Falling back to default`
|
||||||
|
);
|
||||||
|
phoneNumberSharingModeToStore = PhoneNumberSharingMode.Everybody;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
window.storage.put('phoneNumberSharingMode', phoneNumberSharingModeToStore);
|
||||||
|
|
||||||
|
const discoverability = notDiscoverableByPhoneNumber
|
||||||
|
? PhoneNumberDiscoverability.NotDiscoverable
|
||||||
|
: PhoneNumberDiscoverability.Discoverable;
|
||||||
|
window.storage.put('phoneNumberDiscoverability', discoverability);
|
||||||
|
|
||||||
if (profileKey) {
|
if (profileKey) {
|
||||||
window.storage.put('profileKey', profileKey.toArrayBuffer());
|
window.storage.put('profileKey', profileKey.toArrayBuffer());
|
||||||
}
|
}
|
||||||
|
|
10
ts/textsecure.d.ts
vendored
10
ts/textsecure.d.ts
vendored
|
@ -1107,8 +1107,16 @@ export declare class PinnedConversationClass {
|
||||||
groupMasterKey?: ProtoBinaryType;
|
groupMasterKey?: ProtoBinaryType;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
declare enum AccountRecordPhoneNumberSharingMode {
|
||||||
|
EVERYBODY = 0,
|
||||||
|
CONTACTS_ONLY = 1,
|
||||||
|
NOBODY = 2,
|
||||||
|
}
|
||||||
|
|
||||||
export declare class AccountRecordClass {
|
export declare class AccountRecordClass {
|
||||||
|
static PhoneNumberSharingMode: typeof AccountRecordPhoneNumberSharingMode;
|
||||||
static PinnedConversation: typeof PinnedConversationClass;
|
static PinnedConversation: typeof PinnedConversationClass;
|
||||||
|
|
||||||
static decode: (
|
static decode: (
|
||||||
data: ArrayBuffer | ByteBufferClass,
|
data: ArrayBuffer | ByteBufferClass,
|
||||||
encoding?: string
|
encoding?: string
|
||||||
|
@ -1124,6 +1132,8 @@ export declare class AccountRecordClass {
|
||||||
sealedSenderIndicators?: boolean | null;
|
sealedSenderIndicators?: boolean | null;
|
||||||
typingIndicators?: boolean | null;
|
typingIndicators?: boolean | null;
|
||||||
linkPreviews?: boolean | null;
|
linkPreviews?: boolean | null;
|
||||||
|
phoneNumberSharingMode?: AccountRecordPhoneNumberSharingMode;
|
||||||
|
notDiscoverableByPhoneNumber?: boolean;
|
||||||
pinnedConversations?: PinnedConversationClass[];
|
pinnedConversations?: PinnedConversationClass[];
|
||||||
noteToSelfMarkedUnread?: boolean;
|
noteToSelfMarkedUnread?: boolean;
|
||||||
|
|
||||||
|
|
15
ts/util/phoneNumberDiscoverability.ts
Normal file
15
ts/util/phoneNumberDiscoverability.ts
Normal file
|
@ -0,0 +1,15 @@
|
||||||
|
// Copyright 2021 Signal Messenger, LLC
|
||||||
|
// SPDX-License-Identifier: AGPL-3.0-only
|
||||||
|
|
||||||
|
import { makeEnumParser } from './enum';
|
||||||
|
|
||||||
|
// These strings are saved to disk, so be careful when changing them.
|
||||||
|
export enum PhoneNumberDiscoverability {
|
||||||
|
Discoverable = 'Discoverable',
|
||||||
|
NotDiscoverable = 'NotDiscoverable',
|
||||||
|
}
|
||||||
|
|
||||||
|
export const parsePhoneNumberDiscoverability = makeEnumParser(
|
||||||
|
PhoneNumberDiscoverability,
|
||||||
|
PhoneNumberDiscoverability.Discoverable
|
||||||
|
);
|
16
ts/util/phoneNumberSharingMode.ts
Normal file
16
ts/util/phoneNumberSharingMode.ts
Normal file
|
@ -0,0 +1,16 @@
|
||||||
|
// Copyright 2021 Signal Messenger, LLC
|
||||||
|
// SPDX-License-Identifier: AGPL-3.0-only
|
||||||
|
|
||||||
|
import { makeEnumParser } from './enum';
|
||||||
|
|
||||||
|
// These strings are saved to disk, so be careful when changing them.
|
||||||
|
export enum PhoneNumberSharingMode {
|
||||||
|
Everybody = 'Everybody',
|
||||||
|
ContactsOnly = 'ContactsOnly',
|
||||||
|
Nobody = 'Nobody',
|
||||||
|
}
|
||||||
|
|
||||||
|
export const parsePhoneNumberSharingMode = makeEnumParser(
|
||||||
|
PhoneNumberSharingMode,
|
||||||
|
PhoneNumberSharingMode.Everybody
|
||||||
|
);
|
Loading…
Add table
Reference in a new issue