2023-01-03 19:55:46 +00:00
|
|
|
// Copyright 2021 Signal Messenger, LLC
|
2021-06-17 17:15:10 +00:00
|
|
|
// SPDX-License-Identifier: AGPL-3.0-only
|
|
|
|
|
2022-12-23 00:32:03 +00:00
|
|
|
import { groupBy, isEmpty, isNumber, isObject, map, omit } from 'lodash';
|
|
|
|
import { createSelector } from 'reselect';
|
2021-06-17 17:15:10 +00:00
|
|
|
import filesize from 'filesize';
|
2022-03-23 20:23:28 +00:00
|
|
|
import getDirection from 'direction';
|
2022-07-11 23:34:55 +00:00
|
|
|
import emojiRegex from 'emoji-regex';
|
|
|
|
import LinkifyIt from 'linkify-it';
|
2023-04-20 16:31:59 +00:00
|
|
|
import type { ReadonlyDeep } from 'type-fest';
|
|
|
|
|
2022-12-21 20:44:23 +00:00
|
|
|
import type { StateType } from '../reducer';
|
2021-10-26 19:15:33 +00:00
|
|
|
import type {
|
2021-06-17 17:15:10 +00:00
|
|
|
LastMessageStatus,
|
2022-12-21 20:44:23 +00:00
|
|
|
MessageAttributesType,
|
2021-10-29 23:19:44 +00:00
|
|
|
MessageReactionType,
|
2021-06-17 17:15:10 +00:00
|
|
|
ShallowChallengeError,
|
|
|
|
} from '../../model-types.d';
|
|
|
|
|
2022-12-21 20:44:23 +00:00
|
|
|
import type {
|
|
|
|
Contact as SmartMessageDetailContact,
|
|
|
|
OwnProps as SmartMessageDetailPropsType,
|
|
|
|
} from '../smart/MessageDetail';
|
2021-10-26 19:15:33 +00:00
|
|
|
import type { TimelineItemType } from '../../components/conversation/TimelineItem';
|
|
|
|
import type { PropsData } from '../../components/conversation/Message';
|
2022-11-04 13:22:07 +00:00
|
|
|
import type { PropsData as TimelineMessagePropsData } from '../../components/conversation/TimelineMessage';
|
2022-03-23 20:23:28 +00:00
|
|
|
import { TextDirection } from '../../components/conversation/Message';
|
2021-10-26 19:15:33 +00:00
|
|
|
import type { PropsData as TimerNotificationProps } from '../../components/conversation/TimerNotification';
|
|
|
|
import type { PropsData as ChangeNumberNotificationProps } from '../../components/conversation/ChangeNumberNotification';
|
|
|
|
import type { PropsData as SafetyNumberNotificationProps } from '../../components/conversation/SafetyNumberNotification';
|
|
|
|
import type { PropsData as VerificationNotificationProps } from '../../components/conversation/VerificationNotification';
|
|
|
|
import type { PropsDataType as GroupsV2Props } from '../../components/conversation/GroupV2Change';
|
|
|
|
import type { PropsDataType as GroupV1MigrationPropsType } from '../../components/conversation/GroupV1Migration';
|
|
|
|
import type { PropsDataType as DeliveryIssuePropsType } from '../../components/conversation/DeliveryIssueNotification';
|
2022-11-30 21:47:54 +00:00
|
|
|
import type { PropsType as PaymentEventNotificationPropsType } from '../../components/conversation/PaymentEventNotification';
|
2022-12-05 22:46:54 +00:00
|
|
|
import type { PropsDataType as ConversationMergePropsType } from '../../components/conversation/ConversationMergeNotification';
|
2023-10-23 17:40:42 +00:00
|
|
|
import type { PropsDataType as PhoneNumberDiscoveryPropsType } from '../../components/conversation/PhoneNumberDiscoveryNotification';
|
2021-10-26 19:15:33 +00:00
|
|
|
import type {
|
2021-06-17 17:15:10 +00:00
|
|
|
PropsData as GroupNotificationProps,
|
|
|
|
ChangeType,
|
|
|
|
} from '../../components/conversation/GroupNotification';
|
2021-10-26 19:15:33 +00:00
|
|
|
import type { PropsType as ProfileChangeNotificationPropsType } from '../../components/conversation/ProfileChangeNotification';
|
|
|
|
import type { QuotedAttachmentType } from '../../components/conversation/Quote';
|
2021-06-17 17:15:10 +00:00
|
|
|
|
2024-02-22 21:19:50 +00:00
|
|
|
import { getDomain, isCallLink, isStickerPack } from '../../types/LinkPreview';
|
2023-08-10 16:43:33 +00:00
|
|
|
import type {
|
|
|
|
AciString,
|
|
|
|
PniString,
|
|
|
|
ServiceIdString,
|
|
|
|
} from '../../types/ServiceId';
|
2021-06-17 17:15:10 +00:00
|
|
|
|
2021-10-26 19:15:33 +00:00
|
|
|
import type { EmbeddedContactType } from '../../types/EmbeddedContact';
|
|
|
|
import { embeddedContactSelector } from '../../types/EmbeddedContact';
|
2023-10-30 18:39:14 +00:00
|
|
|
import type { HydratedBodyRangesType } from '../../types/BodyRange';
|
|
|
|
import { hydrateRanges } from '../../types/BodyRange';
|
2023-04-10 16:31:45 +00:00
|
|
|
import type { AssertProps } from '../../types/Util';
|
2021-10-26 19:15:33 +00:00
|
|
|
import type { LinkPreviewType } from '../../types/message/LinkPreviews';
|
2022-07-21 16:26:11 +00:00
|
|
|
import { getMentionsRegex } from '../../types/Message';
|
2021-07-09 19:36:10 +00:00
|
|
|
import { SignalService as Proto } from '../../protobuf';
|
2021-10-26 19:15:33 +00:00
|
|
|
import type { AttachmentType } from '../../types/Attachment';
|
2022-05-23 23:07:41 +00:00
|
|
|
import { isVoiceMessage, canBeDownloaded } from '../../types/Attachment';
|
2023-09-01 17:03:44 +00:00
|
|
|
import type { DefaultConversationColorType } from '../../types/Colors';
|
2021-08-12 18:15:55 +00:00
|
|
|
import { ReadStatus } from '../../messages/MessageReadStatus';
|
2021-06-17 17:15:10 +00:00
|
|
|
|
2021-10-26 19:15:33 +00:00
|
|
|
import type { CallingNotificationType } from '../../util/callingNotification';
|
2022-12-21 20:44:23 +00:00
|
|
|
import { getRecipients } from '../../util/getRecipients';
|
|
|
|
import { getOwn } from '../../util/getOwn';
|
2021-06-17 17:15:10 +00:00
|
|
|
import { isNotNil } from '../../util/isNotNil';
|
2021-08-02 19:26:48 +00:00
|
|
|
import { isMoreRecentThan } from '../../util/timestamp';
|
2021-10-29 23:19:44 +00:00
|
|
|
import * as iterables from '../../util/iterables';
|
|
|
|
import { strictAssert } from '../../util/assert';
|
2023-05-12 00:27:19 +00:00
|
|
|
import { canEditMessage } from '../../util/canEditMessage';
|
2021-06-17 17:15:10 +00:00
|
|
|
|
2022-07-01 00:52:03 +00:00
|
|
|
import { getAccountSelector } from './accounts';
|
2023-09-01 17:03:44 +00:00
|
|
|
import { getDefaultConversationColor } from './items';
|
2022-07-01 00:52:03 +00:00
|
|
|
import {
|
|
|
|
getContactNameColorSelector,
|
|
|
|
getConversationSelector,
|
2023-03-20 22:23:53 +00:00
|
|
|
getSelectedMessageIds,
|
|
|
|
getTargetedMessage,
|
2022-07-01 00:52:03 +00:00
|
|
|
isMissingRequiredProfileSharing,
|
2023-04-10 21:38:34 +00:00
|
|
|
getMessages,
|
2022-07-01 00:52:03 +00:00
|
|
|
} from './conversations';
|
|
|
|
import {
|
2022-12-21 20:44:23 +00:00
|
|
|
getIntl,
|
2022-07-01 00:52:03 +00:00
|
|
|
getRegionCode,
|
2022-12-21 20:44:23 +00:00
|
|
|
getUserACI,
|
2023-08-10 16:43:33 +00:00
|
|
|
getUserPNI,
|
2022-07-01 00:52:03 +00:00
|
|
|
getUserConversationId,
|
|
|
|
getUserNumber,
|
|
|
|
} from './user';
|
|
|
|
|
2021-11-11 23:45:47 +00:00
|
|
|
import type {
|
|
|
|
ConversationType,
|
|
|
|
MessageWithUIFieldsType,
|
|
|
|
} from '../ducks/conversations';
|
2021-06-17 17:15:10 +00:00
|
|
|
|
2021-10-26 19:15:33 +00:00
|
|
|
import type { AccountSelectorType } from './accounts';
|
|
|
|
import type { CallSelectorType, CallStateType } from './calling';
|
|
|
|
import type {
|
2021-06-17 17:15:10 +00:00
|
|
|
GetConversationByIdType,
|
2021-08-19 20:14:41 +00:00
|
|
|
ContactNameColorSelectorType,
|
2021-06-17 17:15:10 +00:00
|
|
|
} from './conversations';
|
2021-07-19 22:44:49 +00:00
|
|
|
import {
|
|
|
|
SendStatus,
|
|
|
|
isDelivered,
|
2021-08-31 20:58:39 +00:00
|
|
|
isFailed,
|
2021-07-19 22:44:49 +00:00
|
|
|
isMessageJustForMe,
|
|
|
|
isRead,
|
|
|
|
isSent,
|
2021-07-27 15:42:25 +00:00
|
|
|
isViewed,
|
2021-07-19 22:44:49 +00:00
|
|
|
maxStatus,
|
|
|
|
someSendStatus,
|
|
|
|
} from '../../messages/MessageSendState';
|
2021-09-17 18:27:53 +00:00
|
|
|
import * as log from '../../logging/log';
|
2021-12-04 02:10:03 +00:00
|
|
|
import { getConversationColorAttributes } from '../../util/getConversationColorAttributes';
|
2023-10-13 21:54:36 +00:00
|
|
|
import { DAY, DurationInSeconds } from '../../util/durations';
|
2022-05-10 19:02:21 +00:00
|
|
|
import { getStoryReplyText } from '../../util/getStoryReplyText';
|
2022-11-30 21:47:54 +00:00
|
|
|
import type { MessageAttributesWithPaymentEvent } from '../../messages/helpers';
|
|
|
|
import {
|
|
|
|
isIncoming,
|
|
|
|
isOutgoing,
|
|
|
|
messageHasPaymentEvent,
|
|
|
|
isStory,
|
|
|
|
} from '../../messages/helpers';
|
|
|
|
|
2022-09-09 18:35:00 +00:00
|
|
|
import { calculateExpirationTimestamp } from '../../util/expirationTimer';
|
2022-11-09 02:38:19 +00:00
|
|
|
import { isSignalConversation } from '../../util/isSignalConversation';
|
2022-11-30 21:47:54 +00:00
|
|
|
import type { AnyPaymentEvent } from '../../types/Payment';
|
|
|
|
import { isPaymentNotificationEvent } from '../../types/Payment';
|
2023-10-23 17:40:42 +00:00
|
|
|
import {
|
|
|
|
getTitleNoDefault,
|
|
|
|
getNumber,
|
|
|
|
renderNumber,
|
|
|
|
} from '../../util/getTitle';
|
2023-06-21 17:08:36 +00:00
|
|
|
import { getMessageSentTimestamp } from '../../util/getMessageSentTimestamp';
|
2023-08-09 00:53:06 +00:00
|
|
|
import type { CallHistorySelectorType } from './callHistory';
|
|
|
|
import { CallMode } from '../../types/Calling';
|
|
|
|
import { CallDirection } from '../../types/CallDisposition';
|
2023-08-21 17:09:54 +00:00
|
|
|
import { getCallIdFromEra } from '../../util/callDisposition';
|
2023-12-06 21:27:22 +00:00
|
|
|
import { LONG_MESSAGE } from '../../types/MIME';
|
2022-07-18 20:01:43 +00:00
|
|
|
|
|
|
|
export { isIncoming, isOutgoing, isStory };
|
2021-06-17 17:15:10 +00:00
|
|
|
|
2022-07-11 23:34:55 +00:00
|
|
|
const linkify = LinkifyIt();
|
2021-06-17 17:15:10 +00:00
|
|
|
|
|
|
|
type FormattedContact = Partial<ConversationType> &
|
|
|
|
Pick<
|
|
|
|
ConversationType,
|
|
|
|
| 'acceptedMessageRequest'
|
|
|
|
| 'id'
|
|
|
|
| 'isMe'
|
|
|
|
| 'sharedGroupNames'
|
|
|
|
| 'title'
|
|
|
|
| 'type'
|
|
|
|
| 'unblurredAvatarPath'
|
|
|
|
>;
|
2022-11-04 13:22:07 +00:00
|
|
|
export type PropsForMessage = Omit<TimelineMessagePropsData, 'interactionMode'>;
|
2023-03-27 23:48:57 +00:00
|
|
|
export type MessagePropsType = Omit<
|
|
|
|
PropsForMessage,
|
|
|
|
'renderingContext' | 'menu' | 'contextMenu'
|
|
|
|
>;
|
2021-06-17 17:15:10 +00:00
|
|
|
type PropsForUnsupportedMessage = {
|
|
|
|
canProcessNow: boolean;
|
|
|
|
contact: FormattedContact;
|
|
|
|
};
|
|
|
|
|
2021-08-11 16:23:21 +00:00
|
|
|
export type GetPropsForBubbleOptions = Readonly<{
|
|
|
|
conversationSelector: GetConversationByIdType;
|
2022-02-23 18:48:40 +00:00
|
|
|
ourConversationId?: string;
|
2021-08-11 16:23:21 +00:00
|
|
|
ourNumber?: string;
|
2023-08-10 16:43:33 +00:00
|
|
|
ourAci: AciString | undefined;
|
|
|
|
ourPni: PniString | undefined;
|
2023-03-20 22:23:53 +00:00
|
|
|
targetedMessageId?: string;
|
|
|
|
targetedMessageCounter?: number;
|
|
|
|
selectedMessageIds: ReadonlyArray<string> | undefined;
|
2022-02-23 18:48:40 +00:00
|
|
|
regionCode?: string;
|
2021-08-11 16:23:21 +00:00
|
|
|
callSelector: CallSelectorType;
|
2023-08-09 00:53:06 +00:00
|
|
|
callHistorySelector: CallHistorySelectorType;
|
2021-08-11 16:23:21 +00:00
|
|
|
activeCall?: CallStateType;
|
2021-08-19 20:14:41 +00:00
|
|
|
accountSelector: AccountSelectorType;
|
|
|
|
contactNameColorSelector: ContactNameColorSelectorType;
|
2023-09-01 17:03:44 +00:00
|
|
|
defaultConversationColor: DefaultConversationColorType;
|
2021-08-11 16:23:21 +00:00
|
|
|
}>;
|
|
|
|
|
2021-07-19 22:44:49 +00:00
|
|
|
export function hasErrors(
|
2021-11-11 23:45:47 +00:00
|
|
|
message: Pick<MessageWithUIFieldsType, 'errors'>
|
2021-07-19 22:44:49 +00:00
|
|
|
): boolean {
|
2021-06-17 17:15:10 +00:00
|
|
|
return message.errors ? message.errors.length > 0 : false;
|
|
|
|
}
|
|
|
|
|
|
|
|
export function getSource(
|
2023-02-24 23:18:57 +00:00
|
|
|
message: Pick<MessageAttributesType, 'type' | 'source'>,
|
2021-06-17 17:15:10 +00:00
|
|
|
ourNumber: string | undefined
|
|
|
|
): string | undefined {
|
|
|
|
if (isIncoming(message)) {
|
|
|
|
return message.source;
|
|
|
|
}
|
2021-08-02 21:19:18 +00:00
|
|
|
if (!isOutgoing(message)) {
|
2021-09-17 18:27:53 +00:00
|
|
|
log.warn('message.getSource: Called for non-incoming/non-outoing message');
|
2021-08-02 21:19:18 +00:00
|
|
|
}
|
2021-06-17 17:15:10 +00:00
|
|
|
|
|
|
|
return ourNumber;
|
|
|
|
}
|
|
|
|
|
|
|
|
export function getSourceDevice(
|
2021-11-11 23:45:47 +00:00
|
|
|
message: MessageWithUIFieldsType,
|
2021-06-17 17:15:10 +00:00
|
|
|
ourDeviceId: number
|
|
|
|
): string | number | undefined {
|
|
|
|
const { sourceDevice } = message;
|
|
|
|
|
|
|
|
if (isIncoming(message)) {
|
|
|
|
return sourceDevice;
|
|
|
|
}
|
2021-08-02 21:19:18 +00:00
|
|
|
if (!isOutgoing(message)) {
|
2021-09-17 18:27:53 +00:00
|
|
|
log.warn(
|
2021-08-02 21:19:18 +00:00
|
|
|
'message.getSourceDevice: Called for non-incoming/non-outoing message'
|
|
|
|
);
|
|
|
|
}
|
2021-06-17 17:15:10 +00:00
|
|
|
|
|
|
|
return sourceDevice || ourDeviceId;
|
|
|
|
}
|
|
|
|
|
2023-08-16 20:54:39 +00:00
|
|
|
export function getSourceServiceId(
|
|
|
|
message: Pick<MessageAttributesType, 'type' | 'sourceServiceId'>,
|
2023-08-10 16:43:33 +00:00
|
|
|
ourAci: AciString | undefined
|
|
|
|
): ServiceIdString | undefined {
|
2021-06-17 17:15:10 +00:00
|
|
|
if (isIncoming(message)) {
|
2023-08-16 20:54:39 +00:00
|
|
|
return message.sourceServiceId;
|
2021-06-17 17:15:10 +00:00
|
|
|
}
|
2021-08-02 21:19:18 +00:00
|
|
|
if (!isOutgoing(message)) {
|
2021-09-17 18:27:53 +00:00
|
|
|
log.warn(
|
2023-08-16 20:54:39 +00:00
|
|
|
'message.getSourceServiceId: Called for non-incoming/non-outoing message'
|
2021-08-02 21:19:18 +00:00
|
|
|
);
|
|
|
|
}
|
2021-06-17 17:15:10 +00:00
|
|
|
|
2023-08-10 16:43:33 +00:00
|
|
|
return ourAci;
|
2021-06-17 17:15:10 +00:00
|
|
|
}
|
|
|
|
|
2021-10-28 22:39:16 +00:00
|
|
|
export type GetContactOptions = Pick<
|
|
|
|
GetPropsForBubbleOptions,
|
2023-08-10 16:43:33 +00:00
|
|
|
'conversationSelector' | 'ourConversationId' | 'ourNumber' | 'ourAci'
|
2021-10-28 22:39:16 +00:00
|
|
|
>;
|
|
|
|
|
2021-12-10 22:51:54 +00:00
|
|
|
export function getContactId(
|
2021-11-11 23:45:47 +00:00
|
|
|
message: MessageWithUIFieldsType,
|
2021-10-28 22:39:16 +00:00
|
|
|
{
|
|
|
|
conversationSelector,
|
|
|
|
ourConversationId,
|
|
|
|
ourNumber,
|
2023-08-10 16:43:33 +00:00
|
|
|
ourAci,
|
2021-10-28 22:39:16 +00:00
|
|
|
}: GetContactOptions
|
2022-02-23 18:48:40 +00:00
|
|
|
): string | undefined {
|
2021-06-17 17:15:10 +00:00
|
|
|
const source = getSource(message, ourNumber);
|
2023-08-16 20:54:39 +00:00
|
|
|
const sourceServiceId = getSourceServiceId(message, ourAci);
|
2021-06-17 17:15:10 +00:00
|
|
|
|
2023-08-16 20:54:39 +00:00
|
|
|
if (!source && !sourceServiceId) {
|
2021-06-17 17:15:10 +00:00
|
|
|
return ourConversationId;
|
|
|
|
}
|
|
|
|
|
2023-08-16 20:54:39 +00:00
|
|
|
const conversation = conversationSelector(sourceServiceId || source);
|
2021-06-17 17:15:10 +00:00
|
|
|
return conversation.id;
|
|
|
|
}
|
|
|
|
|
2021-08-11 16:23:21 +00:00
|
|
|
// TODO: DESKTOP-2145
|
2021-06-17 17:15:10 +00:00
|
|
|
export function getContact(
|
2021-11-11 23:45:47 +00:00
|
|
|
message: MessageWithUIFieldsType,
|
2021-08-11 16:23:21 +00:00
|
|
|
{
|
|
|
|
conversationSelector,
|
|
|
|
ourConversationId,
|
|
|
|
ourNumber,
|
2023-08-10 16:43:33 +00:00
|
|
|
ourAci,
|
2021-08-11 16:23:21 +00:00
|
|
|
}: GetContactOptions
|
2021-06-17 17:15:10 +00:00
|
|
|
): ConversationType {
|
|
|
|
const source = getSource(message, ourNumber);
|
2023-08-16 20:54:39 +00:00
|
|
|
const sourceServiceId = getSourceServiceId(message, ourAci);
|
2021-06-17 17:15:10 +00:00
|
|
|
|
2023-08-16 20:54:39 +00:00
|
|
|
if (!source && !sourceServiceId) {
|
2021-06-17 17:15:10 +00:00
|
|
|
return conversationSelector(ourConversationId);
|
|
|
|
}
|
|
|
|
|
2023-08-16 20:54:39 +00:00
|
|
|
return conversationSelector(sourceServiceId || source);
|
2021-06-17 17:15:10 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
export function getConversation(
|
2021-11-11 23:45:47 +00:00
|
|
|
message: Pick<MessageWithUIFieldsType, 'conversationId'>,
|
2021-06-17 17:15:10 +00:00
|
|
|
conversationSelector: GetConversationByIdType
|
|
|
|
): ConversationType {
|
|
|
|
return conversationSelector(message.conversationId);
|
|
|
|
}
|
|
|
|
|
|
|
|
// Message
|
|
|
|
|
2023-01-19 19:56:02 +00:00
|
|
|
export const getAttachmentsForMessage = ({
|
|
|
|
sticker,
|
|
|
|
attachments = [],
|
|
|
|
}: MessageWithUIFieldsType): Array<AttachmentType> => {
|
|
|
|
if (sticker && sticker.data) {
|
|
|
|
const { data } = sticker;
|
2021-06-17 17:15:10 +00:00
|
|
|
|
2023-01-19 19:56:02 +00:00
|
|
|
// We don't show anything if we don't have the sticker or the blurhash...
|
|
|
|
if (!data.blurHash && (data.pending || !data.path)) {
|
|
|
|
return [];
|
2021-08-11 16:23:21 +00:00
|
|
|
}
|
2021-06-17 17:15:10 +00:00
|
|
|
|
2023-01-19 19:56:02 +00:00
|
|
|
return [
|
|
|
|
{
|
|
|
|
...data,
|
|
|
|
// We want to show the blurhash for stickers, not the spinner
|
|
|
|
pending: false,
|
|
|
|
url: data.path
|
|
|
|
? window.Signal.Migrations.getAbsoluteAttachmentPath(data.path)
|
|
|
|
: undefined,
|
|
|
|
},
|
|
|
|
];
|
2021-08-11 16:23:21 +00:00
|
|
|
}
|
2023-12-06 21:27:22 +00:00
|
|
|
return (
|
|
|
|
attachments
|
|
|
|
.filter(attachment => !attachment.error || canBeDownloaded(attachment))
|
|
|
|
// Long message attachments are removed from message.attachments quickly,
|
|
|
|
// but in case they are still around, let's make sure not to show them
|
|
|
|
.filter(attachment => attachment.contentType !== LONG_MESSAGE)
|
|
|
|
.map(attachment => getPropsForAttachment(attachment))
|
|
|
|
.filter(isNotNil)
|
|
|
|
);
|
2023-01-19 19:56:02 +00:00
|
|
|
};
|
2021-06-17 17:15:10 +00:00
|
|
|
|
2023-01-19 19:56:02 +00:00
|
|
|
export const processBodyRanges = (
|
|
|
|
{ bodyRanges }: Pick<MessageWithUIFieldsType, 'bodyRanges'>,
|
|
|
|
options: { conversationSelector: GetConversationByIdType }
|
|
|
|
): HydratedBodyRangesType | undefined => {
|
|
|
|
if (!bodyRanges) {
|
|
|
|
return undefined;
|
2022-12-23 00:32:03 +00:00
|
|
|
}
|
2023-01-19 19:56:02 +00:00
|
|
|
|
2023-04-12 00:16:46 +00:00
|
|
|
return hydrateRanges(bodyRanges, options.conversationSelector)?.sort(
|
|
|
|
(a, b) => b.start - a.start
|
|
|
|
);
|
2023-04-10 16:31:45 +00:00
|
|
|
};
|
|
|
|
|
2022-12-23 00:32:03 +00:00
|
|
|
const getAuthorForMessage = (
|
|
|
|
message: MessageWithUIFieldsType,
|
|
|
|
options: GetContactOptions
|
|
|
|
): PropsData['author'] => {
|
|
|
|
const {
|
|
|
|
acceptedMessageRequest,
|
|
|
|
avatarPath,
|
|
|
|
badges,
|
|
|
|
color,
|
|
|
|
id,
|
|
|
|
isMe,
|
|
|
|
name,
|
|
|
|
phoneNumber,
|
|
|
|
profileName,
|
|
|
|
sharedGroupNames,
|
|
|
|
title,
|
|
|
|
unblurredAvatarPath,
|
|
|
|
} = getContact(message, options);
|
|
|
|
|
|
|
|
const unsafe = {
|
|
|
|
acceptedMessageRequest,
|
|
|
|
avatarPath,
|
|
|
|
badges,
|
|
|
|
color,
|
|
|
|
id,
|
|
|
|
isMe,
|
|
|
|
name,
|
|
|
|
phoneNumber,
|
|
|
|
profileName,
|
|
|
|
sharedGroupNames,
|
|
|
|
title,
|
|
|
|
unblurredAvatarPath,
|
|
|
|
};
|
|
|
|
|
|
|
|
const safe: AssertProps<PropsData['author'], typeof unsafe> = unsafe;
|
|
|
|
|
|
|
|
return safe;
|
|
|
|
};
|
|
|
|
|
|
|
|
const getPreviewsForMessage = ({
|
|
|
|
preview: previews = [],
|
|
|
|
}: MessageWithUIFieldsType): Array<LinkPreviewType> => {
|
|
|
|
return previews.map(preview => ({
|
|
|
|
...preview,
|
|
|
|
isStickerPack: isStickerPack(preview.url),
|
2024-02-22 21:19:50 +00:00
|
|
|
isCallLink: isCallLink(preview.url),
|
2022-12-23 00:32:03 +00:00
|
|
|
domain: getDomain(preview.url),
|
|
|
|
image: preview.image ? getPropsForAttachment(preview.image) : undefined,
|
|
|
|
}));
|
|
|
|
};
|
|
|
|
|
|
|
|
const getReactionsForMessage = (
|
|
|
|
{ reactions = [] }: MessageWithUIFieldsType,
|
|
|
|
{ conversationSelector }: { conversationSelector: GetConversationByIdType }
|
|
|
|
) => {
|
|
|
|
const reactionBySender = new Map<string, MessageReactionType>();
|
|
|
|
for (const reaction of reactions) {
|
|
|
|
const existingReaction = reactionBySender.get(reaction.fromId);
|
|
|
|
if (!existingReaction || reaction.timestamp > existingReaction.timestamp) {
|
|
|
|
reactionBySender.set(reaction.fromId, reaction);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
const reactionsWithEmpties = reactionBySender.values();
|
|
|
|
const reactionsWithEmoji = iterables.filter(
|
|
|
|
reactionsWithEmpties,
|
|
|
|
re => re.emoji
|
|
|
|
);
|
|
|
|
const formattedReactions = iterables.map(reactionsWithEmoji, re => {
|
|
|
|
const c = conversationSelector(re.fromId);
|
2021-08-11 16:23:21 +00:00
|
|
|
|
2022-12-23 00:32:03 +00:00
|
|
|
type From = NonNullable<PropsData['reactions']>[0]['from'];
|
2021-10-28 22:39:16 +00:00
|
|
|
|
|
|
|
const {
|
|
|
|
acceptedMessageRequest,
|
|
|
|
avatarPath,
|
2021-11-15 22:53:42 +00:00
|
|
|
badges,
|
2021-10-28 22:39:16 +00:00
|
|
|
color,
|
|
|
|
id,
|
|
|
|
isMe,
|
|
|
|
name,
|
|
|
|
phoneNumber,
|
|
|
|
profileName,
|
|
|
|
sharedGroupNames,
|
|
|
|
title,
|
2022-12-23 00:32:03 +00:00
|
|
|
} = c;
|
2021-10-28 22:39:16 +00:00
|
|
|
|
|
|
|
const unsafe = {
|
|
|
|
acceptedMessageRequest,
|
|
|
|
avatarPath,
|
2021-11-15 22:53:42 +00:00
|
|
|
badges,
|
2021-10-28 22:39:16 +00:00
|
|
|
color,
|
|
|
|
id,
|
|
|
|
isMe,
|
|
|
|
name,
|
|
|
|
phoneNumber,
|
|
|
|
profileName,
|
|
|
|
sharedGroupNames,
|
|
|
|
title,
|
|
|
|
};
|
2021-08-11 16:23:21 +00:00
|
|
|
|
2022-12-23 00:32:03 +00:00
|
|
|
const from: AssertProps<From, typeof unsafe> = unsafe;
|
2021-08-11 16:23:21 +00:00
|
|
|
|
2022-12-23 00:32:03 +00:00
|
|
|
strictAssert(re.emoji, 'Expected all reactions to have an emoji');
|
2022-03-16 17:30:14 +00:00
|
|
|
|
2022-12-23 00:32:03 +00:00
|
|
|
return {
|
|
|
|
emoji: re.emoji,
|
|
|
|
timestamp: re.timestamp,
|
|
|
|
from,
|
|
|
|
};
|
|
|
|
});
|
2022-03-16 17:30:14 +00:00
|
|
|
|
2022-12-23 00:32:03 +00:00
|
|
|
return [...formattedReactions];
|
|
|
|
};
|
2022-03-16 17:30:14 +00:00
|
|
|
|
2022-12-23 00:32:03 +00:00
|
|
|
const getPropsForStoryReplyContext = (
|
|
|
|
message: Pick<
|
|
|
|
MessageWithUIFieldsType,
|
|
|
|
'body' | 'conversationId' | 'storyReaction' | 'storyReplyContext'
|
|
|
|
>,
|
|
|
|
{
|
|
|
|
conversationSelector,
|
|
|
|
ourConversationId,
|
2023-09-01 17:03:44 +00:00
|
|
|
defaultConversationColor,
|
2022-12-23 00:32:03 +00:00
|
|
|
}: {
|
|
|
|
conversationSelector: GetConversationByIdType;
|
|
|
|
ourConversationId?: string;
|
2023-09-01 17:03:44 +00:00
|
|
|
defaultConversationColor: DefaultConversationColorType;
|
2022-12-23 00:32:03 +00:00
|
|
|
}
|
|
|
|
): PropsData['storyReplyContext'] => {
|
|
|
|
const { storyReaction, storyReplyContext } = message;
|
|
|
|
if (!storyReplyContext) {
|
|
|
|
return undefined;
|
|
|
|
}
|
2022-03-16 17:30:14 +00:00
|
|
|
|
2023-08-16 20:54:39 +00:00
|
|
|
const contact = conversationSelector(storyReplyContext.authorAci);
|
2022-03-16 17:30:14 +00:00
|
|
|
|
2022-12-23 00:32:03 +00:00
|
|
|
const authorTitle = contact.firstName || contact.title;
|
|
|
|
const isFromMe = contact.id === ourConversationId;
|
2022-03-16 17:30:14 +00:00
|
|
|
|
2022-12-23 00:32:03 +00:00
|
|
|
const conversation = getConversation(message, conversationSelector);
|
2022-03-16 17:30:14 +00:00
|
|
|
|
2023-09-01 17:03:44 +00:00
|
|
|
const { conversationColor, customColor } = getConversationColorAttributes(
|
|
|
|
conversation,
|
|
|
|
defaultConversationColor
|
|
|
|
);
|
2022-03-16 17:30:14 +00:00
|
|
|
|
2022-12-23 00:32:03 +00:00
|
|
|
return {
|
|
|
|
authorTitle,
|
|
|
|
conversationColor,
|
|
|
|
customColor,
|
|
|
|
emoji: storyReaction?.emoji,
|
|
|
|
isFromMe,
|
|
|
|
rawAttachment: storyReplyContext.attachment
|
|
|
|
? processQuoteAttachment(storyReplyContext.attachment)
|
|
|
|
: undefined,
|
|
|
|
storyId: storyReplyContext.messageId,
|
|
|
|
text: getStoryReplyText(window.i18n, storyReplyContext.attachment),
|
|
|
|
};
|
|
|
|
};
|
2021-08-11 23:06:20 +00:00
|
|
|
|
2023-01-19 19:56:02 +00:00
|
|
|
export const getPropsForQuote = (
|
2023-04-20 16:31:59 +00:00
|
|
|
message: ReadonlyDeep<
|
|
|
|
Pick<MessageWithUIFieldsType, 'conversationId' | 'quote'>
|
2023-01-19 19:56:02 +00:00
|
|
|
>,
|
|
|
|
{
|
|
|
|
conversationSelector,
|
|
|
|
ourConversationId,
|
2023-09-01 17:03:44 +00:00
|
|
|
defaultConversationColor,
|
2023-01-19 19:56:02 +00:00
|
|
|
}: {
|
|
|
|
conversationSelector: GetConversationByIdType;
|
|
|
|
ourConversationId?: string;
|
2023-09-01 17:03:44 +00:00
|
|
|
defaultConversationColor: DefaultConversationColorType;
|
2023-01-19 19:56:02 +00:00
|
|
|
}
|
|
|
|
): PropsData['quote'] => {
|
|
|
|
const { quote } = message;
|
|
|
|
if (!quote) {
|
|
|
|
return undefined;
|
|
|
|
}
|
2021-08-11 23:06:20 +00:00
|
|
|
|
2023-01-19 19:56:02 +00:00
|
|
|
const {
|
|
|
|
author,
|
2023-08-16 20:54:39 +00:00
|
|
|
authorAci,
|
2023-01-19 19:56:02 +00:00
|
|
|
id: sentAt,
|
|
|
|
isViewOnce,
|
|
|
|
isGiftBadge: isTargetGiftBadge,
|
|
|
|
referencedMessageNotFound,
|
|
|
|
payment,
|
|
|
|
text = '',
|
|
|
|
} = quote;
|
|
|
|
|
2023-08-16 20:54:39 +00:00
|
|
|
const contact = conversationSelector(authorAci || author);
|
2023-01-19 19:56:02 +00:00
|
|
|
|
|
|
|
const authorId = contact.id;
|
|
|
|
const authorName = contact.name;
|
|
|
|
const authorPhoneNumber = contact.phoneNumber;
|
|
|
|
const authorProfileName = contact.profileName;
|
|
|
|
const authorTitle = contact.title;
|
|
|
|
const isFromMe = authorId === ourConversationId;
|
|
|
|
|
|
|
|
const firstAttachment = quote.attachments && quote.attachments[0];
|
|
|
|
const conversation = getConversation(message, conversationSelector);
|
2021-08-25 00:15:12 +00:00
|
|
|
|
2023-09-01 17:03:44 +00:00
|
|
|
const { conversationColor, customColor } = getConversationColorAttributes(
|
|
|
|
conversation,
|
|
|
|
defaultConversationColor
|
|
|
|
);
|
2023-01-19 19:56:02 +00:00
|
|
|
|
|
|
|
return {
|
|
|
|
authorId,
|
|
|
|
authorName,
|
|
|
|
authorPhoneNumber,
|
|
|
|
authorProfileName,
|
|
|
|
authorTitle,
|
|
|
|
bodyRanges: processBodyRanges(quote, { conversationSelector }),
|
|
|
|
conversationColor,
|
|
|
|
conversationTitle: conversation.title,
|
|
|
|
customColor,
|
|
|
|
isFromMe,
|
|
|
|
rawAttachment: firstAttachment
|
|
|
|
? processQuoteAttachment(firstAttachment)
|
|
|
|
: undefined,
|
|
|
|
payment,
|
|
|
|
isGiftBadge: Boolean(isTargetGiftBadge),
|
|
|
|
isViewOnce,
|
|
|
|
referencedMessageNotFound,
|
|
|
|
sentAt: Number(sentAt),
|
|
|
|
text,
|
|
|
|
};
|
|
|
|
};
|
2021-08-11 23:06:20 +00:00
|
|
|
|
2021-08-11 16:23:21 +00:00
|
|
|
export type GetPropsForMessageOptions = Pick<
|
|
|
|
GetPropsForBubbleOptions,
|
|
|
|
| 'conversationSelector'
|
|
|
|
| 'ourConversationId'
|
2023-08-10 16:43:33 +00:00
|
|
|
| 'ourAci'
|
|
|
|
| 'ourPni'
|
2021-08-19 20:14:41 +00:00
|
|
|
| 'ourNumber'
|
2023-03-20 22:23:53 +00:00
|
|
|
| 'targetedMessageId'
|
|
|
|
| 'targetedMessageCounter'
|
|
|
|
| 'selectedMessageIds'
|
2021-08-11 16:23:21 +00:00
|
|
|
| 'regionCode'
|
|
|
|
| 'accountSelector'
|
2021-08-19 20:14:41 +00:00
|
|
|
| 'contactNameColorSelector'
|
2023-09-01 17:03:44 +00:00
|
|
|
| 'defaultConversationColor'
|
2021-08-11 16:23:21 +00:00
|
|
|
>;
|
|
|
|
|
2022-12-23 00:32:03 +00:00
|
|
|
function getTextAttachment(
|
|
|
|
message: MessageWithUIFieldsType
|
|
|
|
): AttachmentType | undefined {
|
|
|
|
return (
|
|
|
|
message.bodyAttachment && getPropsForAttachment(message.bodyAttachment)
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
|
|
|
function getPayment(
|
|
|
|
message: MessageWithUIFieldsType
|
|
|
|
): AnyPaymentEvent | undefined {
|
|
|
|
return message.payment;
|
|
|
|
}
|
|
|
|
|
|
|
|
export function cleanBodyForDirectionCheck(text: string): string {
|
|
|
|
const MENTIONS_REGEX = getMentionsRegex();
|
|
|
|
const EMOJI_REGEX = emojiRegex();
|
|
|
|
const initial = text.replace(MENTIONS_REGEX, '').replace(EMOJI_REGEX, '');
|
|
|
|
|
|
|
|
const linkMatches = linkify.match(initial);
|
|
|
|
|
|
|
|
if (!linkMatches || linkMatches.length === 0) {
|
|
|
|
return initial;
|
|
|
|
}
|
|
|
|
|
|
|
|
let result = '';
|
|
|
|
let lastIndex = 0;
|
|
|
|
|
|
|
|
linkMatches.forEach(match => {
|
|
|
|
if (lastIndex < match.index) {
|
|
|
|
result += initial.slice(lastIndex, match.index);
|
|
|
|
}
|
|
|
|
|
|
|
|
// drop the actual contents of the match
|
2021-08-11 23:06:20 +00:00
|
|
|
|
2022-12-23 00:32:03 +00:00
|
|
|
lastIndex = match.lastIndex;
|
|
|
|
});
|
|
|
|
|
|
|
|
if (lastIndex < initial.length) {
|
|
|
|
result += initial.slice(lastIndex);
|
|
|
|
}
|
|
|
|
|
|
|
|
return result;
|
|
|
|
}
|
|
|
|
|
|
|
|
function getTextDirection(body?: string): TextDirection {
|
|
|
|
if (!body) {
|
|
|
|
return TextDirection.None;
|
|
|
|
}
|
|
|
|
|
|
|
|
const cleaned = cleanBodyForDirectionCheck(body);
|
|
|
|
const direction = getDirection(cleaned);
|
|
|
|
switch (direction) {
|
|
|
|
case 'ltr':
|
|
|
|
return TextDirection.LeftToRight;
|
|
|
|
case 'rtl':
|
|
|
|
return TextDirection.RightToLeft;
|
|
|
|
case 'neutral':
|
|
|
|
return TextDirection.Default;
|
|
|
|
default: {
|
|
|
|
const unexpected: never = direction;
|
|
|
|
log.warn(`getTextDirection: unexpected direction ${unexpected}`);
|
|
|
|
return TextDirection.None;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2021-08-11 23:06:20 +00:00
|
|
|
|
2023-01-19 19:56:02 +00:00
|
|
|
export const getPropsForMessage = (
|
|
|
|
message: MessageWithUIFieldsType,
|
|
|
|
options: GetPropsForMessageOptions
|
|
|
|
): Omit<PropsForMessage, 'renderingContext' | 'menu' | 'contextMenu'> => {
|
2023-10-30 16:24:28 +00:00
|
|
|
const attachmentDroppedDueToSize = message.attachments?.some(
|
|
|
|
item => item.wasTooBig
|
|
|
|
);
|
2023-01-19 19:56:02 +00:00
|
|
|
const attachments = getAttachmentsForMessage(message);
|
|
|
|
const bodyRanges = processBodyRanges(message, options);
|
|
|
|
const author = getAuthorForMessage(message, options);
|
|
|
|
const previews = getPreviewsForMessage(message);
|
|
|
|
const reactions = getReactionsForMessage(message, options);
|
|
|
|
const quote = getPropsForQuote(message, options);
|
|
|
|
const storyReplyContext = getPropsForStoryReplyContext(message, options);
|
|
|
|
const textAttachment = getTextAttachment(message);
|
|
|
|
const payment = getPayment(message);
|
2022-12-23 00:32:03 +00:00
|
|
|
|
2023-01-19 19:56:02 +00:00
|
|
|
const {
|
|
|
|
accountSelector,
|
|
|
|
conversationSelector,
|
|
|
|
ourConversationId,
|
|
|
|
ourNumber,
|
2023-08-10 16:43:33 +00:00
|
|
|
ourAci,
|
2023-01-19 19:56:02 +00:00
|
|
|
regionCode,
|
2023-03-20 22:23:53 +00:00
|
|
|
targetedMessageId,
|
|
|
|
targetedMessageCounter,
|
|
|
|
selectedMessageIds,
|
2023-01-19 19:56:02 +00:00
|
|
|
contactNameColorSelector,
|
2023-09-01 17:03:44 +00:00
|
|
|
defaultConversationColor,
|
2023-01-19 19:56:02 +00:00
|
|
|
} = options;
|
2022-12-23 00:32:03 +00:00
|
|
|
|
2023-01-19 19:56:02 +00:00
|
|
|
const { expireTimer, expirationStartTimestamp, conversationId } = message;
|
|
|
|
const expirationLength = expireTimer
|
|
|
|
? DurationInSeconds.toMillis(expireTimer)
|
|
|
|
: undefined;
|
2021-06-17 17:15:10 +00:00
|
|
|
|
2023-01-19 19:56:02 +00:00
|
|
|
const conversation = getConversation(message, conversationSelector);
|
|
|
|
const isGroup = conversation.type === 'group';
|
|
|
|
const { sticker } = message;
|
2021-06-17 17:15:10 +00:00
|
|
|
|
2023-01-19 19:56:02 +00:00
|
|
|
const isMessageTapToView = isTapToView(message);
|
2021-06-17 17:15:10 +00:00
|
|
|
|
2023-03-20 22:23:53 +00:00
|
|
|
const isTargeted = message.id === targetedMessageId;
|
|
|
|
const isSelected = selectedMessageIds?.includes(message.id) ?? false;
|
|
|
|
const isSelectMode = selectedMessageIds != null;
|
2021-08-11 23:06:20 +00:00
|
|
|
|
2023-01-19 19:56:02 +00:00
|
|
|
const selectedReaction = (
|
|
|
|
(message.reactions || []).find(re => re.fromId === ourConversationId) || {}
|
|
|
|
).emoji;
|
2021-06-17 17:15:10 +00:00
|
|
|
|
2023-01-19 19:56:02 +00:00
|
|
|
const authorId = getContactId(message, {
|
|
|
|
conversationSelector,
|
|
|
|
ourConversationId,
|
|
|
|
ourNumber,
|
2023-08-10 16:43:33 +00:00
|
|
|
ourAci,
|
2023-01-19 19:56:02 +00:00
|
|
|
});
|
|
|
|
const contactNameColor = contactNameColorSelector(conversationId, authorId);
|
2021-08-19 20:14:41 +00:00
|
|
|
|
2023-09-01 17:03:44 +00:00
|
|
|
const { conversationColor, customColor } = getConversationColorAttributes(
|
|
|
|
conversation,
|
|
|
|
defaultConversationColor
|
|
|
|
);
|
2021-08-25 00:15:12 +00:00
|
|
|
|
2023-01-19 19:56:02 +00:00
|
|
|
return {
|
|
|
|
attachments,
|
2023-10-30 16:24:28 +00:00
|
|
|
attachmentDroppedDueToSize,
|
2023-01-19 19:56:02 +00:00
|
|
|
author,
|
|
|
|
bodyRanges,
|
|
|
|
previews,
|
|
|
|
quote,
|
|
|
|
reactions,
|
|
|
|
storyReplyContext,
|
|
|
|
textAttachment,
|
|
|
|
payment,
|
2023-04-22 01:52:25 +00:00
|
|
|
canCopy: canCopy(message),
|
2023-04-20 16:31:59 +00:00
|
|
|
canEditMessage: canEditMessage(message),
|
2024-01-03 16:46:39 +00:00
|
|
|
canDeleteForEveryone: canDeleteForEveryone(message, conversation.isMe),
|
2023-01-19 19:56:02 +00:00
|
|
|
canDownload: canDownload(message, conversationSelector),
|
|
|
|
canReact: canReact(message, ourConversationId, conversationSelector),
|
|
|
|
canReply: canReply(message, ourConversationId, conversationSelector),
|
|
|
|
canRetry: hasErrors(message),
|
|
|
|
canRetryDeleteForEveryone: canRetryDeleteForEveryone(message),
|
|
|
|
contact: getPropsForEmbeddedContact(message, regionCode, accountSelector),
|
|
|
|
contactNameColor,
|
|
|
|
conversationColor,
|
|
|
|
conversationId,
|
|
|
|
conversationTitle: conversation.title,
|
|
|
|
conversationType: isGroup ? 'group' : 'direct',
|
|
|
|
customColor,
|
|
|
|
deletedForEveryone: message.deletedForEveryone || false,
|
|
|
|
direction: isIncoming(message) ? 'incoming' : 'outgoing',
|
|
|
|
displayLimit: message.displayLimit,
|
|
|
|
expirationLength,
|
|
|
|
expirationTimestamp: calculateExpirationTimestamp({
|
|
|
|
expireTimer,
|
|
|
|
expirationStartTimestamp,
|
|
|
|
}),
|
|
|
|
giftBadge: message.giftBadge,
|
|
|
|
id: message.id,
|
|
|
|
isBlocked: conversation.isBlocked || false,
|
2023-03-27 23:48:57 +00:00
|
|
|
isEditedMessage: Boolean(message.editHistory),
|
2023-01-19 19:56:02 +00:00
|
|
|
isMessageRequestAccepted: conversation?.acceptedMessageRequest ?? true,
|
|
|
|
isSelected,
|
2023-03-20 22:23:53 +00:00
|
|
|
isSelectMode,
|
2023-04-10 16:31:45 +00:00
|
|
|
isSpoilerExpanded: message.isSpoilerExpanded,
|
2023-01-19 19:56:02 +00:00
|
|
|
isSticker: Boolean(sticker),
|
2023-04-10 16:31:45 +00:00
|
|
|
isTargeted,
|
|
|
|
isTargetedCounter: isTargeted ? targetedMessageCounter : undefined,
|
2023-01-19 19:56:02 +00:00
|
|
|
isTapToView: isMessageTapToView,
|
|
|
|
isTapToViewError:
|
|
|
|
isMessageTapToView && isIncoming(message) && message.isTapToViewInvalid,
|
|
|
|
isTapToViewExpired: isMessageTapToView && message.isErased,
|
|
|
|
readStatus: message.readStatus ?? ReadStatus.Read,
|
|
|
|
selectedReaction,
|
|
|
|
status: getMessagePropStatus(message, ourConversationId),
|
|
|
|
text: message.body,
|
|
|
|
textDirection: getTextDirection(message.body),
|
2023-06-21 17:08:36 +00:00
|
|
|
timestamp: getMessageSentTimestamp(message, { includeEdits: true, log }),
|
2023-11-04 00:55:12 +00:00
|
|
|
receivedAtMS: message.received_at_ms,
|
2023-01-19 19:56:02 +00:00
|
|
|
};
|
|
|
|
};
|
2021-06-17 17:15:10 +00:00
|
|
|
|
2022-07-01 00:52:03 +00:00
|
|
|
// This is getPropsForMessage but wrapped in reselect's createSelector so that
|
|
|
|
// we can derive all of the selector dependencies that getPropsForMessage
|
|
|
|
// requires and you won't have to pass them in. For use within a smart/connected
|
|
|
|
// component that has access to selectors.
|
|
|
|
export const getMessagePropsSelector = createSelector(
|
|
|
|
getConversationSelector,
|
|
|
|
getUserConversationId,
|
2022-07-08 20:46:25 +00:00
|
|
|
getUserACI,
|
|
|
|
getUserPNI,
|
2022-07-01 00:52:03 +00:00
|
|
|
getUserNumber,
|
|
|
|
getRegionCode,
|
|
|
|
getAccountSelector,
|
|
|
|
getContactNameColorSelector,
|
2023-03-20 22:23:53 +00:00
|
|
|
getTargetedMessage,
|
|
|
|
getSelectedMessageIds,
|
2023-09-01 17:03:44 +00:00
|
|
|
getDefaultConversationColor,
|
2022-07-01 00:52:03 +00:00
|
|
|
(
|
|
|
|
conversationSelector,
|
|
|
|
ourConversationId,
|
2023-08-10 16:43:33 +00:00
|
|
|
ourAci,
|
|
|
|
ourPni,
|
2022-07-01 00:52:03 +00:00
|
|
|
ourNumber,
|
|
|
|
regionCode,
|
|
|
|
accountSelector,
|
|
|
|
contactNameColorSelector,
|
2023-03-20 22:23:53 +00:00
|
|
|
targetedMessage,
|
2023-09-01 17:03:44 +00:00
|
|
|
selectedMessageIds,
|
|
|
|
defaultConversationColor
|
2022-07-01 00:52:03 +00:00
|
|
|
) =>
|
|
|
|
(message: MessageWithUIFieldsType) => {
|
|
|
|
return getPropsForMessage(message, {
|
|
|
|
accountSelector,
|
|
|
|
contactNameColorSelector,
|
|
|
|
conversationSelector,
|
|
|
|
ourConversationId,
|
|
|
|
ourNumber,
|
2023-08-10 16:43:33 +00:00
|
|
|
ourAci,
|
|
|
|
ourPni,
|
2022-07-01 00:52:03 +00:00
|
|
|
regionCode,
|
2023-03-20 22:23:53 +00:00
|
|
|
targetedMessageCounter: targetedMessage?.counter,
|
|
|
|
targetedMessageId: targetedMessage?.id,
|
|
|
|
selectedMessageIds,
|
2023-09-01 17:03:44 +00:00
|
|
|
defaultConversationColor,
|
2022-07-01 00:52:03 +00:00
|
|
|
});
|
|
|
|
}
|
|
|
|
);
|
|
|
|
|
2021-08-11 23:06:20 +00:00
|
|
|
// Top-level prop generation for the message bubble
|
|
|
|
export function getPropsForBubble(
|
2021-11-11 23:45:47 +00:00
|
|
|
message: MessageWithUIFieldsType,
|
2021-08-11 23:06:20 +00:00
|
|
|
options: GetPropsForBubbleOptions
|
|
|
|
): TimelineItemType {
|
2022-01-26 23:05:26 +00:00
|
|
|
const { received_at_ms: receivedAt, timestamp: messageTimestamp } = message;
|
|
|
|
const timestamp = receivedAt || messageTimestamp;
|
|
|
|
|
2021-08-11 23:06:20 +00:00
|
|
|
if (isUnsupportedMessage(message)) {
|
|
|
|
return {
|
|
|
|
type: 'unsupportedMessage',
|
|
|
|
data: getPropsForUnsupportedMessage(message, options),
|
2022-01-26 23:05:26 +00:00
|
|
|
timestamp,
|
2021-08-11 23:06:20 +00:00
|
|
|
};
|
|
|
|
}
|
|
|
|
if (isGroupV2Change(message)) {
|
|
|
|
return {
|
|
|
|
type: 'groupV2Change',
|
|
|
|
data: getPropsForGroupV2Change(message, options),
|
2022-01-26 23:05:26 +00:00
|
|
|
timestamp,
|
2021-08-11 23:06:20 +00:00
|
|
|
};
|
|
|
|
}
|
|
|
|
if (isGroupV1Migration(message)) {
|
|
|
|
return {
|
|
|
|
type: 'groupV1Migration',
|
|
|
|
data: getPropsForGroupV1Migration(message, options),
|
2022-01-26 23:05:26 +00:00
|
|
|
timestamp,
|
2021-08-11 23:06:20 +00:00
|
|
|
};
|
|
|
|
}
|
|
|
|
if (isExpirationTimerUpdate(message)) {
|
|
|
|
return {
|
|
|
|
type: 'timerNotification',
|
|
|
|
data: getPropsForTimerNotification(message, options),
|
2022-01-26 23:05:26 +00:00
|
|
|
timestamp,
|
2021-08-11 23:06:20 +00:00
|
|
|
};
|
|
|
|
}
|
|
|
|
if (isKeyChange(message)) {
|
|
|
|
return {
|
|
|
|
type: 'safetyNumberNotification',
|
|
|
|
data: getPropsForSafetyNumberNotification(message, options),
|
2022-01-26 23:05:26 +00:00
|
|
|
timestamp,
|
2021-08-11 23:06:20 +00:00
|
|
|
};
|
|
|
|
}
|
|
|
|
if (isVerifiedChange(message)) {
|
|
|
|
return {
|
|
|
|
type: 'verificationNotification',
|
|
|
|
data: getPropsForVerificationNotification(message, options),
|
2022-01-26 23:05:26 +00:00
|
|
|
timestamp,
|
2021-08-11 23:06:20 +00:00
|
|
|
};
|
|
|
|
}
|
|
|
|
if (isGroupUpdate(message)) {
|
|
|
|
return {
|
|
|
|
type: 'groupNotification',
|
|
|
|
data: getPropsForGroupNotification(message, options),
|
2022-01-26 23:05:26 +00:00
|
|
|
timestamp,
|
2021-08-11 23:06:20 +00:00
|
|
|
};
|
|
|
|
}
|
|
|
|
if (isEndSession(message)) {
|
|
|
|
return {
|
|
|
|
type: 'resetSessionNotification',
|
|
|
|
data: null,
|
2022-01-26 23:05:26 +00:00
|
|
|
timestamp,
|
2021-08-11 23:06:20 +00:00
|
|
|
};
|
|
|
|
}
|
|
|
|
if (isCallHistory(message)) {
|
|
|
|
return {
|
|
|
|
type: 'callHistory',
|
|
|
|
data: getPropsForCallHistory(message, options),
|
2022-01-26 23:05:26 +00:00
|
|
|
timestamp,
|
2021-08-11 23:06:20 +00:00
|
|
|
};
|
|
|
|
}
|
|
|
|
if (isProfileChange(message)) {
|
|
|
|
return {
|
|
|
|
type: 'profileChange',
|
|
|
|
data: getPropsForProfileChange(message, options),
|
2022-01-26 23:05:26 +00:00
|
|
|
timestamp,
|
2021-08-11 23:06:20 +00:00
|
|
|
};
|
|
|
|
}
|
|
|
|
if (isUniversalTimerNotification(message)) {
|
|
|
|
return {
|
|
|
|
type: 'universalTimerNotification',
|
|
|
|
data: null,
|
2022-01-26 23:05:26 +00:00
|
|
|
timestamp,
|
2021-08-11 23:06:20 +00:00
|
|
|
};
|
|
|
|
}
|
2023-04-05 20:48:00 +00:00
|
|
|
if (isContactRemovedNotification(message)) {
|
|
|
|
return {
|
|
|
|
type: 'contactRemovedNotification',
|
|
|
|
data: null,
|
|
|
|
timestamp,
|
|
|
|
};
|
|
|
|
}
|
2021-08-11 23:06:20 +00:00
|
|
|
if (isChangeNumberNotification(message)) {
|
|
|
|
return {
|
|
|
|
type: 'changeNumberNotification',
|
|
|
|
data: getPropsForChangeNumberNotification(message, options),
|
2022-01-26 23:05:26 +00:00
|
|
|
timestamp,
|
2021-08-11 23:06:20 +00:00
|
|
|
};
|
|
|
|
}
|
|
|
|
if (isChatSessionRefreshed(message)) {
|
|
|
|
return {
|
|
|
|
type: 'chatSessionRefreshed',
|
|
|
|
data: null,
|
2022-01-26 23:05:26 +00:00
|
|
|
timestamp,
|
2021-08-11 23:06:20 +00:00
|
|
|
};
|
|
|
|
}
|
|
|
|
if (isDeliveryIssue(message)) {
|
|
|
|
return {
|
|
|
|
type: 'deliveryIssue',
|
|
|
|
data: getPropsForDeliveryIssue(message, options),
|
2022-01-26 23:05:26 +00:00
|
|
|
timestamp,
|
2021-08-11 23:06:20 +00:00
|
|
|
};
|
|
|
|
}
|
2022-12-05 22:46:54 +00:00
|
|
|
if (isConversationMerge(message)) {
|
|
|
|
return {
|
|
|
|
type: 'conversationMerge',
|
|
|
|
data: getPropsForConversationMerge(message, options),
|
|
|
|
timestamp,
|
|
|
|
};
|
|
|
|
}
|
2023-10-23 17:40:42 +00:00
|
|
|
if (isPhoneNumberDiscovery(message)) {
|
|
|
|
return {
|
|
|
|
type: 'phoneNumberDiscovery',
|
|
|
|
data: getPropsForPhoneNumberDiscovery(message, options),
|
|
|
|
timestamp,
|
|
|
|
};
|
|
|
|
}
|
2021-08-11 23:06:20 +00:00
|
|
|
|
2022-11-30 21:47:54 +00:00
|
|
|
if (
|
|
|
|
messageHasPaymentEvent(message) &&
|
|
|
|
!isPaymentNotificationEvent(message.payment)
|
|
|
|
) {
|
|
|
|
return {
|
|
|
|
type: 'paymentEvent',
|
|
|
|
data: getPropsForPaymentEvent(message, options),
|
|
|
|
timestamp,
|
|
|
|
};
|
|
|
|
}
|
|
|
|
|
2022-12-23 00:32:03 +00:00
|
|
|
const data = getPropsForMessage(message, options);
|
|
|
|
|
|
|
|
return {
|
|
|
|
type: 'message' as const,
|
|
|
|
data,
|
|
|
|
timestamp: data.timestamp,
|
|
|
|
};
|
2021-08-11 23:06:20 +00:00
|
|
|
}
|
|
|
|
|
2022-11-30 21:47:54 +00:00
|
|
|
function getPropsForPaymentEvent(
|
|
|
|
message: MessageAttributesWithPaymentEvent,
|
|
|
|
{ conversationSelector }: GetPropsForBubbleOptions
|
|
|
|
): Omit<PaymentEventNotificationPropsType, 'i18n'> {
|
|
|
|
return {
|
2023-08-16 20:54:39 +00:00
|
|
|
sender: conversationSelector(message.sourceServiceId),
|
2022-12-23 00:32:03 +00:00
|
|
|
conversation: getConversation(message, conversationSelector),
|
2022-11-30 21:47:54 +00:00
|
|
|
event: message.payment,
|
|
|
|
};
|
|
|
|
}
|
|
|
|
|
2021-06-17 17:15:10 +00:00
|
|
|
// Unsupported Message
|
|
|
|
|
2021-11-11 23:45:47 +00:00
|
|
|
export function isUnsupportedMessage(
|
|
|
|
message: MessageWithUIFieldsType
|
|
|
|
): boolean {
|
2021-06-17 17:15:10 +00:00
|
|
|
const versionAtReceive = message.supportedVersionAtReceive;
|
|
|
|
const requiredVersion = message.requiredProtocolVersion;
|
|
|
|
|
|
|
|
return (
|
|
|
|
isNumber(versionAtReceive) &&
|
|
|
|
isNumber(requiredVersion) &&
|
|
|
|
versionAtReceive < requiredVersion
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
|
|
|
function getPropsForUnsupportedMessage(
|
2021-11-11 23:45:47 +00:00
|
|
|
message: MessageWithUIFieldsType,
|
2021-08-11 16:23:21 +00:00
|
|
|
options: GetContactOptions
|
2021-06-17 17:15:10 +00:00
|
|
|
): PropsForUnsupportedMessage {
|
2021-07-09 19:36:10 +00:00
|
|
|
const CURRENT_PROTOCOL_VERSION = Proto.DataMessage.ProtocolVersion.CURRENT;
|
2021-06-17 17:15:10 +00:00
|
|
|
|
|
|
|
const requiredVersion = message.requiredProtocolVersion;
|
|
|
|
const canProcessNow = Boolean(
|
|
|
|
CURRENT_PROTOCOL_VERSION &&
|
|
|
|
requiredVersion &&
|
|
|
|
CURRENT_PROTOCOL_VERSION >= requiredVersion
|
|
|
|
);
|
|
|
|
|
|
|
|
return {
|
|
|
|
canProcessNow,
|
2021-08-11 16:23:21 +00:00
|
|
|
contact: getContact(message, options),
|
2021-06-17 17:15:10 +00:00
|
|
|
};
|
|
|
|
}
|
|
|
|
|
|
|
|
// GroupV2 Change
|
|
|
|
|
2021-11-11 23:45:47 +00:00
|
|
|
export function isGroupV2Change(message: MessageWithUIFieldsType): boolean {
|
2021-06-17 17:15:10 +00:00
|
|
|
return Boolean(message.groupV2Change);
|
|
|
|
}
|
|
|
|
|
|
|
|
function getPropsForGroupV2Change(
|
2021-11-11 23:45:47 +00:00
|
|
|
message: MessageWithUIFieldsType,
|
2023-08-10 16:43:33 +00:00
|
|
|
{ conversationSelector, ourAci, ourPni }: GetPropsForBubbleOptions
|
2021-06-17 17:15:10 +00:00
|
|
|
): GroupsV2Props {
|
|
|
|
const change = message.groupV2Change;
|
|
|
|
|
|
|
|
if (!change) {
|
|
|
|
throw new Error('getPropsForGroupV2Change: Change is missing!');
|
|
|
|
}
|
|
|
|
|
|
|
|
const conversation = getConversation(message, conversationSelector);
|
|
|
|
|
|
|
|
return {
|
2022-03-16 00:11:28 +00:00
|
|
|
areWeAdmin: Boolean(conversation.areWeAdmin),
|
2022-12-21 03:25:10 +00:00
|
|
|
conversationId: conversation.id,
|
2021-06-17 17:15:10 +00:00
|
|
|
groupName: conversation?.type === 'group' ? conversation?.name : undefined,
|
2022-03-16 00:11:28 +00:00
|
|
|
groupMemberships: conversation.memberships,
|
|
|
|
groupBannedMemberships: conversation.bannedMemberships,
|
2023-08-10 16:43:33 +00:00
|
|
|
ourAci,
|
|
|
|
ourPni,
|
2021-06-17 17:15:10 +00:00
|
|
|
change,
|
|
|
|
};
|
|
|
|
}
|
|
|
|
|
|
|
|
// GroupV1 Migration
|
|
|
|
|
2021-11-11 23:45:47 +00:00
|
|
|
export function isGroupV1Migration(message: MessageWithUIFieldsType): boolean {
|
2021-06-17 17:15:10 +00:00
|
|
|
return message.type === 'group-v1-migration';
|
|
|
|
}
|
|
|
|
|
|
|
|
function getPropsForGroupV1Migration(
|
2021-11-11 23:45:47 +00:00
|
|
|
message: MessageWithUIFieldsType,
|
2021-08-11 16:23:21 +00:00
|
|
|
{ conversationSelector }: GetPropsForBubbleOptions
|
2021-06-17 17:15:10 +00:00
|
|
|
): GroupV1MigrationPropsType {
|
|
|
|
const migration = message.groupMigration;
|
|
|
|
if (!migration) {
|
|
|
|
// Backwards-compatibility with data schema in early betas
|
|
|
|
const invitedGV2Members = message.invitedGV2Members || [];
|
|
|
|
const droppedGV2MemberIds = message.droppedGV2MemberIds || [];
|
|
|
|
|
|
|
|
const invitedMembers = invitedGV2Members.map(item =>
|
2021-10-26 22:59:08 +00:00
|
|
|
conversationSelector(item.uuid)
|
2021-06-17 17:15:10 +00:00
|
|
|
);
|
|
|
|
const droppedMembers = droppedGV2MemberIds.map(conversationId =>
|
|
|
|
conversationSelector(conversationId)
|
|
|
|
);
|
|
|
|
|
|
|
|
return {
|
|
|
|
areWeInvited: false,
|
2022-12-08 06:41:37 +00:00
|
|
|
conversationId: message.conversationId,
|
2021-06-17 17:15:10 +00:00
|
|
|
droppedMembers,
|
|
|
|
invitedMembers,
|
|
|
|
};
|
|
|
|
}
|
|
|
|
|
|
|
|
const {
|
|
|
|
areWeInvited,
|
|
|
|
droppedMemberIds,
|
|
|
|
invitedMembers: rawInvitedMembers,
|
|
|
|
} = migration;
|
|
|
|
const invitedMembers = rawInvitedMembers.map(item =>
|
2021-10-26 22:59:08 +00:00
|
|
|
conversationSelector(item.uuid)
|
2021-06-17 17:15:10 +00:00
|
|
|
);
|
|
|
|
const droppedMembers = droppedMemberIds.map(conversationId =>
|
|
|
|
conversationSelector(conversationId)
|
|
|
|
);
|
|
|
|
|
|
|
|
return {
|
|
|
|
areWeInvited,
|
2022-12-08 06:41:37 +00:00
|
|
|
conversationId: message.conversationId,
|
2021-06-17 17:15:10 +00:00
|
|
|
droppedMembers,
|
|
|
|
invitedMembers,
|
|
|
|
};
|
|
|
|
}
|
|
|
|
|
|
|
|
// Note: props are null!
|
|
|
|
|
|
|
|
// Expiration Timer Update
|
|
|
|
|
|
|
|
export function isExpirationTimerUpdate(
|
2021-11-11 23:45:47 +00:00
|
|
|
message: Pick<MessageWithUIFieldsType, 'flags'>
|
2021-06-17 17:15:10 +00:00
|
|
|
): boolean {
|
2021-07-09 19:36:10 +00:00
|
|
|
const flag = Proto.DataMessage.Flags.EXPIRATION_TIMER_UPDATE;
|
2021-06-17 17:15:10 +00:00
|
|
|
// eslint-disable-next-line no-bitwise
|
|
|
|
return Boolean(message.flags && message.flags & flag);
|
|
|
|
}
|
|
|
|
|
|
|
|
function getPropsForTimerNotification(
|
2021-11-11 23:45:47 +00:00
|
|
|
message: MessageWithUIFieldsType,
|
2021-08-11 16:23:21 +00:00
|
|
|
{ ourConversationId, conversationSelector }: GetPropsForBubbleOptions
|
2021-06-17 17:15:10 +00:00
|
|
|
): TimerNotificationProps {
|
|
|
|
const timerUpdate = message.expirationTimerUpdate;
|
|
|
|
if (!timerUpdate) {
|
|
|
|
throw new Error(
|
|
|
|
'getPropsForTimerNotification: missing expirationTimerUpdate!'
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
2023-08-16 20:54:39 +00:00
|
|
|
const { expireTimer, fromSync, source, sourceServiceId } = timerUpdate;
|
2021-06-17 17:15:10 +00:00
|
|
|
const disabled = !expireTimer;
|
2023-08-16 20:54:39 +00:00
|
|
|
const sourceId = sourceServiceId || source;
|
2023-01-19 19:56:02 +00:00
|
|
|
const { id: formattedContactId, title } = conversationSelector(sourceId);
|
2021-06-17 17:15:10 +00:00
|
|
|
|
2022-11-16 20:18:02 +00:00
|
|
|
// Pacify typescript
|
|
|
|
type MaybeExpireTimerType =
|
|
|
|
| { disabled: true }
|
|
|
|
| {
|
|
|
|
disabled: false;
|
|
|
|
expireTimer: DurationInSeconds;
|
|
|
|
};
|
|
|
|
|
|
|
|
const maybeExpireTimer: MaybeExpireTimerType = disabled
|
|
|
|
? {
|
|
|
|
disabled: true,
|
|
|
|
}
|
|
|
|
: {
|
|
|
|
disabled: false,
|
|
|
|
expireTimer,
|
|
|
|
};
|
|
|
|
|
2021-06-17 17:15:10 +00:00
|
|
|
const basicProps = {
|
2023-01-19 19:56:02 +00:00
|
|
|
title,
|
2022-11-16 20:18:02 +00:00
|
|
|
...maybeExpireTimer,
|
2021-06-17 17:15:10 +00:00
|
|
|
type: 'fromOther' as const,
|
|
|
|
};
|
|
|
|
|
|
|
|
if (fromSync) {
|
|
|
|
return {
|
|
|
|
...basicProps,
|
|
|
|
type: 'fromSync' as const,
|
|
|
|
};
|
|
|
|
}
|
2023-01-19 19:56:02 +00:00
|
|
|
if (formattedContactId === ourConversationId) {
|
2021-06-17 17:15:10 +00:00
|
|
|
return {
|
|
|
|
...basicProps,
|
|
|
|
type: 'fromMe' as const,
|
|
|
|
};
|
|
|
|
}
|
|
|
|
if (!sourceId) {
|
|
|
|
return {
|
|
|
|
...basicProps,
|
|
|
|
type: 'fromMember' as const,
|
|
|
|
};
|
|
|
|
}
|
|
|
|
|
|
|
|
return basicProps;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Key Change
|
|
|
|
|
2021-11-11 23:45:47 +00:00
|
|
|
export function isKeyChange(message: MessageWithUIFieldsType): boolean {
|
2021-06-17 17:15:10 +00:00
|
|
|
return message.type === 'keychange';
|
|
|
|
}
|
|
|
|
|
|
|
|
function getPropsForSafetyNumberNotification(
|
2021-11-11 23:45:47 +00:00
|
|
|
message: MessageWithUIFieldsType,
|
2021-08-11 16:23:21 +00:00
|
|
|
{ conversationSelector }: GetPropsForBubbleOptions
|
2021-06-17 17:15:10 +00:00
|
|
|
): SafetyNumberNotificationProps {
|
|
|
|
const conversation = getConversation(message, conversationSelector);
|
|
|
|
const isGroup = conversation?.type === 'group';
|
|
|
|
const identifier = message.key_changed;
|
2022-12-05 22:46:54 +00:00
|
|
|
|
|
|
|
if (isGroup && !identifier) {
|
|
|
|
throw new Error(
|
|
|
|
'getPropsForSafetyNumberNotification: isGroup = true, but no identifier!'
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
|
|
|
const contact = identifier ? conversationSelector(identifier) : conversation;
|
2021-06-17 17:15:10 +00:00
|
|
|
|
|
|
|
return {
|
|
|
|
isGroup,
|
|
|
|
contact,
|
|
|
|
};
|
|
|
|
}
|
|
|
|
|
|
|
|
// Verified Change
|
|
|
|
|
2021-11-11 23:45:47 +00:00
|
|
|
export function isVerifiedChange(message: MessageWithUIFieldsType): boolean {
|
2021-06-17 17:15:10 +00:00
|
|
|
return message.type === 'verified-change';
|
|
|
|
}
|
|
|
|
|
|
|
|
function getPropsForVerificationNotification(
|
2021-11-11 23:45:47 +00:00
|
|
|
message: MessageWithUIFieldsType,
|
2021-08-11 16:23:21 +00:00
|
|
|
{ conversationSelector }: GetPropsForBubbleOptions
|
2021-06-17 17:15:10 +00:00
|
|
|
): VerificationNotificationProps {
|
|
|
|
const type = message.verified ? 'markVerified' : 'markNotVerified';
|
|
|
|
const isLocal = message.local || false;
|
|
|
|
const identifier = message.verifiedChanged;
|
|
|
|
|
|
|
|
return {
|
|
|
|
type,
|
|
|
|
isLocal,
|
|
|
|
contact: conversationSelector(identifier),
|
|
|
|
};
|
|
|
|
}
|
|
|
|
|
2022-05-11 20:59:58 +00:00
|
|
|
// Gift Badge
|
|
|
|
|
|
|
|
export function isGiftBadge(
|
|
|
|
message: Pick<MessageWithUIFieldsType, 'giftBadge'>
|
|
|
|
): boolean {
|
|
|
|
return Boolean(message.giftBadge);
|
|
|
|
}
|
|
|
|
|
2021-06-17 17:15:10 +00:00
|
|
|
// Group Update (V1)
|
|
|
|
|
2021-06-30 00:51:57 +00:00
|
|
|
export function isGroupUpdate(
|
2021-11-11 23:45:47 +00:00
|
|
|
message: Pick<MessageWithUIFieldsType, 'group_update'>
|
2021-06-30 00:51:57 +00:00
|
|
|
): boolean {
|
2021-06-17 17:15:10 +00:00
|
|
|
return Boolean(message.group_update);
|
|
|
|
}
|
|
|
|
|
|
|
|
function getPropsForGroupNotification(
|
2021-11-11 23:45:47 +00:00
|
|
|
message: MessageWithUIFieldsType,
|
2021-08-11 16:23:21 +00:00
|
|
|
options: GetContactOptions
|
2021-06-17 17:15:10 +00:00
|
|
|
): GroupNotificationProps {
|
|
|
|
const groupUpdate = message.group_update;
|
|
|
|
if (!groupUpdate) {
|
|
|
|
throw new Error(
|
|
|
|
'getPropsForGroupNotification: Message missing group_update'
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
2021-08-11 16:23:21 +00:00
|
|
|
const { conversationSelector } = options;
|
|
|
|
|
2021-06-17 17:15:10 +00:00
|
|
|
const changes = [];
|
|
|
|
|
|
|
|
if (
|
|
|
|
!groupUpdate.avatarUpdated &&
|
|
|
|
!groupUpdate.left &&
|
|
|
|
!groupUpdate.joined &&
|
|
|
|
!groupUpdate.name
|
|
|
|
) {
|
|
|
|
changes.push({
|
|
|
|
type: 'general' as ChangeType,
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
2021-06-23 16:14:11 +00:00
|
|
|
if (groupUpdate.joined?.length) {
|
2021-06-17 17:15:10 +00:00
|
|
|
changes.push({
|
|
|
|
type: 'add' as ChangeType,
|
|
|
|
contacts: map(
|
|
|
|
Array.isArray(groupUpdate.joined)
|
|
|
|
? groupUpdate.joined
|
|
|
|
: [groupUpdate.joined],
|
|
|
|
identifier => conversationSelector(identifier)
|
|
|
|
),
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
if (groupUpdate.left === 'You') {
|
|
|
|
changes.push({
|
|
|
|
type: 'remove' as ChangeType,
|
|
|
|
});
|
|
|
|
} else if (groupUpdate.left) {
|
|
|
|
changes.push({
|
|
|
|
type: 'remove' as ChangeType,
|
|
|
|
contacts: map(
|
|
|
|
Array.isArray(groupUpdate.left) ? groupUpdate.left : [groupUpdate.left],
|
|
|
|
identifier => conversationSelector(identifier)
|
|
|
|
),
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
if (groupUpdate.name) {
|
|
|
|
changes.push({
|
|
|
|
type: 'name' as ChangeType,
|
|
|
|
newName: groupUpdate.name,
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
if (groupUpdate.avatarUpdated) {
|
|
|
|
changes.push({
|
|
|
|
type: 'avatar' as ChangeType,
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
2021-08-11 16:23:21 +00:00
|
|
|
const from = getContact(message, options);
|
2021-06-17 17:15:10 +00:00
|
|
|
|
|
|
|
return {
|
|
|
|
from,
|
|
|
|
changes,
|
|
|
|
};
|
|
|
|
}
|
|
|
|
|
|
|
|
// End Session
|
|
|
|
|
2021-06-30 00:51:57 +00:00
|
|
|
export function isEndSession(
|
2021-11-11 23:45:47 +00:00
|
|
|
message: Pick<MessageWithUIFieldsType, 'flags'>
|
2021-06-30 00:51:57 +00:00
|
|
|
): boolean {
|
2021-07-09 19:36:10 +00:00
|
|
|
const flag = Proto.DataMessage.Flags.END_SESSION;
|
2021-06-17 17:15:10 +00:00
|
|
|
// eslint-disable-next-line no-bitwise
|
|
|
|
return Boolean(message.flags && message.flags & flag);
|
|
|
|
}
|
|
|
|
|
|
|
|
// Call History
|
|
|
|
|
2021-11-11 23:45:47 +00:00
|
|
|
export function isCallHistory(message: MessageWithUIFieldsType): boolean {
|
2021-06-17 17:15:10 +00:00
|
|
|
return message.type === 'call-history';
|
|
|
|
}
|
|
|
|
|
2021-08-11 16:23:21 +00:00
|
|
|
export type GetPropsForCallHistoryOptions = Pick<
|
|
|
|
GetPropsForBubbleOptions,
|
2023-08-09 00:53:06 +00:00
|
|
|
| 'callSelector'
|
|
|
|
| 'activeCall'
|
|
|
|
| 'callHistorySelector'
|
|
|
|
| 'conversationSelector'
|
|
|
|
| 'ourConversationId'
|
2023-12-12 16:11:39 +00:00
|
|
|
| 'selectedMessageIds'
|
|
|
|
| 'targetedMessageId'
|
2021-08-11 16:23:21 +00:00
|
|
|
>;
|
|
|
|
|
2023-08-21 17:09:54 +00:00
|
|
|
const emptyCallNotification: CallingNotificationType = {
|
2023-08-17 00:11:09 +00:00
|
|
|
callHistory: null,
|
|
|
|
callCreator: null,
|
2023-08-21 17:09:54 +00:00
|
|
|
activeConversationId: null,
|
|
|
|
groupCallEnded: null,
|
2023-08-17 00:11:09 +00:00
|
|
|
maxDevices: Infinity,
|
|
|
|
deviceCount: 0,
|
2023-12-12 16:11:39 +00:00
|
|
|
isSelectMode: false,
|
|
|
|
isTargeted: false,
|
2023-08-17 00:11:09 +00:00
|
|
|
};
|
|
|
|
|
2021-06-17 17:15:10 +00:00
|
|
|
export function getPropsForCallHistory(
|
2021-11-11 23:45:47 +00:00
|
|
|
message: MessageWithUIFieldsType,
|
2021-08-11 16:23:21 +00:00
|
|
|
{
|
|
|
|
callSelector,
|
2023-08-09 00:53:06 +00:00
|
|
|
callHistorySelector,
|
2021-08-11 16:23:21 +00:00
|
|
|
activeCall,
|
2023-08-09 00:53:06 +00:00
|
|
|
conversationSelector,
|
|
|
|
ourConversationId,
|
2023-12-12 16:11:39 +00:00
|
|
|
selectedMessageIds,
|
|
|
|
targetedMessageId,
|
2021-08-11 16:23:21 +00:00
|
|
|
}: GetPropsForCallHistoryOptions
|
2021-06-17 17:15:10 +00:00
|
|
|
): CallingNotificationType {
|
2023-08-09 00:53:06 +00:00
|
|
|
const { callId } = message;
|
2023-08-17 00:11:09 +00:00
|
|
|
if (callId == null) {
|
|
|
|
log.error('getPropsForCallHistory: Missing callId');
|
|
|
|
return emptyCallNotification;
|
2023-08-10 22:16:51 +00:00
|
|
|
}
|
2023-08-09 00:53:06 +00:00
|
|
|
const callHistory = callHistorySelector(callId);
|
2023-08-17 00:11:09 +00:00
|
|
|
if (callHistory == null) {
|
|
|
|
log.error('getPropsForCallHistory: Missing callHistory');
|
|
|
|
return emptyCallNotification;
|
|
|
|
}
|
2021-06-17 17:15:10 +00:00
|
|
|
|
2023-08-21 17:09:54 +00:00
|
|
|
const activeConversationId = activeCall?.conversationId ?? null;
|
|
|
|
|
2023-08-09 00:53:06 +00:00
|
|
|
const conversation = conversationSelector(callHistory.peerId);
|
|
|
|
strictAssert(
|
|
|
|
conversation != null,
|
|
|
|
'getPropsForCallHistory: Missing conversation'
|
|
|
|
);
|
2022-02-11 18:21:45 +00:00
|
|
|
|
2023-12-12 16:11:39 +00:00
|
|
|
const isSelectMode = selectedMessageIds != null;
|
|
|
|
|
2023-08-09 00:53:06 +00:00
|
|
|
let callCreator: ConversationType | null = null;
|
|
|
|
if (callHistory.ringerId) {
|
|
|
|
callCreator = conversationSelector(callHistory.ringerId);
|
|
|
|
} else if (callHistory.direction === CallDirection.Outgoing) {
|
|
|
|
callCreator = conversationSelector(ourConversationId);
|
|
|
|
}
|
2021-06-17 17:15:10 +00:00
|
|
|
|
2023-08-21 17:09:54 +00:00
|
|
|
if (callHistory.mode === CallMode.Direct) {
|
|
|
|
return {
|
|
|
|
callHistory,
|
|
|
|
callCreator,
|
|
|
|
activeConversationId,
|
|
|
|
groupCallEnded: false,
|
|
|
|
deviceCount: 0,
|
|
|
|
maxDevices: Infinity,
|
2023-12-12 16:11:39 +00:00
|
|
|
isSelectMode,
|
|
|
|
isTargeted: message.id === targetedMessageId,
|
2023-08-21 17:09:54 +00:00
|
|
|
};
|
2023-08-09 00:53:06 +00:00
|
|
|
}
|
2022-02-08 19:18:51 +00:00
|
|
|
|
2023-08-21 17:09:54 +00:00
|
|
|
// This could be a later call in the conversation
|
|
|
|
const conversationCall = callSelector(conversation.id);
|
|
|
|
|
|
|
|
if (conversationCall != null) {
|
|
|
|
strictAssert(
|
|
|
|
conversationCall?.callMode === CallMode.Group,
|
|
|
|
'getPropsForCallHistory: Call was expected to be a group call'
|
|
|
|
);
|
2021-06-17 17:15:10 +00:00
|
|
|
}
|
2023-08-09 00:53:06 +00:00
|
|
|
|
2023-08-21 17:09:54 +00:00
|
|
|
const conversationCallId =
|
|
|
|
conversationCall?.peekInfo?.eraId != null &&
|
|
|
|
getCallIdFromEra(conversationCall.peekInfo.eraId);
|
|
|
|
|
|
|
|
const deviceCount = conversationCall?.peekInfo?.deviceCount ?? 0;
|
|
|
|
const maxDevices = conversationCall?.peekInfo?.maxDevices ?? Infinity;
|
|
|
|
|
2023-08-09 00:53:06 +00:00
|
|
|
return {
|
|
|
|
callHistory,
|
|
|
|
callCreator,
|
2023-08-21 17:09:54 +00:00
|
|
|
activeConversationId,
|
|
|
|
groupCallEnded: callId !== conversationCallId || deviceCount === 0,
|
2023-08-09 00:53:06 +00:00
|
|
|
deviceCount,
|
|
|
|
maxDevices,
|
2023-12-12 16:11:39 +00:00
|
|
|
isSelectMode,
|
|
|
|
isTargeted: message.id === targetedMessageId,
|
2023-08-09 00:53:06 +00:00
|
|
|
};
|
2021-06-17 17:15:10 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// Profile Change
|
|
|
|
|
2021-11-11 23:45:47 +00:00
|
|
|
export function isProfileChange(message: MessageWithUIFieldsType): boolean {
|
2021-06-17 17:15:10 +00:00
|
|
|
return message.type === 'profile-change';
|
|
|
|
}
|
|
|
|
|
|
|
|
function getPropsForProfileChange(
|
2021-11-11 23:45:47 +00:00
|
|
|
message: MessageWithUIFieldsType,
|
2021-08-11 16:23:21 +00:00
|
|
|
{ conversationSelector }: GetPropsForBubbleOptions
|
2021-06-17 17:15:10 +00:00
|
|
|
): ProfileChangeNotificationPropsType {
|
|
|
|
const change = message.profileChange;
|
|
|
|
const { changedId } = message;
|
|
|
|
const changedContact = conversationSelector(changedId);
|
|
|
|
|
|
|
|
if (!change) {
|
|
|
|
throw new Error('getPropsForProfileChange: profileChange is undefined');
|
|
|
|
}
|
|
|
|
|
|
|
|
return {
|
|
|
|
changedContact,
|
|
|
|
change,
|
|
|
|
} as ProfileChangeNotificationPropsType;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Universal Timer Notification
|
|
|
|
|
|
|
|
// Note: smart, so props not generated here
|
|
|
|
|
|
|
|
export function isUniversalTimerNotification(
|
2021-11-11 23:45:47 +00:00
|
|
|
message: MessageWithUIFieldsType
|
2021-06-17 17:15:10 +00:00
|
|
|
): boolean {
|
|
|
|
return message.type === 'universal-timer-notification';
|
|
|
|
}
|
|
|
|
|
2023-04-05 20:48:00 +00:00
|
|
|
// Contact Removed Notification
|
|
|
|
|
|
|
|
// Note: smart, so props not generated here
|
|
|
|
|
|
|
|
export function isContactRemovedNotification(
|
|
|
|
message: MessageWithUIFieldsType
|
|
|
|
): boolean {
|
|
|
|
return message.type === 'contact-removed-notification';
|
|
|
|
}
|
|
|
|
|
2021-08-05 23:34:49 +00:00
|
|
|
// Change Number Notification
|
|
|
|
|
|
|
|
export function isChangeNumberNotification(
|
2021-11-11 23:45:47 +00:00
|
|
|
message: MessageWithUIFieldsType
|
2021-08-05 23:34:49 +00:00
|
|
|
): boolean {
|
|
|
|
return message.type === 'change-number-notification';
|
|
|
|
}
|
|
|
|
|
|
|
|
function getPropsForChangeNumberNotification(
|
2021-11-11 23:45:47 +00:00
|
|
|
message: MessageWithUIFieldsType,
|
2021-08-11 16:23:21 +00:00
|
|
|
{ conversationSelector }: GetPropsForBubbleOptions
|
2021-08-05 23:34:49 +00:00
|
|
|
): ChangeNumberNotificationProps {
|
|
|
|
return {
|
2023-08-16 20:54:39 +00:00
|
|
|
sender: conversationSelector(message.sourceServiceId),
|
2021-08-05 23:34:49 +00:00
|
|
|
timestamp: message.sent_at,
|
|
|
|
};
|
|
|
|
}
|
|
|
|
|
2021-06-17 17:15:10 +00:00
|
|
|
// Chat Session Refreshed
|
|
|
|
|
|
|
|
export function isChatSessionRefreshed(
|
2021-11-11 23:45:47 +00:00
|
|
|
message: MessageWithUIFieldsType
|
2021-06-17 17:15:10 +00:00
|
|
|
): boolean {
|
|
|
|
return message.type === 'chat-session-refreshed';
|
|
|
|
}
|
|
|
|
|
|
|
|
// Note: props are null
|
|
|
|
|
2022-12-05 22:46:54 +00:00
|
|
|
export function isConversationMerge(message: MessageWithUIFieldsType): boolean {
|
|
|
|
return message.type === 'conversation-merge';
|
|
|
|
}
|
|
|
|
export function getPropsForConversationMerge(
|
|
|
|
message: MessageWithUIFieldsType,
|
|
|
|
{ conversationSelector }: GetPropsForBubbleOptions
|
|
|
|
): ConversationMergePropsType {
|
|
|
|
const { conversationMerge } = message;
|
|
|
|
if (!conversationMerge) {
|
|
|
|
throw new Error(
|
|
|
|
'getPropsForConversationMerge: message is missing conversationMerge!'
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
|
|
|
const conversation = getConversation(message, conversationSelector);
|
|
|
|
const conversationTitle = conversation.title;
|
|
|
|
|
2023-01-12 22:18:08 +00:00
|
|
|
const { renderInfo } = conversationMerge;
|
|
|
|
const obsoleteConversationTitle = getTitleNoDefault(renderInfo);
|
|
|
|
const obsoleteConversationNumber = getNumber(renderInfo);
|
2022-12-05 22:46:54 +00:00
|
|
|
|
|
|
|
return {
|
|
|
|
conversationTitle,
|
|
|
|
obsoleteConversationTitle,
|
2023-01-12 22:18:08 +00:00
|
|
|
obsoleteConversationNumber,
|
2022-12-05 22:46:54 +00:00
|
|
|
};
|
|
|
|
}
|
|
|
|
|
2023-10-23 17:40:42 +00:00
|
|
|
export function isPhoneNumberDiscovery(
|
|
|
|
message: MessageWithUIFieldsType
|
|
|
|
): boolean {
|
|
|
|
return message.type === 'phone-number-discovery';
|
|
|
|
}
|
|
|
|
export function getPropsForPhoneNumberDiscovery(
|
|
|
|
message: MessageWithUIFieldsType,
|
|
|
|
{ conversationSelector }: GetPropsForBubbleOptions
|
|
|
|
): PhoneNumberDiscoveryPropsType {
|
|
|
|
const { phoneNumberDiscovery } = message;
|
|
|
|
if (!phoneNumberDiscovery) {
|
|
|
|
throw new Error(
|
|
|
|
'getPropsForPhoneNumberDiscovery: message is missing phoneNumberDiscovery!'
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
|
|
|
const conversation = getConversation(message, conversationSelector);
|
|
|
|
const conversationTitle = conversation.title;
|
|
|
|
const sharedGroup = conversation.sharedGroupNames[0];
|
|
|
|
const { e164 } = phoneNumberDiscovery;
|
|
|
|
|
|
|
|
return {
|
|
|
|
conversationTitle,
|
|
|
|
phoneNumber: renderNumber(e164) ?? e164,
|
|
|
|
sharedGroup,
|
|
|
|
};
|
|
|
|
}
|
|
|
|
|
2021-06-17 17:15:10 +00:00
|
|
|
// Delivery Issue
|
|
|
|
|
2021-11-11 23:45:47 +00:00
|
|
|
export function isDeliveryIssue(message: MessageWithUIFieldsType): boolean {
|
2021-06-17 17:15:10 +00:00
|
|
|
return message.type === 'delivery-issue';
|
|
|
|
}
|
|
|
|
|
|
|
|
function getPropsForDeliveryIssue(
|
2021-11-11 23:45:47 +00:00
|
|
|
message: MessageWithUIFieldsType,
|
2021-08-11 16:23:21 +00:00
|
|
|
{ conversationSelector }: GetPropsForBubbleOptions
|
2021-06-17 17:15:10 +00:00
|
|
|
): DeliveryIssuePropsType {
|
2023-08-16 20:54:39 +00:00
|
|
|
const sender = conversationSelector(message.sourceServiceId);
|
2022-12-23 00:32:03 +00:00
|
|
|
const conversation = getConversation(message, conversationSelector);
|
2021-06-17 17:15:10 +00:00
|
|
|
|
|
|
|
return {
|
|
|
|
sender,
|
2021-07-27 20:30:41 +00:00
|
|
|
inGroup: conversation.type === 'group',
|
2021-06-17 17:15:10 +00:00
|
|
|
};
|
|
|
|
}
|
|
|
|
|
|
|
|
// Other utility functions
|
|
|
|
|
2021-11-11 23:45:47 +00:00
|
|
|
export function isTapToView(message: MessageWithUIFieldsType): boolean {
|
2021-06-17 17:15:10 +00:00
|
|
|
// If a message is deleted for everyone, that overrides all other styling
|
|
|
|
if (message.deletedForEveryone) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
return Boolean(message.isViewOnce || message.messageTimer);
|
|
|
|
}
|
|
|
|
|
|
|
|
export function getMessagePropStatus(
|
2021-07-19 22:44:49 +00:00
|
|
|
message: Pick<
|
2021-11-11 23:45:47 +00:00
|
|
|
MessageWithUIFieldsType,
|
2022-03-04 19:22:31 +00:00
|
|
|
| 'deletedForEveryone'
|
|
|
|
| 'deletedForEveryoneFailed'
|
|
|
|
| 'deletedForEveryoneSendStatus'
|
|
|
|
| 'errors'
|
|
|
|
| 'sendStateByConversationId'
|
|
|
|
| 'type'
|
2021-07-19 22:44:49 +00:00
|
|
|
>,
|
2022-02-23 18:48:40 +00:00
|
|
|
ourConversationId: string | undefined
|
2021-06-17 17:15:10 +00:00
|
|
|
): LastMessageStatus | undefined {
|
2022-06-01 18:40:36 +00:00
|
|
|
if (!isOutgoing(message)) {
|
2022-05-31 16:26:07 +00:00
|
|
|
return hasErrors(message) ? 'error' : undefined;
|
2021-07-09 21:38:51 +00:00
|
|
|
}
|
2021-07-12 23:51:45 +00:00
|
|
|
|
2021-07-19 22:44:49 +00:00
|
|
|
if (getLastChallengeError(message)) {
|
|
|
|
return 'paused';
|
|
|
|
}
|
|
|
|
|
2022-03-04 19:22:31 +00:00
|
|
|
const {
|
|
|
|
deletedForEveryone,
|
|
|
|
deletedForEveryoneFailed,
|
|
|
|
deletedForEveryoneSendStatus,
|
|
|
|
sendStateByConversationId = {},
|
|
|
|
} = message;
|
|
|
|
|
|
|
|
// Note: we only do anything here if deletedForEveryoneSendStatus exists, because old
|
|
|
|
// messages deleted for everyone won't have send status.
|
|
|
|
if (deletedForEveryone && deletedForEveryoneSendStatus) {
|
|
|
|
if (deletedForEveryoneFailed) {
|
|
|
|
const anySuccessfulSends = Object.values(
|
|
|
|
deletedForEveryoneSendStatus
|
|
|
|
).some(item => item);
|
|
|
|
|
|
|
|
return anySuccessfulSends ? 'partial-sent' : 'error';
|
|
|
|
}
|
|
|
|
const missingSends = Object.values(deletedForEveryoneSendStatus).some(
|
|
|
|
item => !item
|
|
|
|
);
|
|
|
|
if (missingSends) {
|
|
|
|
return 'sending';
|
|
|
|
}
|
|
|
|
}
|
2021-07-19 22:44:49 +00:00
|
|
|
|
2022-02-23 18:48:40 +00:00
|
|
|
if (
|
|
|
|
ourConversationId &&
|
|
|
|
isMessageJustForMe(sendStateByConversationId, ourConversationId)
|
|
|
|
) {
|
2021-07-19 22:44:49 +00:00
|
|
|
const status =
|
|
|
|
sendStateByConversationId[ourConversationId]?.status ??
|
|
|
|
SendStatus.Pending;
|
|
|
|
const sent = isSent(status);
|
2021-08-31 20:58:39 +00:00
|
|
|
if (
|
|
|
|
hasErrors(message) ||
|
|
|
|
someSendStatus(sendStateByConversationId, isFailed)
|
|
|
|
) {
|
2021-07-19 22:44:49 +00:00
|
|
|
return sent ? 'partial-sent' : 'error';
|
|
|
|
}
|
2021-07-27 15:42:25 +00:00
|
|
|
return sent ? 'viewed' : 'sending';
|
2021-07-19 22:44:49 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
const sendStates = Object.values(
|
2022-02-23 18:48:40 +00:00
|
|
|
ourConversationId
|
|
|
|
? omit(sendStateByConversationId, ourConversationId)
|
|
|
|
: sendStateByConversationId
|
2021-07-19 22:44:49 +00:00
|
|
|
);
|
|
|
|
const highestSuccessfulStatus = sendStates.reduce(
|
|
|
|
(result: SendStatus, { status }) => maxStatus(result, status),
|
|
|
|
SendStatus.Pending
|
|
|
|
);
|
|
|
|
|
2021-08-31 20:58:39 +00:00
|
|
|
if (
|
|
|
|
hasErrors(message) ||
|
|
|
|
someSendStatus(sendStateByConversationId, isFailed)
|
|
|
|
) {
|
2021-07-19 22:44:49 +00:00
|
|
|
return isSent(highestSuccessfulStatus) ? 'partial-sent' : 'error';
|
|
|
|
}
|
2021-07-27 15:42:25 +00:00
|
|
|
if (isViewed(highestSuccessfulStatus)) {
|
|
|
|
return 'viewed';
|
|
|
|
}
|
2021-07-21 19:21:16 +00:00
|
|
|
if (isRead(highestSuccessfulStatus)) {
|
2021-06-17 17:15:10 +00:00
|
|
|
return 'read';
|
|
|
|
}
|
2021-07-19 22:44:49 +00:00
|
|
|
if (isDelivered(highestSuccessfulStatus)) {
|
2021-06-17 17:15:10 +00:00
|
|
|
return 'delivered';
|
|
|
|
}
|
2021-07-19 22:44:49 +00:00
|
|
|
if (isSent(highestSuccessfulStatus)) {
|
2021-06-17 17:15:10 +00:00
|
|
|
return 'sent';
|
|
|
|
}
|
|
|
|
return 'sending';
|
|
|
|
}
|
|
|
|
|
|
|
|
export function getPropsForEmbeddedContact(
|
2021-11-11 23:45:47 +00:00
|
|
|
message: MessageWithUIFieldsType,
|
2022-02-23 18:48:40 +00:00
|
|
|
regionCode: string | undefined,
|
2023-08-10 16:43:33 +00:00
|
|
|
accountSelector: (identifier?: string) => ServiceIdString | undefined
|
2021-08-20 01:56:39 +00:00
|
|
|
): EmbeddedContactType | undefined {
|
2021-06-17 17:15:10 +00:00
|
|
|
const contacts = message.contact;
|
|
|
|
if (!contacts || !contacts.length) {
|
|
|
|
return undefined;
|
|
|
|
}
|
|
|
|
|
|
|
|
const firstContact = contacts[0];
|
|
|
|
const numbers = firstContact?.number;
|
|
|
|
const firstNumber = numbers && numbers[0] ? numbers[0].value : undefined;
|
|
|
|
|
2021-08-20 01:56:39 +00:00
|
|
|
return embeddedContactSelector(firstContact, {
|
2021-06-17 17:15:10 +00:00
|
|
|
regionCode,
|
2023-02-24 23:18:57 +00:00
|
|
|
getAbsoluteAttachmentPath: getAttachmentUrlForPath,
|
2021-06-17 17:15:10 +00:00
|
|
|
firstNumber,
|
2023-08-16 20:54:39 +00:00
|
|
|
serviceId: accountSelector(firstNumber),
|
2021-06-17 17:15:10 +00:00
|
|
|
});
|
|
|
|
}
|
|
|
|
|
2023-02-24 23:18:57 +00:00
|
|
|
export function getAttachmentUrlForPath(path: string): string {
|
|
|
|
return window.Signal.Migrations.getAbsoluteAttachmentPath(path);
|
|
|
|
}
|
|
|
|
|
2021-06-17 17:15:10 +00:00
|
|
|
export function getPropsForAttachment(
|
2021-06-24 19:05:27 +00:00
|
|
|
attachment: AttachmentType
|
2022-05-23 23:07:41 +00:00
|
|
|
): AttachmentType | undefined {
|
2021-06-17 17:15:10 +00:00
|
|
|
if (!attachment) {
|
2022-05-23 23:07:41 +00:00
|
|
|
return undefined;
|
2021-06-17 17:15:10 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
const { path, pending, size, screenshot, thumbnail } = attachment;
|
|
|
|
|
|
|
|
return {
|
|
|
|
...attachment,
|
2021-06-24 19:05:27 +00:00
|
|
|
fileSize: size ? filesize(size) : undefined,
|
2021-06-17 17:15:10 +00:00
|
|
|
isVoiceMessage: isVoiceMessage(attachment),
|
|
|
|
pending,
|
2023-02-24 23:18:57 +00:00
|
|
|
url: path ? getAttachmentUrlForPath(path) : undefined,
|
2022-06-10 01:10:20 +00:00
|
|
|
screenshot: screenshot?.path
|
2021-06-17 17:15:10 +00:00
|
|
|
? {
|
|
|
|
...screenshot,
|
2023-02-24 23:18:57 +00:00
|
|
|
url: getAttachmentUrlForPath(screenshot.path),
|
2021-06-17 17:15:10 +00:00
|
|
|
}
|
2021-06-24 19:05:27 +00:00
|
|
|
: undefined,
|
2022-06-10 01:10:20 +00:00
|
|
|
thumbnail: thumbnail?.path
|
2021-06-17 17:15:10 +00:00
|
|
|
? {
|
|
|
|
...thumbnail,
|
2023-02-24 23:18:57 +00:00
|
|
|
url: getAttachmentUrlForPath(thumbnail.path),
|
2021-06-17 17:15:10 +00:00
|
|
|
}
|
2021-06-24 19:05:27 +00:00
|
|
|
: undefined,
|
2021-06-17 17:15:10 +00:00
|
|
|
};
|
|
|
|
}
|
|
|
|
|
|
|
|
function processQuoteAttachment(
|
|
|
|
attachment: AttachmentType
|
|
|
|
): QuotedAttachmentType {
|
|
|
|
const { thumbnail } = attachment;
|
|
|
|
const path =
|
2023-02-24 23:18:57 +00:00
|
|
|
thumbnail && thumbnail.path && getAttachmentUrlForPath(thumbnail.path);
|
2021-06-17 17:15:10 +00:00
|
|
|
const objectUrl = thumbnail && thumbnail.objectUrl;
|
|
|
|
|
|
|
|
const thumbnailWithObjectUrl =
|
|
|
|
(!path && !objectUrl) || !thumbnail
|
|
|
|
? undefined
|
|
|
|
: { ...thumbnail, objectUrl: path || objectUrl };
|
|
|
|
|
|
|
|
return {
|
|
|
|
...attachment,
|
|
|
|
isVoiceMessage: isVoiceMessage(attachment),
|
|
|
|
thumbnail: thumbnailWithObjectUrl,
|
|
|
|
};
|
|
|
|
}
|
|
|
|
|
2021-10-29 23:19:44 +00:00
|
|
|
function canReplyOrReact(
|
2021-07-01 23:57:10 +00:00
|
|
|
message: Pick<
|
2021-11-11 23:45:47 +00:00
|
|
|
MessageWithUIFieldsType,
|
2022-07-01 00:52:03 +00:00
|
|
|
| 'canReplyToStory'
|
|
|
|
| 'deletedForEveryone'
|
|
|
|
| 'sendStateByConversationId'
|
2022-11-30 21:47:54 +00:00
|
|
|
| 'payment'
|
2022-07-01 00:52:03 +00:00
|
|
|
| 'type'
|
2021-07-01 23:57:10 +00:00
|
|
|
>,
|
2022-02-23 18:48:40 +00:00
|
|
|
ourConversationId: string | undefined,
|
2021-10-29 23:19:44 +00:00
|
|
|
conversation: undefined | Readonly<ConversationType>
|
2021-06-17 17:15:10 +00:00
|
|
|
): boolean {
|
2021-07-19 22:44:49 +00:00
|
|
|
const { deletedForEveryone, sendStateByConversationId } = message;
|
2021-06-17 17:15:10 +00:00
|
|
|
|
|
|
|
if (!conversation) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (conversation.isGroupV1AndDisabled) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (isMissingRequiredProfileSharing(conversation)) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2023-12-08 02:20:36 +00:00
|
|
|
if (
|
|
|
|
!conversation.acceptedMessageRequest &&
|
|
|
|
conversation.removalStage !== 'justNotification'
|
|
|
|
) {
|
2021-06-17 17:15:10 +00:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2023-06-14 13:23:06 +00:00
|
|
|
if (conversation.isBlocked) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2021-07-01 23:57:10 +00:00
|
|
|
if (deletedForEveryone) {
|
2021-06-17 17:15:10 +00:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2022-11-09 02:38:19 +00:00
|
|
|
if (isSignalConversation(conversation)) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2021-07-01 23:57:10 +00:00
|
|
|
if (isOutgoing(message)) {
|
2021-07-19 22:44:49 +00:00
|
|
|
return (
|
|
|
|
isMessageJustForMe(sendStateByConversationId, ourConversationId) ||
|
2022-02-23 18:48:40 +00:00
|
|
|
someSendStatus(
|
|
|
|
ourConversationId
|
|
|
|
? omit(sendStateByConversationId, ourConversationId)
|
|
|
|
: sendStateByConversationId,
|
|
|
|
isSent
|
|
|
|
)
|
2021-07-19 22:44:49 +00:00
|
|
|
);
|
2021-06-17 17:15:10 +00:00
|
|
|
}
|
|
|
|
|
2022-03-04 21:14:52 +00:00
|
|
|
// If we get past all the other checks above then we can always reply or
|
|
|
|
// react if the message type is "incoming" | "story"
|
2022-07-01 00:52:03 +00:00
|
|
|
if (isIncoming(message)) {
|
2021-06-17 17:15:10 +00:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2022-07-01 00:52:03 +00:00
|
|
|
if (isStory(message)) {
|
2022-09-21 19:19:16 +00:00
|
|
|
return (
|
|
|
|
Boolean(message.canReplyToStory) && conversation.id !== ourConversationId
|
|
|
|
);
|
2022-07-01 00:52:03 +00:00
|
|
|
}
|
|
|
|
|
2021-06-17 17:15:10 +00:00
|
|
|
// Fail safe.
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2021-10-29 23:19:44 +00:00
|
|
|
export function canReply(
|
|
|
|
message: Pick<
|
2021-11-11 23:45:47 +00:00
|
|
|
MessageWithUIFieldsType,
|
2022-07-01 00:52:03 +00:00
|
|
|
| 'canReplyToStory'
|
2021-10-29 23:19:44 +00:00
|
|
|
| 'conversationId'
|
|
|
|
| 'deletedForEveryone'
|
|
|
|
| 'sendStateByConversationId'
|
|
|
|
| 'type'
|
|
|
|
>,
|
2022-02-23 18:48:40 +00:00
|
|
|
ourConversationId: string | undefined,
|
2021-10-29 23:19:44 +00:00
|
|
|
conversationSelector: GetConversationByIdType
|
|
|
|
): boolean {
|
|
|
|
const conversation = getConversation(message, conversationSelector);
|
|
|
|
if (
|
|
|
|
!conversation ||
|
|
|
|
(conversation.announcementsOnly && !conversation.areWeAdmin)
|
|
|
|
) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
return canReplyOrReact(message, ourConversationId, conversation);
|
|
|
|
}
|
|
|
|
|
|
|
|
export function canReact(
|
|
|
|
message: Pick<
|
2021-11-11 23:45:47 +00:00
|
|
|
MessageWithUIFieldsType,
|
2021-10-29 23:19:44 +00:00
|
|
|
| 'conversationId'
|
|
|
|
| 'deletedForEveryone'
|
|
|
|
| 'sendStateByConversationId'
|
|
|
|
| 'type'
|
|
|
|
>,
|
2022-02-23 18:48:40 +00:00
|
|
|
ourConversationId: string | undefined,
|
2021-10-29 23:19:44 +00:00
|
|
|
conversationSelector: GetConversationByIdType
|
|
|
|
): boolean {
|
|
|
|
const conversation = getConversation(message, conversationSelector);
|
|
|
|
return canReplyOrReact(message, ourConversationId, conversation);
|
|
|
|
}
|
|
|
|
|
2023-04-22 01:52:25 +00:00
|
|
|
export function canCopy(
|
|
|
|
message: Pick<MessageWithUIFieldsType, 'body' | 'deletedForEveryone'>
|
|
|
|
): boolean {
|
|
|
|
return !message.deletedForEveryone && Boolean(message.body);
|
|
|
|
}
|
|
|
|
|
2021-08-02 19:26:48 +00:00
|
|
|
export function canDeleteForEveryone(
|
|
|
|
message: Pick<
|
2021-11-11 23:45:47 +00:00
|
|
|
MessageWithUIFieldsType,
|
2021-08-02 19:26:48 +00:00
|
|
|
'type' | 'deletedForEveryone' | 'sent_at' | 'sendStateByConversationId'
|
2024-01-03 16:46:39 +00:00
|
|
|
>,
|
|
|
|
isMe: boolean
|
2021-08-02 19:26:48 +00:00
|
|
|
): boolean {
|
|
|
|
return (
|
|
|
|
// Is this a message I sent?
|
|
|
|
isOutgoing(message) &&
|
|
|
|
// Has the message already been deleted?
|
|
|
|
!message.deletedForEveryone &&
|
2024-01-03 16:46:39 +00:00
|
|
|
// Is it too old to delete? (we relax that requirement in Note to Self)
|
|
|
|
(isMoreRecentThan(message.sent_at, DAY) || isMe) &&
|
2021-12-02 21:28:19 +00:00
|
|
|
// Is it sent to anyone?
|
|
|
|
someSendStatus(message.sendStateByConversationId, isSent)
|
2021-08-02 19:26:48 +00:00
|
|
|
);
|
2021-06-17 17:15:10 +00:00
|
|
|
}
|
|
|
|
|
2023-04-10 21:38:34 +00:00
|
|
|
export const canDeleteMessagesForEveryone = createSelector(
|
2024-01-03 16:46:39 +00:00
|
|
|
[
|
|
|
|
getMessages,
|
|
|
|
(_state, options: { messageIds: ReadonlyArray<string>; isMe: boolean }) =>
|
|
|
|
options,
|
|
|
|
],
|
|
|
|
(messagesLookup, options) => {
|
|
|
|
return options.messageIds.every(messageId => {
|
2023-04-10 21:38:34 +00:00
|
|
|
const message = getOwn(messagesLookup, messageId);
|
2024-01-03 16:46:39 +00:00
|
|
|
return message != null && canDeleteForEveryone(message, options.isMe);
|
2023-04-10 21:38:34 +00:00
|
|
|
});
|
|
|
|
}
|
|
|
|
);
|
|
|
|
|
2022-03-04 19:22:31 +00:00
|
|
|
export function canRetryDeleteForEveryone(
|
|
|
|
message: Pick<
|
|
|
|
MessageWithUIFieldsType,
|
|
|
|
'deletedForEveryone' | 'deletedForEveryoneFailed' | 'sent_at'
|
|
|
|
>
|
|
|
|
): boolean {
|
|
|
|
return Boolean(
|
|
|
|
message.deletedForEveryone &&
|
|
|
|
message.deletedForEveryoneFailed &&
|
|
|
|
// Is it too old to delete?
|
|
|
|
isMoreRecentThan(message.sent_at, DAY)
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
2021-06-17 17:15:10 +00:00
|
|
|
export function canDownload(
|
2021-11-11 23:45:47 +00:00
|
|
|
message: MessageWithUIFieldsType,
|
2021-06-17 17:15:10 +00:00
|
|
|
conversationSelector: GetConversationByIdType
|
|
|
|
): boolean {
|
|
|
|
if (isOutgoing(message)) {
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
const conversation = getConversation(message, conversationSelector);
|
|
|
|
const isAccepted = Boolean(
|
|
|
|
conversation && conversation.acceptedMessageRequest
|
|
|
|
);
|
|
|
|
if (!isAccepted) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Ensure that all attachments are downloadable
|
|
|
|
const { attachments } = message;
|
|
|
|
if (attachments && attachments.length) {
|
|
|
|
return attachments.every(attachment => Boolean(attachment.path));
|
|
|
|
}
|
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
export function getLastChallengeError(
|
2021-11-11 23:45:47 +00:00
|
|
|
message: Pick<MessageWithUIFieldsType, 'errors'>
|
2021-06-17 17:15:10 +00:00
|
|
|
): ShallowChallengeError | undefined {
|
|
|
|
const { errors } = message;
|
|
|
|
if (!errors) {
|
|
|
|
return undefined;
|
|
|
|
}
|
|
|
|
|
|
|
|
const challengeErrors = errors
|
|
|
|
.filter((error): error is ShallowChallengeError => {
|
|
|
|
return (
|
|
|
|
error.name === 'SendMessageChallengeError' &&
|
|
|
|
isNumber(error.retryAfter) &&
|
|
|
|
isObject(error.data)
|
|
|
|
);
|
|
|
|
})
|
|
|
|
.sort((a, b) => a.retryAfter - b.retryAfter);
|
|
|
|
|
|
|
|
return challengeErrors.pop();
|
|
|
|
}
|
2022-12-21 20:44:23 +00:00
|
|
|
|
2023-03-20 22:23:53 +00:00
|
|
|
const getTargetedMessageForDetails = (
|
2022-12-21 20:44:23 +00:00
|
|
|
state: StateType
|
|
|
|
): MessageAttributesType | undefined =>
|
2023-03-20 22:23:53 +00:00
|
|
|
state.conversations.targetedMessageForDetails;
|
2022-12-21 20:44:23 +00:00
|
|
|
|
|
|
|
const OUTGOING_KEY_ERROR = 'OutgoingIdentityKeyError';
|
|
|
|
|
|
|
|
export const getMessageDetails = createSelector(
|
|
|
|
getAccountSelector,
|
|
|
|
getContactNameColorSelector,
|
|
|
|
getConversationSelector,
|
|
|
|
getIntl,
|
|
|
|
getRegionCode,
|
2023-03-20 22:23:53 +00:00
|
|
|
getTargetedMessageForDetails,
|
2022-12-21 20:44:23 +00:00
|
|
|
getUserACI,
|
|
|
|
getUserPNI,
|
|
|
|
getUserConversationId,
|
|
|
|
getUserNumber,
|
2023-03-20 22:23:53 +00:00
|
|
|
getSelectedMessageIds,
|
2023-09-01 17:03:44 +00:00
|
|
|
getDefaultConversationColor,
|
2022-12-21 20:44:23 +00:00
|
|
|
(
|
|
|
|
accountSelector,
|
|
|
|
contactNameColorSelector,
|
|
|
|
conversationSelector,
|
|
|
|
i18n,
|
|
|
|
regionCode,
|
|
|
|
message,
|
2023-08-10 16:43:33 +00:00
|
|
|
ourAci,
|
|
|
|
ourPni,
|
2022-12-21 20:44:23 +00:00
|
|
|
ourConversationId,
|
2023-03-20 22:23:53 +00:00
|
|
|
ourNumber,
|
2023-09-01 17:03:44 +00:00
|
|
|
selectedMessageIds,
|
|
|
|
defaultConversationColor
|
2022-12-21 20:44:23 +00:00
|
|
|
): SmartMessageDetailPropsType | undefined => {
|
|
|
|
if (!message || !ourConversationId) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
const {
|
|
|
|
errors: messageErrors = [],
|
|
|
|
sendStateByConversationId = {},
|
|
|
|
unidentifiedDeliveries = [],
|
|
|
|
unidentifiedDeliveryReceived,
|
|
|
|
} = message;
|
|
|
|
|
|
|
|
const unidentifiedDeliveriesSet = new Set(
|
|
|
|
map(
|
|
|
|
unidentifiedDeliveries,
|
|
|
|
identifier =>
|
|
|
|
window.ConversationController.getConversationId(identifier) as string
|
|
|
|
)
|
|
|
|
);
|
|
|
|
|
|
|
|
let conversationIds: Array<string>;
|
|
|
|
if (isIncoming(message)) {
|
|
|
|
conversationIds = [
|
|
|
|
getContactId(message, {
|
|
|
|
conversationSelector,
|
|
|
|
ourConversationId,
|
|
|
|
ourNumber,
|
2023-08-10 16:43:33 +00:00
|
|
|
ourAci,
|
2022-12-21 20:44:23 +00:00
|
|
|
}),
|
|
|
|
].filter(isNotNil);
|
|
|
|
} else if (!isEmpty(sendStateByConversationId)) {
|
|
|
|
if (isMessageJustForMe(sendStateByConversationId, ourConversationId)) {
|
|
|
|
conversationIds = [ourConversationId];
|
|
|
|
} else {
|
|
|
|
conversationIds = Object.keys(sendStateByConversationId).filter(
|
|
|
|
id => id !== ourConversationId
|
|
|
|
);
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
const messageConversation = window.ConversationController.get(
|
|
|
|
message.conversationId
|
|
|
|
);
|
|
|
|
const conversationRecipients = messageConversation
|
|
|
|
? getRecipients(messageConversation.attributes) || []
|
|
|
|
: [];
|
|
|
|
// Older messages don't have the recipients included on the message, so we fall back
|
|
|
|
// to the conversation's current recipients
|
|
|
|
conversationIds = conversationRecipients
|
|
|
|
.map((id: string) =>
|
|
|
|
window.ConversationController.getConversationId(id)
|
|
|
|
)
|
|
|
|
.filter(isNotNil);
|
|
|
|
}
|
|
|
|
|
|
|
|
// This will make the error message for outgoing key errors a bit nicer
|
|
|
|
const allErrors = messageErrors.map(error => {
|
|
|
|
if (error.name === OUTGOING_KEY_ERROR) {
|
|
|
|
return {
|
|
|
|
...error,
|
2023-03-30 00:03:25 +00:00
|
|
|
message: i18n('icu:newIdentity'),
|
2022-12-21 20:44:23 +00:00
|
|
|
};
|
|
|
|
}
|
|
|
|
|
|
|
|
return error;
|
|
|
|
});
|
|
|
|
|
|
|
|
// If an error has a specific number it's associated with, we'll show it next to
|
|
|
|
// that contact. Otherwise, it will be a standalone entry.
|
|
|
|
const errors = allErrors.filter(error =>
|
2023-08-10 16:43:33 +00:00
|
|
|
Boolean(error.serviceId || error.number)
|
2022-12-21 20:44:23 +00:00
|
|
|
);
|
|
|
|
const errorsGroupedById = groupBy(allErrors, error => {
|
2023-08-10 16:43:33 +00:00
|
|
|
const serviceId = error.serviceId || error.number;
|
|
|
|
if (!serviceId) {
|
2022-12-21 20:44:23 +00:00
|
|
|
return null;
|
|
|
|
}
|
|
|
|
|
2023-08-10 16:43:33 +00:00
|
|
|
return window.ConversationController.getConversationId(serviceId);
|
2022-12-21 20:44:23 +00:00
|
|
|
});
|
|
|
|
|
|
|
|
const hasUnidentifiedDeliveryIndicators = window.storage.get(
|
|
|
|
'unidentifiedDeliveryIndicators',
|
|
|
|
false
|
|
|
|
);
|
|
|
|
|
|
|
|
const contacts: ReadonlyArray<SmartMessageDetailContact> =
|
|
|
|
conversationIds.map(id => {
|
|
|
|
const errorsForContact = getOwn(errorsGroupedById, id);
|
|
|
|
const isOutgoingKeyError = Boolean(
|
|
|
|
errorsForContact?.some(error => error.name === OUTGOING_KEY_ERROR)
|
|
|
|
);
|
|
|
|
|
|
|
|
let isUnidentifiedDelivery = false;
|
|
|
|
if (hasUnidentifiedDeliveryIndicators) {
|
|
|
|
isUnidentifiedDelivery = isIncoming(message)
|
|
|
|
? Boolean(unidentifiedDeliveryReceived)
|
|
|
|
: unidentifiedDeliveriesSet.has(id);
|
|
|
|
}
|
|
|
|
|
|
|
|
const sendState = getOwn(sendStateByConversationId, id);
|
|
|
|
|
|
|
|
let status = sendState?.status;
|
|
|
|
|
|
|
|
// If a message was only sent to yourself (Note to Self or a lonely group), it
|
|
|
|
// is shown read.
|
|
|
|
if (id === ourConversationId && status && isSent(status)) {
|
|
|
|
status = SendStatus.Read;
|
|
|
|
}
|
|
|
|
|
|
|
|
const statusTimestamp = sendState?.updatedAt;
|
|
|
|
|
|
|
|
return {
|
|
|
|
...conversationSelector(id),
|
|
|
|
errors: errorsForContact,
|
|
|
|
isOutgoingKeyError,
|
|
|
|
isUnidentifiedDelivery,
|
|
|
|
status,
|
|
|
|
statusTimestamp:
|
|
|
|
statusTimestamp === message.timestamp ? undefined : statusTimestamp,
|
|
|
|
};
|
|
|
|
});
|
|
|
|
|
|
|
|
return {
|
|
|
|
contacts,
|
|
|
|
errors,
|
|
|
|
message: getPropsForMessage(message, {
|
|
|
|
accountSelector,
|
|
|
|
contactNameColorSelector,
|
|
|
|
conversationSelector,
|
2023-08-10 16:43:33 +00:00
|
|
|
ourAci,
|
|
|
|
ourPni,
|
2022-12-21 20:44:23 +00:00
|
|
|
ourConversationId,
|
|
|
|
ourNumber,
|
|
|
|
regionCode,
|
2023-03-20 22:23:53 +00:00
|
|
|
selectedMessageIds,
|
2023-09-01 17:03:44 +00:00
|
|
|
defaultConversationColor,
|
2022-12-21 20:44:23 +00:00
|
|
|
}),
|
|
|
|
receivedAt: Number(message.received_at_ms || message.received_at),
|
|
|
|
};
|
|
|
|
}
|
|
|
|
);
|