2023-01-03 11:55:46 -08:00
|
|
|
// Copyright 2018 Signal Messenger, LLC
|
2021-02-23 14:34:28 -06:00
|
|
|
// SPDX-License-Identifier: AGPL-3.0-only
|
|
|
|
|
2021-10-26 14:15:33 -05:00
|
|
|
import type { FunctionComponent, ReactNode } from 'react';
|
|
|
|
import React, { useCallback } from 'react';
|
2021-02-23 14:34:28 -06:00
|
|
|
import classNames from 'classnames';
|
|
|
|
|
|
|
|
import {
|
|
|
|
BaseConversationListItem,
|
2021-10-14 10:48:48 -05:00
|
|
|
HEADER_NAME_CLASS_NAME,
|
|
|
|
HEADER_CONTACT_NAME_CLASS_NAME,
|
2021-02-23 14:34:28 -06:00
|
|
|
MESSAGE_TEXT_CLASS_NAME,
|
|
|
|
} from './BaseConversationListItem';
|
|
|
|
import { MessageBody } from '../conversation/MessageBody';
|
|
|
|
import { ContactName } from '../conversation/ContactName';
|
|
|
|
import { TypingAnimation } from '../conversation/TypingAnimation';
|
|
|
|
|
2021-11-02 18:01:13 -05:00
|
|
|
import type { LocalizerType, ThemeType } from '../../types/Util';
|
2021-10-26 14:15:33 -05:00
|
|
|
import type { ConversationType } from '../../state/ducks/conversations';
|
2021-11-02 18:01:13 -05:00
|
|
|
import type { BadgeType } from '../../badges/types';
|
2022-11-08 21:38:19 -05:00
|
|
|
import { isSignalConversation } from '../../util/isSignalConversation';
|
2023-04-10 09:31:45 -07:00
|
|
|
import { RenderLocation } from '../conversation/MessageTextRenderer';
|
2021-02-23 14:34:28 -06:00
|
|
|
|
2023-05-09 17:40:19 -07:00
|
|
|
const EMPTY_OBJECT = Object.freeze(Object.create(null));
|
2021-02-23 14:34:28 -06:00
|
|
|
const MESSAGE_STATUS_ICON_CLASS_NAME = `${MESSAGE_TEXT_CLASS_NAME}__status-icon`;
|
|
|
|
|
|
|
|
export const MessageStatuses = [
|
|
|
|
'sending',
|
|
|
|
'sent',
|
|
|
|
'delivered',
|
|
|
|
'read',
|
2021-05-05 17:09:29 -07:00
|
|
|
'paused',
|
2021-02-23 14:34:28 -06:00
|
|
|
'error',
|
|
|
|
'partial-sent',
|
|
|
|
] as const;
|
|
|
|
|
2024-07-23 17:31:40 -07:00
|
|
|
export type MessageStatusType = (typeof MessageStatuses)[number];
|
2021-02-23 14:34:28 -06:00
|
|
|
|
2021-05-07 17:21:10 -05:00
|
|
|
export type PropsData = Pick<
|
|
|
|
ConversationType,
|
|
|
|
| 'acceptedMessageRequest'
|
2024-07-11 12:44:09 -07:00
|
|
|
| 'avatarUrl'
|
2021-11-02 18:01:13 -05:00
|
|
|
| 'badges'
|
2021-05-07 17:21:10 -05:00
|
|
|
| 'color'
|
|
|
|
| 'draftPreview'
|
2023-01-12 19:24:59 -05:00
|
|
|
| 'groupId'
|
2021-05-07 17:21:10 -05:00
|
|
|
| 'id'
|
2024-04-02 09:41:28 -07:00
|
|
|
| 'isBlocked'
|
2021-05-07 17:21:10 -05:00
|
|
|
| 'isMe'
|
2022-01-31 14:01:34 -08:00
|
|
|
// NOTE: Passed for CI, not used for rendering
|
2021-05-07 17:21:10 -05:00
|
|
|
| 'isPinned'
|
|
|
|
| 'isSelected'
|
|
|
|
| 'lastMessage'
|
|
|
|
| 'lastUpdated'
|
|
|
|
| 'markedUnread'
|
|
|
|
| 'muteExpiresAt'
|
|
|
|
| 'phoneNumber'
|
|
|
|
| 'profileName'
|
2023-04-05 13:48:00 -07:00
|
|
|
| 'removalStage'
|
2021-05-07 17:21:10 -05:00
|
|
|
| 'sharedGroupNames'
|
|
|
|
| 'shouldShowDraft'
|
|
|
|
| 'title'
|
|
|
|
| 'type'
|
2023-09-27 17:23:52 -04:00
|
|
|
| 'typingContactIdTimestamps'
|
2024-07-11 12:44:09 -07:00
|
|
|
| 'unblurredAvatarUrl'
|
2021-05-07 17:21:10 -05:00
|
|
|
| 'unreadCount'
|
2023-05-23 17:59:07 -04:00
|
|
|
| 'unreadMentionsCount'
|
2023-08-16 22:54:39 +02:00
|
|
|
| 'serviceId'
|
2021-11-02 18:01:13 -05:00
|
|
|
> & {
|
|
|
|
badge?: BadgeType;
|
|
|
|
};
|
2021-02-23 14:34:28 -06:00
|
|
|
|
|
|
|
type PropsHousekeeping = {
|
2023-04-21 17:23:30 -04:00
|
|
|
buttonAriaLabel?: string;
|
2021-02-23 14:34:28 -06:00
|
|
|
i18n: LocalizerType;
|
|
|
|
onClick: (id: string) => void;
|
2024-08-21 18:48:29 -07:00
|
|
|
onMouseDown: (id: string) => void;
|
2021-11-02 18:01:13 -05:00
|
|
|
theme: ThemeType;
|
2021-02-23 14:34:28 -06:00
|
|
|
};
|
|
|
|
|
|
|
|
export type Props = PropsData & PropsHousekeeping;
|
|
|
|
|
|
|
|
export const ConversationListItem: FunctionComponent<Props> = React.memo(
|
2021-08-11 12:29:07 -07:00
|
|
|
function ConversationListItem({
|
2021-02-23 14:34:28 -06:00
|
|
|
acceptedMessageRequest,
|
2024-07-11 12:44:09 -07:00
|
|
|
avatarUrl,
|
2021-11-02 18:01:13 -05:00
|
|
|
badge,
|
2023-04-21 17:23:30 -04:00
|
|
|
buttonAriaLabel,
|
2021-02-23 14:34:28 -06:00
|
|
|
color,
|
|
|
|
draftPreview,
|
2023-01-12 19:24:59 -05:00
|
|
|
groupId,
|
2021-02-23 14:34:28 -06:00
|
|
|
i18n,
|
|
|
|
id,
|
2024-04-02 09:41:28 -07:00
|
|
|
isBlocked,
|
2021-02-23 14:34:28 -06:00
|
|
|
isMe,
|
|
|
|
isSelected,
|
|
|
|
lastMessage,
|
|
|
|
lastUpdated,
|
|
|
|
markedUnread,
|
|
|
|
muteExpiresAt,
|
|
|
|
onClick,
|
2024-08-21 18:48:29 -07:00
|
|
|
onMouseDown,
|
2021-02-23 14:34:28 -06:00
|
|
|
phoneNumber,
|
|
|
|
profileName,
|
2023-04-05 13:48:00 -07:00
|
|
|
removalStage,
|
2021-04-30 14:40:25 -05:00
|
|
|
sharedGroupNames,
|
2021-02-23 14:34:28 -06:00
|
|
|
shouldShowDraft,
|
2021-11-02 18:01:13 -05:00
|
|
|
theme,
|
2021-02-23 14:34:28 -06:00
|
|
|
title,
|
|
|
|
type,
|
2023-09-27 17:23:52 -04:00
|
|
|
typingContactIdTimestamps,
|
2024-07-11 12:44:09 -07:00
|
|
|
unblurredAvatarUrl,
|
2021-02-23 14:34:28 -06:00
|
|
|
unreadCount,
|
2023-05-23 17:59:07 -04:00
|
|
|
unreadMentionsCount,
|
2023-08-16 22:54:39 +02:00
|
|
|
serviceId,
|
2021-08-11 12:29:07 -07:00
|
|
|
}) {
|
2021-10-14 10:48:48 -05:00
|
|
|
const isMuted = Boolean(muteExpiresAt && Date.now() < muteExpiresAt);
|
2023-09-27 17:23:52 -04:00
|
|
|
const isSomeoneTyping =
|
|
|
|
Object.keys(typingContactIdTimestamps ?? {}).length > 0;
|
2021-10-14 10:48:48 -05:00
|
|
|
const headerName = (
|
|
|
|
<>
|
|
|
|
{isMe ? (
|
2023-03-02 07:57:35 +01:00
|
|
|
<ContactName
|
|
|
|
module={HEADER_CONTACT_NAME_CLASS_NAME}
|
|
|
|
isMe={isMe}
|
2023-03-29 17:03:25 -07:00
|
|
|
title={i18n('icu:noteToSelf')}
|
2023-03-02 07:57:35 +01:00
|
|
|
/>
|
2021-10-14 10:48:48 -05:00
|
|
|
) : (
|
2022-11-08 21:38:19 -05:00
|
|
|
<ContactName
|
|
|
|
module={HEADER_CONTACT_NAME_CLASS_NAME}
|
2023-08-16 22:54:39 +02:00
|
|
|
isSignalConversation={isSignalConversation({ id, serviceId })}
|
2022-11-08 21:38:19 -05:00
|
|
|
title={title}
|
|
|
|
/>
|
2021-10-14 10:48:48 -05:00
|
|
|
)}
|
|
|
|
{isMuted && <div className={`${HEADER_NAME_CLASS_NAME}__mute-icon`} />}
|
|
|
|
</>
|
2021-02-23 14:34:28 -06:00
|
|
|
);
|
|
|
|
|
|
|
|
let messageText: ReactNode = null;
|
|
|
|
let messageStatusIcon: ReactNode = null;
|
|
|
|
|
2024-04-02 09:41:28 -07:00
|
|
|
if (isBlocked) {
|
|
|
|
messageText = (
|
|
|
|
<span className={`${MESSAGE_TEXT_CLASS_NAME}__blocked`}>
|
|
|
|
{i18n('icu:ConversationListItem--blocked')}
|
|
|
|
</span>
|
|
|
|
);
|
|
|
|
} else if (!acceptedMessageRequest && removalStage !== 'justNotification') {
|
2021-09-20 14:20:53 -05:00
|
|
|
messageText = (
|
|
|
|
<span className={`${MESSAGE_TEXT_CLASS_NAME}__message-request`}>
|
2023-03-29 17:03:25 -07:00
|
|
|
{i18n('icu:ConversationListItem--message-request')}
|
2021-09-20 14:20:53 -05:00
|
|
|
</span>
|
2021-02-23 14:34:28 -06:00
|
|
|
);
|
2023-09-18 14:17:26 -07:00
|
|
|
} else if (isSomeoneTyping) {
|
2021-09-20 14:20:53 -05:00
|
|
|
messageText = <TypingAnimation i18n={i18n} />;
|
|
|
|
} else if (shouldShowDraft && draftPreview) {
|
2021-02-23 14:34:28 -06:00
|
|
|
messageText = (
|
|
|
|
<>
|
2021-09-20 14:20:53 -05:00
|
|
|
<span className={`${MESSAGE_TEXT_CLASS_NAME}__draft-prefix`}>
|
2023-03-29 17:03:25 -07:00
|
|
|
{i18n('icu:ConversationListItem--draft-prefix')}
|
2021-09-20 14:20:53 -05:00
|
|
|
</span>
|
|
|
|
<MessageBody
|
2023-04-10 09:31:45 -07:00
|
|
|
bodyRanges={draftPreview.bodyRanges}
|
2021-09-20 14:20:53 -05:00
|
|
|
disableJumbomoji
|
|
|
|
disableLinks
|
|
|
|
i18n={i18n}
|
2023-05-09 17:40:19 -07:00
|
|
|
isSpoilerExpanded={{}}
|
2023-04-10 09:31:45 -07:00
|
|
|
prefix={draftPreview.prefix}
|
|
|
|
renderLocation={RenderLocation.ConversationList}
|
|
|
|
text={draftPreview.text}
|
2021-09-20 14:20:53 -05:00
|
|
|
/>
|
2021-02-23 14:34:28 -06:00
|
|
|
</>
|
|
|
|
);
|
2021-09-20 14:20:53 -05:00
|
|
|
} else if (lastMessage?.deletedForEveryone) {
|
|
|
|
messageText = (
|
|
|
|
<span className={`${MESSAGE_TEXT_CLASS_NAME}__deleted-for-everyone`}>
|
2023-03-29 17:03:25 -07:00
|
|
|
{i18n('icu:message--deletedForEveryone')}
|
2021-09-20 14:20:53 -05:00
|
|
|
</span>
|
|
|
|
);
|
|
|
|
} else if (lastMessage) {
|
|
|
|
messageText = (
|
|
|
|
<MessageBody
|
2022-08-25 10:16:37 -06:00
|
|
|
author={type === 'group' ? lastMessage.author : undefined}
|
2023-04-10 09:31:45 -07:00
|
|
|
bodyRanges={lastMessage.bodyRanges}
|
2021-09-20 14:20:53 -05:00
|
|
|
disableJumbomoji
|
|
|
|
disableLinks
|
|
|
|
i18n={i18n}
|
2023-05-09 17:40:19 -07:00
|
|
|
isSpoilerExpanded={EMPTY_OBJECT}
|
2023-04-10 09:31:45 -07:00
|
|
|
prefix={lastMessage.prefix}
|
|
|
|
renderLocation={RenderLocation.ConversationList}
|
|
|
|
text={lastMessage.text}
|
2021-09-20 14:20:53 -05:00
|
|
|
/>
|
|
|
|
);
|
|
|
|
if (lastMessage.status) {
|
2021-02-23 14:34:28 -06:00
|
|
|
messageStatusIcon = (
|
|
|
|
<div
|
|
|
|
className={classNames(
|
|
|
|
MESSAGE_STATUS_ICON_CLASS_NAME,
|
|
|
|
`${MESSAGE_STATUS_ICON_CLASS_NAME}--${lastMessage.status}`
|
|
|
|
)}
|
|
|
|
/>
|
|
|
|
);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
const onClickItem = useCallback(() => onClick(id), [onClick, id]);
|
2024-08-21 18:48:29 -07:00
|
|
|
const onMouseDownItem = useCallback(
|
|
|
|
() => onMouseDown(id),
|
|
|
|
[onMouseDown, id]
|
|
|
|
);
|
2021-02-23 14:34:28 -06:00
|
|
|
|
|
|
|
return (
|
|
|
|
<BaseConversationListItem
|
2021-04-30 14:40:25 -05:00
|
|
|
acceptedMessageRequest={acceptedMessageRequest}
|
2024-07-11 12:44:09 -07:00
|
|
|
avatarUrl={avatarUrl}
|
2021-11-02 18:01:13 -05:00
|
|
|
badge={badge}
|
2023-04-21 17:23:30 -04:00
|
|
|
buttonAriaLabel={buttonAriaLabel}
|
2021-02-23 14:34:28 -06:00
|
|
|
color={color}
|
|
|
|
conversationType={type}
|
2023-01-12 19:24:59 -05:00
|
|
|
groupId={groupId}
|
2021-02-23 14:34:28 -06:00
|
|
|
headerDate={lastUpdated}
|
|
|
|
headerName={headerName}
|
|
|
|
i18n={i18n}
|
|
|
|
id={id}
|
|
|
|
isMe={isMe}
|
|
|
|
isSelected={Boolean(isSelected)}
|
|
|
|
markedUnread={markedUnread}
|
|
|
|
messageStatusIcon={messageStatusIcon}
|
|
|
|
messageText={messageText}
|
2021-10-12 18:59:08 -05:00
|
|
|
messageTextIsAlwaysFullSize
|
2021-02-23 14:34:28 -06:00
|
|
|
onClick={onClickItem}
|
2024-08-21 18:48:29 -07:00
|
|
|
onMouseDown={onMouseDownItem}
|
2021-02-23 14:34:28 -06:00
|
|
|
phoneNumber={phoneNumber}
|
|
|
|
profileName={profileName}
|
2021-04-30 14:40:25 -05:00
|
|
|
sharedGroupNames={sharedGroupNames}
|
2021-11-02 18:01:13 -05:00
|
|
|
theme={theme}
|
2021-02-23 14:34:28 -06:00
|
|
|
title={title}
|
|
|
|
unreadCount={unreadCount}
|
2023-05-23 17:59:07 -04:00
|
|
|
unreadMentionsCount={unreadMentionsCount}
|
2024-07-11 12:44:09 -07:00
|
|
|
unblurredAvatarUrl={unblurredAvatarUrl}
|
2023-08-16 22:54:39 +02:00
|
|
|
serviceId={serviceId}
|
2021-02-23 14:34:28 -06:00
|
|
|
/>
|
|
|
|
);
|
|
|
|
}
|
|
|
|
);
|