2021-03-24 22:06:12 +00:00
|
|
|
// Copyright 2019-2021 Signal Messenger, LLC
|
2020-10-30 20:34:04 +00:00
|
|
|
// SPDX-License-Identifier: AGPL-3.0-only
|
|
|
|
|
2021-10-26 19:15:33 +00:00
|
|
|
import type { RefObject } from 'react';
|
|
|
|
import React from 'react';
|
2021-08-11 16:23:21 +00:00
|
|
|
import { omit } from 'lodash';
|
|
|
|
|
2021-10-26 19:15:33 +00:00
|
|
|
import type { LocalizerType, ThemeType } from '../../types/Util';
|
2019-03-20 17:42:28 +00:00
|
|
|
|
2021-10-26 19:15:33 +00:00
|
|
|
import type { InteractionModeType } from '../../state/ducks/conversations';
|
|
|
|
import type {
|
2020-05-05 19:49:34 +00:00
|
|
|
Props as AllMessageProps,
|
2019-03-20 17:42:28 +00:00
|
|
|
PropsActions as MessageActionsType,
|
|
|
|
PropsData as MessageProps,
|
|
|
|
} from './Message';
|
2021-10-26 19:15:33 +00:00
|
|
|
import { Message } from './Message';
|
|
|
|
import type { PropsActionsType as CallingNotificationActionsType } from './CallingNotification';
|
|
|
|
import { CallingNotification } from './CallingNotification';
|
|
|
|
import type { PropsActionsType as PropsChatSessionRefreshedActionsType } from './ChatSessionRefreshedNotification';
|
|
|
|
import { ChatSessionRefreshedNotification } from './ChatSessionRefreshedNotification';
|
|
|
|
import type {
|
2021-07-30 20:30:59 +00:00
|
|
|
PropsActionsType as DeliveryIssueActionProps,
|
2021-05-28 19:11:19 +00:00
|
|
|
PropsDataType as DeliveryIssueProps,
|
|
|
|
} from './DeliveryIssueNotification';
|
2021-10-26 19:15:33 +00:00
|
|
|
import { DeliveryIssueNotification } from './DeliveryIssueNotification';
|
2021-09-07 19:55:03 +00:00
|
|
|
import { LinkNotification } from './LinkNotification';
|
2021-10-26 19:15:33 +00:00
|
|
|
import type { PropsData as ChangeNumberNotificationProps } from './ChangeNumberNotification';
|
|
|
|
import { ChangeNumberNotification } from './ChangeNumberNotification';
|
|
|
|
import type { CallingNotificationType } from '../../util/callingNotification';
|
2019-11-07 21:36:16 +00:00
|
|
|
import { InlineNotificationWrapper } from './InlineNotificationWrapper';
|
2021-10-26 19:15:33 +00:00
|
|
|
import type {
|
2019-05-31 22:42:01 +00:00
|
|
|
PropsActions as UnsupportedMessageActionsType,
|
|
|
|
PropsData as UnsupportedMessageProps,
|
|
|
|
} from './UnsupportedMessage';
|
2021-10-26 19:15:33 +00:00
|
|
|
import { UnsupportedMessage } from './UnsupportedMessage';
|
|
|
|
import type { PropsData as TimerNotificationProps } from './TimerNotification';
|
|
|
|
import { TimerNotification } from './TimerNotification';
|
|
|
|
import type {
|
2019-03-20 17:42:28 +00:00
|
|
|
PropsActions as SafetyNumberActionsType,
|
|
|
|
PropsData as SafetyNumberNotificationProps,
|
|
|
|
} from './SafetyNumberNotification';
|
2021-10-26 19:15:33 +00:00
|
|
|
import { SafetyNumberNotification } from './SafetyNumberNotification';
|
|
|
|
import type { PropsData as VerificationNotificationProps } from './VerificationNotification';
|
|
|
|
import { VerificationNotification } from './VerificationNotification';
|
|
|
|
import type { PropsData as GroupNotificationProps } from './GroupNotification';
|
|
|
|
import { GroupNotification } from './GroupNotification';
|
|
|
|
import type { PropsDataType as GroupV2ChangeProps } from './GroupV2Change';
|
|
|
|
import { GroupV2Change } from './GroupV2Change';
|
|
|
|
import type { PropsDataType as GroupV1MigrationProps } from './GroupV1Migration';
|
|
|
|
import { GroupV1Migration } from './GroupV1Migration';
|
|
|
|
import type { SmartContactRendererType } from '../../groupChange';
|
2019-03-20 17:42:28 +00:00
|
|
|
import { ResetSessionNotification } from './ResetSessionNotification';
|
2021-10-26 19:15:33 +00:00
|
|
|
import type { PropsType as ProfileChangeNotificationPropsType } from './ProfileChangeNotification';
|
|
|
|
import { ProfileChangeNotification } from './ProfileChangeNotification';
|
2021-09-17 18:27:53 +00:00
|
|
|
import * as log from '../../logging/log';
|
2019-03-20 17:42:28 +00:00
|
|
|
|
2020-06-04 18:16:19 +00:00
|
|
|
type CallHistoryType = {
|
|
|
|
type: 'callHistory';
|
2020-12-07 20:43:19 +00:00
|
|
|
data: CallingNotificationType;
|
2020-06-04 18:16:19 +00:00
|
|
|
};
|
2021-02-18 16:40:26 +00:00
|
|
|
type ChatSessionRefreshedType = {
|
|
|
|
type: 'chatSessionRefreshed';
|
|
|
|
data: null;
|
|
|
|
};
|
2021-05-28 19:11:19 +00:00
|
|
|
type DeliveryIssueType = {
|
|
|
|
type: 'deliveryIssue';
|
|
|
|
data: DeliveryIssueProps;
|
|
|
|
};
|
2020-03-10 00:43:09 +00:00
|
|
|
type LinkNotificationType = {
|
|
|
|
type: 'linkNotification';
|
|
|
|
data: null;
|
|
|
|
};
|
2019-03-20 17:42:28 +00:00
|
|
|
type MessageType = {
|
|
|
|
type: 'message';
|
2021-06-29 19:58:29 +00:00
|
|
|
data: Omit<MessageProps, 'renderingContext'>;
|
2019-03-20 17:42:28 +00:00
|
|
|
};
|
2019-05-31 22:42:01 +00:00
|
|
|
type UnsupportedMessageType = {
|
|
|
|
type: 'unsupportedMessage';
|
|
|
|
data: UnsupportedMessageProps;
|
|
|
|
};
|
2019-03-20 17:42:28 +00:00
|
|
|
type TimerNotificationType = {
|
|
|
|
type: 'timerNotification';
|
|
|
|
data: TimerNotificationProps;
|
|
|
|
};
|
2021-06-01 20:45:43 +00:00
|
|
|
type UniversalTimerNotificationType = {
|
|
|
|
type: 'universalTimerNotification';
|
|
|
|
data: null;
|
|
|
|
};
|
2021-08-05 23:34:49 +00:00
|
|
|
type ChangeNumberNotificationType = {
|
|
|
|
type: 'changeNumberNotification';
|
|
|
|
data: ChangeNumberNotificationProps;
|
|
|
|
};
|
2019-03-20 17:42:28 +00:00
|
|
|
type SafetyNumberNotificationType = {
|
|
|
|
type: 'safetyNumberNotification';
|
|
|
|
data: SafetyNumberNotificationProps;
|
|
|
|
};
|
|
|
|
type VerificationNotificationType = {
|
|
|
|
type: 'verificationNotification';
|
|
|
|
data: VerificationNotificationProps;
|
|
|
|
};
|
|
|
|
type GroupNotificationType = {
|
|
|
|
type: 'groupNotification';
|
|
|
|
data: GroupNotificationProps;
|
|
|
|
};
|
2020-09-09 02:25:05 +00:00
|
|
|
type GroupV2ChangeType = {
|
|
|
|
type: 'groupV2Change';
|
|
|
|
data: GroupV2ChangeProps;
|
|
|
|
};
|
2020-11-20 17:30:45 +00:00
|
|
|
type GroupV1MigrationType = {
|
|
|
|
type: 'groupV1Migration';
|
|
|
|
data: GroupV1MigrationProps;
|
|
|
|
};
|
2019-03-20 17:42:28 +00:00
|
|
|
type ResetSessionNotificationType = {
|
|
|
|
type: 'resetSessionNotification';
|
|
|
|
data: null;
|
|
|
|
};
|
2020-07-29 23:20:05 +00:00
|
|
|
type ProfileChangeNotificationType = {
|
|
|
|
type: 'profileChange';
|
|
|
|
data: ProfileChangeNotificationPropsType;
|
|
|
|
};
|
|
|
|
|
2019-05-31 22:42:01 +00:00
|
|
|
export type TimelineItemType =
|
2020-06-04 18:16:19 +00:00
|
|
|
| CallHistoryType
|
2021-02-18 16:40:26 +00:00
|
|
|
| ChatSessionRefreshedType
|
2021-05-28 19:11:19 +00:00
|
|
|
| DeliveryIssueType
|
2020-07-29 23:20:05 +00:00
|
|
|
| GroupNotificationType
|
2020-11-20 17:30:45 +00:00
|
|
|
| GroupV1MigrationType
|
2020-09-09 02:25:05 +00:00
|
|
|
| GroupV2ChangeType
|
2020-03-10 00:43:09 +00:00
|
|
|
| LinkNotificationType
|
2019-05-31 22:42:01 +00:00
|
|
|
| MessageType
|
2020-07-29 23:20:05 +00:00
|
|
|
| ProfileChangeNotificationType
|
2020-03-10 00:43:09 +00:00
|
|
|
| ResetSessionNotificationType
|
2019-05-31 22:42:01 +00:00
|
|
|
| SafetyNumberNotificationType
|
2020-03-10 00:43:09 +00:00
|
|
|
| TimerNotificationType
|
2021-06-01 20:45:43 +00:00
|
|
|
| UniversalTimerNotificationType
|
2021-08-05 23:34:49 +00:00
|
|
|
| ChangeNumberNotificationType
|
2020-03-10 00:43:09 +00:00
|
|
|
| UnsupportedMessageType
|
2020-07-29 23:20:05 +00:00
|
|
|
| VerificationNotificationType;
|
2019-03-20 17:42:28 +00:00
|
|
|
|
2019-11-07 21:36:16 +00:00
|
|
|
type PropsLocalType = {
|
2021-08-20 19:36:27 +00:00
|
|
|
containerElementRef: RefObject<HTMLElement>;
|
2019-11-07 21:36:16 +00:00
|
|
|
conversationId: string;
|
2019-05-31 22:42:01 +00:00
|
|
|
item?: TimelineItemType;
|
2019-11-07 21:36:16 +00:00
|
|
|
id: string;
|
|
|
|
isSelected: boolean;
|
|
|
|
selectMessage: (messageId: string, conversationId: string) => unknown;
|
2020-09-09 02:25:05 +00:00
|
|
|
renderContact: SmartContactRendererType;
|
2021-06-01 20:45:43 +00:00
|
|
|
renderUniversalTimerNotification: () => JSX.Element;
|
2019-03-20 17:42:28 +00:00
|
|
|
i18n: LocalizerType;
|
2021-03-24 22:06:12 +00:00
|
|
|
interactionMode: InteractionModeType;
|
2021-11-15 22:53:42 +00:00
|
|
|
theme: ThemeType;
|
2021-09-10 23:59:41 +00:00
|
|
|
previousItem: undefined | TimelineItemType;
|
|
|
|
nextItem: undefined | TimelineItemType;
|
2019-03-20 17:42:28 +00:00
|
|
|
};
|
|
|
|
|
2019-11-07 21:36:16 +00:00
|
|
|
type PropsActionsType = MessageActionsType &
|
2020-12-07 20:43:19 +00:00
|
|
|
CallingNotificationActionsType &
|
2021-07-30 20:30:59 +00:00
|
|
|
DeliveryIssueActionProps &
|
2021-02-18 16:40:26 +00:00
|
|
|
PropsChatSessionRefreshedActionsType &
|
2019-05-31 22:42:01 +00:00
|
|
|
UnsupportedMessageActionsType &
|
|
|
|
SafetyNumberActionsType;
|
2019-03-20 17:42:28 +00:00
|
|
|
|
2020-05-05 19:49:34 +00:00
|
|
|
export type PropsType = PropsLocalType &
|
|
|
|
PropsActionsType &
|
2021-09-10 18:00:31 +00:00
|
|
|
Pick<
|
|
|
|
AllMessageProps,
|
2021-10-12 23:59:08 +00:00
|
|
|
| 'containerWidthBreakpoint'
|
2021-11-17 21:11:46 +00:00
|
|
|
| 'getPreferredBadge'
|
2021-10-12 23:59:08 +00:00
|
|
|
| 'renderEmojiPicker'
|
|
|
|
| 'renderAudioAttachment'
|
|
|
|
| 'renderReactionPicker'
|
2021-09-10 18:00:31 +00:00
|
|
|
>;
|
2019-03-20 17:42:28 +00:00
|
|
|
|
2019-11-07 21:36:16 +00:00
|
|
|
export class TimelineItem extends React.PureComponent<PropsType> {
|
2021-11-12 23:44:20 +00:00
|
|
|
public override render(): JSX.Element | null {
|
2019-11-07 21:36:16 +00:00
|
|
|
const {
|
2021-08-20 19:36:27 +00:00
|
|
|
containerElementRef,
|
2019-11-07 21:36:16 +00:00
|
|
|
conversationId,
|
2021-11-17 21:11:46 +00:00
|
|
|
getPreferredBadge,
|
2019-11-07 21:36:16 +00:00
|
|
|
id,
|
|
|
|
isSelected,
|
|
|
|
item,
|
|
|
|
i18n,
|
2021-02-12 01:50:11 +00:00
|
|
|
theme,
|
2020-12-07 20:43:19 +00:00
|
|
|
messageSizeChanged,
|
2021-09-10 23:59:41 +00:00
|
|
|
nextItem,
|
2020-09-09 02:25:05 +00:00
|
|
|
renderContact,
|
2021-06-01 20:45:43 +00:00
|
|
|
renderUniversalTimerNotification,
|
2020-12-07 20:43:19 +00:00
|
|
|
returnToActiveCall,
|
2019-11-07 21:36:16 +00:00
|
|
|
selectMessage,
|
2020-12-07 20:43:19 +00:00
|
|
|
startCallingLobby,
|
2019-11-07 21:36:16 +00:00
|
|
|
} = this.props;
|
2019-03-20 17:42:28 +00:00
|
|
|
|
|
|
|
if (!item) {
|
2021-09-17 18:27:53 +00:00
|
|
|
log.warn(`TimelineItem: item ${id} provided was falsey`);
|
2019-05-31 22:42:01 +00:00
|
|
|
|
|
|
|
return null;
|
2019-03-20 17:42:28 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
if (item.type === 'message') {
|
2021-02-12 01:50:11 +00:00
|
|
|
return (
|
2021-06-29 19:58:29 +00:00
|
|
|
<Message
|
2021-08-11 16:23:21 +00:00
|
|
|
{...omit(this.props, ['item'])}
|
2021-06-29 19:58:29 +00:00
|
|
|
{...item.data}
|
2021-08-20 19:36:27 +00:00
|
|
|
containerElementRef={containerElementRef}
|
2021-11-17 21:11:46 +00:00
|
|
|
getPreferredBadge={getPreferredBadge}
|
2021-06-29 19:58:29 +00:00
|
|
|
i18n={i18n}
|
|
|
|
theme={theme}
|
|
|
|
renderingContext="conversation/TimelineItem"
|
|
|
|
/>
|
2021-02-12 01:50:11 +00:00
|
|
|
);
|
2019-03-20 17:42:28 +00:00
|
|
|
}
|
2019-11-07 21:36:16 +00:00
|
|
|
|
|
|
|
let notification;
|
|
|
|
|
2019-05-31 22:42:01 +00:00
|
|
|
if (item.type === 'unsupportedMessage') {
|
2019-11-07 21:36:16 +00:00
|
|
|
notification = (
|
|
|
|
<UnsupportedMessage {...this.props} {...item.data} i18n={i18n} />
|
|
|
|
);
|
2020-06-04 18:16:19 +00:00
|
|
|
} else if (item.type === 'callHistory') {
|
2020-12-07 20:43:19 +00:00
|
|
|
notification = (
|
|
|
|
<CallingNotification
|
|
|
|
conversationId={conversationId}
|
|
|
|
i18n={i18n}
|
|
|
|
messageId={id}
|
|
|
|
messageSizeChanged={messageSizeChanged}
|
2021-09-10 23:59:41 +00:00
|
|
|
nextItem={nextItem}
|
2020-12-07 20:43:19 +00:00
|
|
|
returnToActiveCall={returnToActiveCall}
|
|
|
|
startCallingLobby={startCallingLobby}
|
|
|
|
{...item.data}
|
|
|
|
/>
|
|
|
|
);
|
2021-02-18 16:40:26 +00:00
|
|
|
} else if (item.type === 'chatSessionRefreshed') {
|
|
|
|
notification = (
|
|
|
|
<ChatSessionRefreshedNotification
|
|
|
|
{...this.props}
|
|
|
|
{...item.data}
|
|
|
|
i18n={i18n}
|
|
|
|
/>
|
|
|
|
);
|
2021-05-28 19:11:19 +00:00
|
|
|
} else if (item.type === 'deliveryIssue') {
|
2021-07-30 20:30:59 +00:00
|
|
|
notification = (
|
|
|
|
<DeliveryIssueNotification {...item.data} {...this.props} i18n={i18n} />
|
|
|
|
);
|
2020-03-10 00:43:09 +00:00
|
|
|
} else if (item.type === 'linkNotification') {
|
2021-09-07 19:55:03 +00:00
|
|
|
notification = <LinkNotification i18n={i18n} />;
|
2019-11-07 21:36:16 +00:00
|
|
|
} else if (item.type === 'timerNotification') {
|
|
|
|
notification = (
|
|
|
|
<TimerNotification {...this.props} {...item.data} i18n={i18n} />
|
|
|
|
);
|
2021-06-01 20:45:43 +00:00
|
|
|
} else if (item.type === 'universalTimerNotification') {
|
|
|
|
notification = renderUniversalTimerNotification();
|
2021-08-05 23:34:49 +00:00
|
|
|
} else if (item.type === 'changeNumberNotification') {
|
|
|
|
notification = (
|
|
|
|
<ChangeNumberNotification {...this.props} {...item.data} i18n={i18n} />
|
|
|
|
);
|
2019-11-07 21:36:16 +00:00
|
|
|
} else if (item.type === 'safetyNumberNotification') {
|
|
|
|
notification = (
|
2019-03-20 17:42:28 +00:00
|
|
|
<SafetyNumberNotification {...this.props} {...item.data} i18n={i18n} />
|
|
|
|
);
|
2019-11-07 21:36:16 +00:00
|
|
|
} else if (item.type === 'verificationNotification') {
|
|
|
|
notification = (
|
2019-03-20 17:42:28 +00:00
|
|
|
<VerificationNotification {...this.props} {...item.data} i18n={i18n} />
|
|
|
|
);
|
2019-11-07 21:36:16 +00:00
|
|
|
} else if (item.type === 'groupNotification') {
|
|
|
|
notification = (
|
|
|
|
<GroupNotification {...this.props} {...item.data} i18n={i18n} />
|
|
|
|
);
|
2020-09-09 02:25:05 +00:00
|
|
|
} else if (item.type === 'groupV2Change') {
|
|
|
|
notification = (
|
|
|
|
<GroupV2Change
|
|
|
|
renderContact={renderContact}
|
|
|
|
{...item.data}
|
|
|
|
i18n={i18n}
|
|
|
|
/>
|
|
|
|
);
|
2020-11-20 17:30:45 +00:00
|
|
|
} else if (item.type === 'groupV1Migration') {
|
|
|
|
notification = (
|
|
|
|
<GroupV1Migration {...this.props} {...item.data} i18n={i18n} />
|
|
|
|
);
|
2019-11-07 21:36:16 +00:00
|
|
|
} else if (item.type === 'resetSessionNotification') {
|
|
|
|
notification = (
|
2019-03-20 17:42:28 +00:00
|
|
|
<ResetSessionNotification {...this.props} {...item.data} i18n={i18n} />
|
|
|
|
);
|
2020-07-29 23:20:05 +00:00
|
|
|
} else if (item.type === 'profileChange') {
|
|
|
|
notification = (
|
|
|
|
<ProfileChangeNotification {...this.props} {...item.data} i18n={i18n} />
|
|
|
|
);
|
2019-11-07 21:36:16 +00:00
|
|
|
} else {
|
2020-09-09 02:25:05 +00:00
|
|
|
// Weird, yes, but the idea is to get a compile error when we aren't comprehensive
|
|
|
|
// with our if/else checks above, but also log out the type we don't understand if
|
|
|
|
// we encounter it at runtime.
|
|
|
|
const unknownItem: never = item;
|
|
|
|
const asItem = unknownItem as TimelineItemType;
|
|
|
|
throw new Error(`TimelineItem: Unknown type: ${asItem.type}`);
|
2019-03-20 17:42:28 +00:00
|
|
|
}
|
|
|
|
|
2019-11-07 21:36:16 +00:00
|
|
|
return (
|
|
|
|
<InlineNotificationWrapper
|
|
|
|
id={id}
|
|
|
|
conversationId={conversationId}
|
|
|
|
isSelected={isSelected}
|
|
|
|
selectMessage={selectMessage}
|
|
|
|
>
|
|
|
|
{notification}
|
|
|
|
</InlineNotificationWrapper>
|
|
|
|
);
|
2019-03-20 17:42:28 +00:00
|
|
|
}
|
|
|
|
}
|