2021-04-05 16:03:27 +00:00
|
|
|
// Copyright 2021 Signal Messenger, LLC
|
|
|
|
// SPDX-License-Identifier: AGPL-3.0-only
|
|
|
|
|
2022-08-15 21:53:33 +00:00
|
|
|
import type { ConversationAttributesType } from '../model-types.d';
|
|
|
|
|
2021-04-05 16:03:27 +00:00
|
|
|
import { makeEnumParser } from './enum';
|
2022-08-15 21:53:33 +00:00
|
|
|
import { missingCaseError } from './missingCaseError';
|
|
|
|
import { isDirectConversation, isMe } from './whatTypeOfConversation';
|
2021-04-05 16:03:27 +00:00
|
|
|
|
|
|
|
// 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
|
|
|
|
);
|
2022-08-15 21:53:33 +00:00
|
|
|
|
|
|
|
export const shouldSharePhoneNumberWith = (
|
|
|
|
conversation: ConversationAttributesType
|
|
|
|
): boolean => {
|
|
|
|
if (!isDirectConversation(conversation) || isMe(conversation)) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
const phoneNumberSharingMode = parsePhoneNumberSharingMode(
|
|
|
|
window.storage.get('phoneNumberSharingMode')
|
|
|
|
);
|
|
|
|
|
|
|
|
switch (phoneNumberSharingMode) {
|
|
|
|
case PhoneNumberSharingMode.Everybody:
|
|
|
|
return true;
|
|
|
|
case PhoneNumberSharingMode.ContactsOnly:
|
|
|
|
case PhoneNumberSharingMode.Nobody:
|
|
|
|
return false;
|
|
|
|
default:
|
|
|
|
throw missingCaseError(phoneNumberSharingMode);
|
|
|
|
}
|
|
|
|
};
|