From fe040a2873deb11b24915daf10c7c4567ef63d82 Mon Sep 17 00:00:00 2001 From: Fedor Indutny <79877362+indutny-signal@users.noreply.github.com> Date: Thu, 19 Aug 2021 18:56:39 -0700 Subject: [PATCH] Rename ContactType to EmbeddedContactType --- js/modules/signal.js | 4 ++-- ts/components/conversation/ContactDetail.stories.tsx | 2 +- ts/components/conversation/ContactDetail.tsx | 6 +++--- ts/components/conversation/EmbeddedContact.stories.tsx | 2 +- ts/components/conversation/EmbeddedContact.tsx | 4 ++-- ts/components/conversation/Message.tsx | 6 +++--- ts/components/conversation/_contactUtil.tsx | 8 ++++---- ts/model-types.d.ts | 4 ++-- ts/models/conversations.ts | 4 ++-- ts/models/messages.ts | 5 +++-- ts/state/selectors/message.ts | 9 ++++++--- .../types/{Contact_test.ts => EmbeddedContact_test.ts} | 10 +++++----- ts/types/{Contact.tsx => EmbeddedContact.ts} | 10 +++++----- ts/types/Message.ts | 4 ++-- ts/views/conversation_view.ts | 6 +++--- ts/window.d.ts | 4 ++-- 16 files changed, 46 insertions(+), 42 deletions(-) rename ts/test-node/types/{Contact_test.ts => EmbeddedContact_test.ts} (94%) rename ts/types/{Contact.tsx => EmbeddedContact.ts} (92%) diff --git a/js/modules/signal.js b/js/modules/signal.js index 66ea3522f..c93051158 100644 --- a/js/modules/signal.js +++ b/js/modules/signal.js @@ -137,7 +137,7 @@ const searchSelectors = require('../../ts/state/selectors/search'); // Types const AttachmentType = require('../../ts/types/Attachment'); const VisualAttachment = require('./types/visual_attachment'); -const Contact = require('../../ts/types/Contact'); +const EmbeddedContact = require('../../ts/types/EmbeddedContact'); const Conversation = require('./types/conversation'); const Errors = require('../../ts/types/errors'); const MediaGalleryMessage = require('../../ts/components/conversation/media-gallery/types/Message'); @@ -429,7 +429,7 @@ exports.setup = (options = {}) => { const Types = { Attachment: AttachmentType, - Contact, + EmbeddedContact, Conversation, Errors, Message: MessageType, diff --git a/ts/components/conversation/ContactDetail.stories.tsx b/ts/components/conversation/ContactDetail.stories.tsx index a02fff04c..8225d3285 100644 --- a/ts/components/conversation/ContactDetail.stories.tsx +++ b/ts/components/conversation/ContactDetail.stories.tsx @@ -8,7 +8,7 @@ import { boolean } from '@storybook/addon-knobs'; import { storiesOf } from '@storybook/react'; import { ContactDetail, Props } from './ContactDetail'; -import { AddressType, ContactFormType } from '../../types/Contact'; +import { AddressType, ContactFormType } from '../../types/EmbeddedContact'; import { setup as setupI18n } from '../../../js/modules/i18n'; import enMessages from '../../../_locales/en/messages.json'; import { IMAGE_GIF } from '../../types/MIME'; diff --git a/ts/components/conversation/ContactDetail.tsx b/ts/components/conversation/ContactDetail.tsx index 522127901..1074e972e 100644 --- a/ts/components/conversation/ContactDetail.tsx +++ b/ts/components/conversation/ContactDetail.tsx @@ -6,11 +6,11 @@ import React from 'react'; import { AddressType, ContactFormType, - ContactType, + EmbeddedContactType, Email, Phone, PostalAddress, -} from '../../types/Contact'; +} from '../../types/EmbeddedContact'; import { missingCaseError } from '../../util/missingCaseError'; import { @@ -22,7 +22,7 @@ import { import { LocalizerType } from '../../types/Util'; export type Props = { - contact: ContactType; + contact: EmbeddedContactType; hasSignalAccount: boolean; i18n: LocalizerType; onSendMessage: () => void; diff --git a/ts/components/conversation/EmbeddedContact.stories.tsx b/ts/components/conversation/EmbeddedContact.stories.tsx index 2ca89013f..b361b6eae 100644 --- a/ts/components/conversation/EmbeddedContact.stories.tsx +++ b/ts/components/conversation/EmbeddedContact.stories.tsx @@ -10,7 +10,7 @@ import { storiesOf } from '@storybook/react'; import { EmbeddedContact, Props } from './EmbeddedContact'; import { setup as setupI18n } from '../../../js/modules/i18n'; import enMessages from '../../../_locales/en/messages.json'; -import { ContactFormType } from '../../types/Contact'; +import { ContactFormType } from '../../types/EmbeddedContact'; import { IMAGE_GIF } from '../../types/MIME'; const i18n = setupI18n('en', enMessages); diff --git a/ts/components/conversation/EmbeddedContact.tsx b/ts/components/conversation/EmbeddedContact.tsx index 56e85e860..47c1f8aae 100644 --- a/ts/components/conversation/EmbeddedContact.tsx +++ b/ts/components/conversation/EmbeddedContact.tsx @@ -4,7 +4,7 @@ import React from 'react'; import classNames from 'classnames'; -import { ContactType } from '../../types/Contact'; +import { EmbeddedContactType } from '../../types/EmbeddedContact'; import { LocalizerType } from '../../types/Util'; import { @@ -14,7 +14,7 @@ import { } from './_contactUtil'; export type Props = { - contact: ContactType; + contact: EmbeddedContactType; i18n: LocalizerType; isIncoming: boolean; withContentAbove: boolean; diff --git a/ts/components/conversation/Message.tsx b/ts/components/conversation/Message.tsx index b153bf13b..7dd6a659c 100644 --- a/ts/components/conversation/Message.tsx +++ b/ts/components/conversation/Message.tsx @@ -49,7 +49,7 @@ import { isVideo, isGIF, } from '../../types/Attachment'; -import { ContactType } from '../../types/Contact'; +import { EmbeddedContactType } from '../../types/EmbeddedContact'; import { getIncrement } from '../../util/timer'; import { isFileDangerous } from '../../util/isFileDangerous'; @@ -129,7 +129,7 @@ export type PropsData = { direction: DirectionType; timestamp: number; status?: MessageStatusType; - contact?: ContactType; + contact?: EmbeddedContactType; author: Pick< ConversationType, | 'acceptedMessageRequest' @@ -216,7 +216,7 @@ export type PropsActions = { openConversation: (conversationId: string, messageId?: string) => void; showContactDetail: (options: { - contact: ContactType; + contact: EmbeddedContactType; signalAccount?: string; }) => void; showContactModal: (contactId: string) => void; diff --git a/ts/components/conversation/_contactUtil.tsx b/ts/components/conversation/_contactUtil.tsx index 7f3d95873..9074909e7 100644 --- a/ts/components/conversation/_contactUtil.tsx +++ b/ts/components/conversation/_contactUtil.tsx @@ -9,7 +9,7 @@ import { Spinner } from '../Spinner'; import { LocalizerType } from '../../types/Util'; import { AvatarColors } from '../../types/Colors'; -import { ContactType, getName } from '../../types/Contact'; +import { EmbeddedContactType, getName } from '../../types/EmbeddedContact'; // This file starts with _ to keep it from showing up in the StyleGuide. @@ -19,7 +19,7 @@ export function renderAvatar({ size, direction, }: { - contact: ContactType; + contact: EmbeddedContactType; i18n: LocalizerType; size: 28 | 52 | 80; direction?: 'outgoing' | 'incoming'; @@ -65,7 +65,7 @@ export function renderName({ isIncoming, module, }: { - contact: ContactType; + contact: EmbeddedContactType; isIncoming: boolean; module: string; }): JSX.Element { @@ -86,7 +86,7 @@ export function renderContactShorthand({ isIncoming, module, }: { - contact: ContactType; + contact: EmbeddedContactType; isIncoming: boolean; module: string; }): JSX.Element { diff --git a/ts/model-types.d.ts b/ts/model-types.d.ts index f06b0f0b8..7f222c29c 100644 --- a/ts/model-types.d.ts +++ b/ts/model-types.d.ts @@ -23,7 +23,7 @@ import { import { GroupNameCollisionsWithIdsByTitle } from './util/groupMemberNameCollisions'; import { ConversationColorType } from './types/Colors'; import { AttachmentType, ThumbnailType } from './types/Attachment'; -import { ContactType } from './types/Contact'; +import { EmbeddedContactType } from './types/EmbeddedContact'; import { SignalService as Proto } from './protobuf'; import { AvatarDataType } from './types/Avatar'; @@ -156,7 +156,7 @@ export type MessageAttributesType = { }; sent_at: number; unidentifiedDeliveries?: Array; - contact?: Array; + contact?: Array; conversationId: string; reaction?: WhatIsThis; diff --git a/ts/models/conversations.ts b/ts/models/conversations.ts index d96123070..0ffbfecc1 100644 --- a/ts/models/conversations.ts +++ b/ts/models/conversations.ts @@ -90,7 +90,7 @@ const FIXMEU8 = Uint8Array; window.Whisper = window.Whisper || {}; const { Services, Util } = window.Signal; -const { Contact, Message } = window.Signal.Types; +const { EmbeddedContact, Message } = window.Signal.Types; const { deleteAttachmentData, doesAttachmentExist, @@ -3170,7 +3170,7 @@ export class ConversationModel extends window.Backbone async makeQuote( quotedMessage: typeof window.Whisper.MessageType ): Promise { - const { getName } = Contact; + const { getName } = EmbeddedContact; // eslint-disable-next-line @typescript-eslint/no-non-null-assertion const contact = quotedMessage.getContact()!; const attachments = quotedMessage.get('attachments'); diff --git a/ts/models/messages.ts b/ts/models/messages.ts index 15fcc645f..813e47d28 100644 --- a/ts/models/messages.ts +++ b/ts/models/messages.ts @@ -129,7 +129,7 @@ const { Message: TypedMessage, Attachment, MIME, - Contact, + EmbeddedContact, Errors, } = window.Signal.Types; const { @@ -678,7 +678,8 @@ export class MessageModel extends window.Backbone.Model { const contacts = this.get('contact'); if (contacts && contacts.length) { return { - text: Contact.getName(contacts[0]) || window.i18n('unknownContact'), + text: + EmbeddedContact.getName(contacts[0]) || window.i18n('unknownContact'), emoji: '👤', }; } diff --git a/ts/state/selectors/message.ts b/ts/state/selectors/message.ts index 762d2cb94..0f7d49e3a 100644 --- a/ts/state/selectors/message.ts +++ b/ts/state/selectors/message.ts @@ -38,7 +38,10 @@ import { QuotedAttachmentType } from '../../components/conversation/Quote'; import { getDomain, isStickerPack } from '../../types/LinkPreview'; -import { ContactType, contactSelector } from '../../types/Contact'; +import { + EmbeddedContactType, + embeddedContactSelector, +} from '../../types/EmbeddedContact'; import { AssertProps, BodyRangesType } from '../../types/Util'; import { LinkPreviewType } from '../../types/message/LinkPreviews'; import { ConversationColors } from '../../types/Colors'; @@ -1260,7 +1263,7 @@ export function getPropsForEmbeddedContact( message: MessageAttributesType, regionCode: string, accountSelector: (identifier?: string) => boolean -): ContactType | undefined { +): EmbeddedContactType | undefined { const contacts = message.contact; if (!contacts || !contacts.length) { return undefined; @@ -1270,7 +1273,7 @@ export function getPropsForEmbeddedContact( const numbers = firstContact?.number; const firstNumber = numbers && numbers[0] ? numbers[0].value : undefined; - return contactSelector(firstContact, { + return embeddedContactSelector(firstContact, { regionCode, getAbsoluteAttachmentPath: window.Signal.Migrations.getAbsoluteAttachmentPath, diff --git a/ts/test-node/types/Contact_test.ts b/ts/test-node/types/EmbeddedContact_test.ts similarity index 94% rename from ts/test-node/types/Contact_test.ts rename to ts/test-node/types/EmbeddedContact_test.ts index db97d63b0..75c67aafc 100644 --- a/ts/test-node/types/Contact_test.ts +++ b/ts/test-node/types/EmbeddedContact_test.ts @@ -4,7 +4,7 @@ import { assert } from 'chai'; import { IMAGE_GIF } from '../../types/MIME'; -import { contactSelector, getName } from '../../types/Contact'; +import { embeddedContactSelector, getName } from '../../types/EmbeddedContact'; describe('Contact', () => { describe('getName', () => { @@ -65,7 +65,7 @@ describe('Contact', () => { assert.strictEqual(actual, expected); }); }); - describe('contactSelector', () => { + describe('embeddedContactSelector', () => { const regionCode = '1'; const firstNumber = '+1202555000'; const isNumberOnSignal = false; @@ -99,7 +99,7 @@ describe('Contact', () => { isNumberOnSignal, number: undefined, }; - const actual = contactSelector(contact, { + const actual = embeddedContactSelector(contact, { regionCode, firstNumber, isNumberOnSignal, @@ -143,7 +143,7 @@ describe('Contact', () => { isNumberOnSignal, number: undefined, }; - const actual = contactSelector(contact, { + const actual = embeddedContactSelector(contact, { regionCode, firstNumber, isNumberOnSignal, @@ -186,7 +186,7 @@ describe('Contact', () => { isNumberOnSignal: true, number: undefined, }; - const actual = contactSelector(contact, { + const actual = embeddedContactSelector(contact, { regionCode, firstNumber, isNumberOnSignal: true, diff --git a/ts/types/Contact.tsx b/ts/types/EmbeddedContact.ts similarity index 92% rename from ts/types/Contact.tsx rename to ts/types/EmbeddedContact.ts index 0ccd00d81..2679bdb13 100644 --- a/ts/types/Contact.tsx +++ b/ts/types/EmbeddedContact.ts @@ -4,7 +4,7 @@ import { format as formatPhoneNumber } from './PhoneNumber'; import { AttachmentType } from './Attachment'; -export type ContactType = { +export type EmbeddedContactType = { name?: Name; number?: Array; email?: Array; @@ -68,15 +68,15 @@ type Avatar = { isProfile: boolean; }; -export function contactSelector( - contact: ContactType, +export function embeddedContactSelector( + contact: EmbeddedContactType, options: { regionCode: string; firstNumber?: string; isNumberOnSignal?: boolean; getAbsoluteAttachmentPath: (path: string) => string; } -): ContactType { +): EmbeddedContactType { const { getAbsoluteAttachmentPath, firstNumber, @@ -117,7 +117,7 @@ export function contactSelector( }; } -export function getName(contact: ContactType): string | undefined { +export function getName(contact: EmbeddedContactType): string | undefined { const { name, organization } = contact; const displayName = (name && name.displayName) || undefined; const givenName = (name && name.givenName) || undefined; diff --git a/ts/types/Message.ts b/ts/types/Message.ts index 4f5d0354b..cbc3f9928 100644 --- a/ts/types/Message.ts +++ b/ts/types/Message.ts @@ -4,7 +4,7 @@ /* eslint-disable camelcase */ import { AttachmentType } from './Attachment'; -import { ContactType } from './Contact'; +import { EmbeddedContactType } from './EmbeddedContact'; import { IndexableBoolean, IndexablePresence } from './IndexedDB'; export type Message = ( @@ -110,7 +110,7 @@ type MessageSchemaVersion5 = Partial< type MessageSchemaVersion6 = Partial< Readonly<{ - contact: Array; + contact: Array; }> >; diff --git a/ts/views/conversation_view.ts b/ts/views/conversation_view.ts index 44644d8f4..714b63417 100644 --- a/ts/views/conversation_view.ts +++ b/ts/views/conversation_view.ts @@ -65,7 +65,7 @@ import { ReadStatus } from '../messages/MessageReadStatus'; import { markViewed } from '../services/MessageUpdater'; import { viewedReceiptsJobQueue } from '../jobs/viewedReceiptsJobQueue'; import { viewSyncJobQueue } from '../jobs/viewSyncJobQueue'; -import type { ContactType } from '../types/Contact'; +import type { EmbeddedContactType } from '../types/EmbeddedContact'; import type { WhatIsThis } from '../window.d'; type AttachmentOptions = { @@ -845,7 +845,7 @@ Whisper.ConversationView = Whisper.View.extend({ this.openConversation(conversationId, messageId); }; const showContactDetail = (options: { - contact: ContactType; + contact: EmbeddedContactType; signalAccount?: string; }) => { this.showContactDetail(options); @@ -3486,7 +3486,7 @@ Whisper.ConversationView = Whisper.View.extend({ contact, signalAccount, }: { - contact: ContactType; + contact: EmbeddedContactType; signalAccount?: string; }) { const view = new Whisper.ReactWrapperView({ diff --git a/ts/window.d.ts b/ts/window.d.ts index e3b14e76a..f1b0215e2 100644 --- a/ts/window.d.ts +++ b/ts/window.d.ts @@ -36,7 +36,7 @@ import * as zkgroup from './util/zkgroup'; import { LocalizerType, BodyRangesType, BodyRangeType } from './types/Util'; import * as Attachment from './types/Attachment'; import * as MIME from './types/MIME'; -import * as Contact from './types/Contact'; +import * as EmbeddedContact from './types/EmbeddedContact'; import * as Errors from './types/errors'; import { ConversationController } from './ConversationController'; import { ReduxActions } from './state/types'; @@ -359,7 +359,7 @@ declare global { Types: { Attachment: typeof Attachment; MIME: typeof MIME; - Contact: typeof Contact; + EmbeddedContact: typeof EmbeddedContact; Conversation: { computeHash: (data: string) => Promise; deleteExternalFiles: (