From 26b90ba44adf1e08f820b23c5d905e5743c1f44a Mon Sep 17 00:00:00 2001 From: Josh Perez <60019601+josh-signal@users.noreply.github.com> Date: Thu, 22 Apr 2021 07:20:01 -0700 Subject: [PATCH] Add return types for two MessageModel "getProps" methods --- ts/models/messages.ts | 84 +++++++++++++++++++++++++++++++++++++------ 1 file changed, 73 insertions(+), 11 deletions(-) diff --git a/ts/models/messages.ts b/ts/models/messages.ts index a49f92a7f0b9..17c8847137d1 100644 --- a/ts/models/messages.ts +++ b/ts/models/messages.ts @@ -50,6 +50,74 @@ import { MIMEType } from '../types/MIME'; /* eslint-disable camelcase */ /* eslint-disable more/no-then */ +type PropsForMessageDetail = Pick< + SmartMessageDetailPropsType, + 'sentAt' | 'receivedAt' | 'message' | 'errors' | 'contacts' +>; +type PropsForMessage = Omit; + +type FormattedContact = Partial & + Pick; + +type PropsForUnsupportedMessage = { + canProcessNow: boolean; + contact: FormattedContact; +}; + +type MessageBubbleProps = + | { + type: 'unsupportedMessage'; + data: PropsForUnsupportedMessage; + } + | { + type: 'groupV2Change'; + data: GroupsV2Props; + } + | { + type: 'groupV1Migration'; + data: GroupV1MigrationPropsType; + } + | { + type: 'linkNotification'; + data: null; + } + | { + type: 'timerNotification'; + data?: TimerNotificationProps; + } + | { + type: 'safetyNumberNotification'; + data: SafetyNumberNotificationProps; + } + | { + type: 'verificationNotification'; + data: VerificationNotificationProps; + } + | { + type: 'groupNotification'; + data: GroupNotificationProps; + } + | { + type: 'resetSessionNotification'; + data: ResetSessionNotificationProps; + } + | { + type: 'callHistory'; + data?: CallingNotificationType; + } + | { + type: 'profileChange'; + data: ProfileChangeNotificationPropsType; + } + | { + type: 'chatSessionRefreshed'; + data: null; + } + | { + type: 'message'; + data: PropsForMessage; + }; + declare const _: typeof window._; window.Whisper = window.Whisper || {}; @@ -244,7 +312,7 @@ export class MessageModel extends window.Backbone.Model { } // Top-level prop generation for the message bubble - getPropsForBubble(): WhatIsThis { + getPropsForBubble(): MessageBubbleProps { if (this.isUnsupportedMessage()) { return { type: 'unsupportedMessage', @@ -324,10 +392,7 @@ export class MessageModel extends window.Backbone.Model { }; } - getPropsForMessageDetail(): Pick< - SmartMessageDetailPropsType, - 'sentAt' | 'receivedAt' | 'message' | 'errors' | 'contacts' - > { + getPropsForMessageDetail(): PropsForMessageDetail { const newIdentity = window.i18n('newIdentity'); const OUTGOING_KEY_ERROR = 'OutgoingIdentityKeyError'; @@ -481,7 +546,7 @@ export class MessageModel extends window.Backbone.Model { } // Props for each message type - getPropsForUnsupportedMessage(): WhatIsThis { + getPropsForUnsupportedMessage(): PropsForUnsupportedMessage { const requiredVersion = this.get('requiredProtocolVersion'); // eslint-disable-next-line @typescript-eslint/no-non-null-assertion const canProcessNow = this.CURRENT_PROTOCOL_VERSION! >= requiredVersion!; @@ -815,7 +880,7 @@ export class MessageModel extends window.Backbone.Model { } // Note: interactionMode is mixed in via selectors/conversations._messageSelector - getPropsForMessage(): Omit { + getPropsForMessage(): PropsForMessage { const sourceId = this.getContactId(); const contact = this.findAndFormatContact(sourceId); const contactModel = this.findContact(sourceId); @@ -925,10 +990,7 @@ export class MessageModel extends window.Backbone.Model { } // Dependencies of prop-generation functions - findAndFormatContact( - identifier?: string - ): Partial & - Pick { + findAndFormatContact(identifier?: string): FormattedContact { if (!identifier) { return PLACEHOLDER_CONTACT; }