2022-07-25 18:55:44 +00:00
|
|
|
// Copyright 2022 Signal Messenger, LLC
|
|
|
|
// SPDX-License-Identifier: AGPL-3.0-only
|
|
|
|
|
|
|
|
import React from 'react';
|
|
|
|
import formatFileSize from 'filesize';
|
|
|
|
import type { LocalizerType } from '../types/Util';
|
|
|
|
import type { PreferredBadgeSelectorType } from '../state/selectors/badges';
|
|
|
|
import type { StorySendStateType, StoryViewType } from '../types/Stories';
|
|
|
|
import { Avatar, AvatarSize } from './Avatar';
|
|
|
|
import { ContactName } from './conversation/ContactName';
|
|
|
|
import { ContextMenu } from './ContextMenu';
|
|
|
|
import { Intl } from './Intl';
|
|
|
|
import { Modal } from './Modal';
|
|
|
|
import { SendStatus } from '../messages/MessageSendState';
|
|
|
|
import { Theme } from '../util/theme';
|
2022-11-16 20:18:02 +00:00
|
|
|
import { formatDateTimeLong } from '../util/timestamp';
|
|
|
|
import { DurationInSeconds } from '../util/durations';
|
2022-12-14 18:12:04 +00:00
|
|
|
import type { SaveAttachmentActionCreatorType } from '../state/ducks/conversations';
|
2022-11-22 22:33:15 +00:00
|
|
|
import type { AttachmentType } from '../types/Attachment';
|
2022-07-25 18:55:44 +00:00
|
|
|
import { ThemeType } from '../types/Util';
|
|
|
|
import { Time } from './Time';
|
|
|
|
import { groupBy } from '../util/mapUtil';
|
2022-09-09 18:35:00 +00:00
|
|
|
import { format as formatRelativeTime } from '../util/expirationTimer';
|
2022-07-25 18:55:44 +00:00
|
|
|
|
|
|
|
export type PropsType = {
|
|
|
|
getPreferredBadge: PreferredBadgeSelectorType;
|
|
|
|
i18n: LocalizerType;
|
2022-11-22 22:33:15 +00:00
|
|
|
isInternalUser?: boolean;
|
2022-07-25 18:55:44 +00:00
|
|
|
onClose: () => unknown;
|
2022-12-14 18:12:04 +00:00
|
|
|
saveAttachment: SaveAttachmentActionCreatorType;
|
2022-07-25 18:55:44 +00:00
|
|
|
sender: StoryViewType['sender'];
|
|
|
|
sendState?: Array<StorySendStateType>;
|
2022-11-22 22:33:15 +00:00
|
|
|
attachment?: AttachmentType;
|
2022-09-09 18:35:00 +00:00
|
|
|
expirationTimestamp: number | undefined;
|
2022-07-25 18:55:44 +00:00
|
|
|
timestamp: number;
|
|
|
|
};
|
|
|
|
|
|
|
|
const contactSortCollator = new window.Intl.Collator();
|
|
|
|
|
2023-03-28 18:26:46 +00:00
|
|
|
function getSendStatusLabel(
|
|
|
|
sendStatus: SendStatus | undefined,
|
|
|
|
i18n: LocalizerType
|
|
|
|
): string {
|
2022-07-25 18:55:44 +00:00
|
|
|
if (sendStatus === SendStatus.Failed) {
|
2023-03-30 00:03:25 +00:00
|
|
|
return i18n('icu:MessageDetailsHeader--Failed');
|
2022-07-25 18:55:44 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
if (sendStatus === SendStatus.Viewed) {
|
2023-03-30 00:03:25 +00:00
|
|
|
return i18n('icu:MessageDetailsHeader--Viewed');
|
2022-07-25 18:55:44 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
if (sendStatus === SendStatus.Read) {
|
2023-03-30 00:03:25 +00:00
|
|
|
return i18n('icu:MessageDetailsHeader--Read');
|
2022-07-25 18:55:44 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
if (sendStatus === SendStatus.Delivered) {
|
2023-03-30 00:03:25 +00:00
|
|
|
return i18n('icu:MessageDetailsHeader--Delivered');
|
2022-07-25 18:55:44 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
if (sendStatus === SendStatus.Sent) {
|
2023-03-30 00:03:25 +00:00
|
|
|
return i18n('icu:MessageDetailsHeader--Sent');
|
2022-07-25 18:55:44 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
if (sendStatus === SendStatus.Pending) {
|
2023-03-30 00:03:25 +00:00
|
|
|
return i18n('icu:MessageDetailsHeader--Pending');
|
2022-07-25 18:55:44 +00:00
|
|
|
}
|
|
|
|
|
2023-03-30 00:03:25 +00:00
|
|
|
return i18n('icu:from');
|
2022-07-25 18:55:44 +00:00
|
|
|
}
|
|
|
|
|
2022-11-18 00:45:19 +00:00
|
|
|
export function StoryDetailsModal({
|
2022-11-22 22:33:15 +00:00
|
|
|
attachment,
|
2022-07-25 18:55:44 +00:00
|
|
|
getPreferredBadge,
|
|
|
|
i18n,
|
2022-11-22 22:33:15 +00:00
|
|
|
isInternalUser,
|
2022-07-25 18:55:44 +00:00
|
|
|
onClose,
|
2022-11-22 22:33:15 +00:00
|
|
|
saveAttachment,
|
2022-07-25 18:55:44 +00:00
|
|
|
sender,
|
|
|
|
sendState,
|
|
|
|
timestamp,
|
2022-09-09 18:35:00 +00:00
|
|
|
expirationTimestamp,
|
2022-11-18 00:45:19 +00:00
|
|
|
}: PropsType): JSX.Element {
|
2022-09-22 19:03:50 +00:00
|
|
|
// the sender is included in the sendState data
|
|
|
|
// but we don't want to show the sender in the "Sent To" list
|
|
|
|
const actualRecipientsSendState = sendState?.filter(
|
|
|
|
s => s.recipient.id !== sender.id
|
|
|
|
);
|
|
|
|
|
|
|
|
const contactsBySendStatus = actualRecipientsSendState
|
|
|
|
? groupBy(actualRecipientsSendState, contact => contact.status)
|
2022-07-25 18:55:44 +00:00
|
|
|
: undefined;
|
|
|
|
|
|
|
|
let content: JSX.Element;
|
|
|
|
if (contactsBySendStatus) {
|
|
|
|
content = (
|
|
|
|
<div className="StoryDetailsModal__contact-container">
|
|
|
|
{[
|
|
|
|
SendStatus.Failed,
|
|
|
|
SendStatus.Viewed,
|
|
|
|
SendStatus.Read,
|
|
|
|
SendStatus.Delivered,
|
|
|
|
SendStatus.Sent,
|
|
|
|
SendStatus.Pending,
|
|
|
|
].map(sendStatus => {
|
|
|
|
const contacts = contactsBySendStatus.get(sendStatus);
|
|
|
|
|
|
|
|
if (!contacts) {
|
|
|
|
return null;
|
|
|
|
}
|
|
|
|
|
2023-03-28 18:26:46 +00:00
|
|
|
const sendStatusLabel = getSendStatusLabel(sendStatus, i18n);
|
2022-07-25 18:55:44 +00:00
|
|
|
|
|
|
|
const sortedContacts = [...contacts].sort((a, b) =>
|
|
|
|
contactSortCollator.compare(a.recipient.title, b.recipient.title)
|
|
|
|
);
|
|
|
|
|
|
|
|
return (
|
2023-03-28 18:26:46 +00:00
|
|
|
<div
|
|
|
|
key={sendStatusLabel}
|
|
|
|
className="StoryDetailsModal__contact-group"
|
|
|
|
>
|
2022-07-25 18:55:44 +00:00
|
|
|
<div className="StoryDetailsModal__contact-group__header">
|
2023-03-28 18:26:46 +00:00
|
|
|
{sendStatusLabel}
|
2022-07-25 18:55:44 +00:00
|
|
|
</div>
|
|
|
|
{sortedContacts.map(status => {
|
|
|
|
const contact = status.recipient;
|
|
|
|
|
|
|
|
return (
|
|
|
|
<div key={contact.id} className="StoryDetailsModal__contact">
|
|
|
|
<Avatar
|
|
|
|
acceptedMessageRequest={contact.acceptedMessageRequest}
|
|
|
|
avatarPath={contact.avatarPath}
|
|
|
|
badge={getPreferredBadge(contact.badges)}
|
|
|
|
color={contact.color}
|
|
|
|
conversationType="direct"
|
|
|
|
i18n={i18n}
|
|
|
|
isMe={contact.isMe}
|
|
|
|
phoneNumber={contact.phoneNumber}
|
|
|
|
profileName={contact.profileName}
|
|
|
|
sharedGroupNames={contact.sharedGroupNames}
|
2022-12-09 20:37:45 +00:00
|
|
|
size={AvatarSize.THIRTY_TWO}
|
2022-07-25 18:55:44 +00:00
|
|
|
theme={ThemeType.dark}
|
|
|
|
title={contact.title}
|
|
|
|
unblurredAvatarPath={contact.unblurredAvatarPath}
|
|
|
|
/>
|
|
|
|
<div className="StoryDetailsModal__contact__text">
|
|
|
|
<ContactName title={contact.title} />
|
|
|
|
</div>
|
|
|
|
{status.updatedAt && (
|
|
|
|
<Time
|
|
|
|
className="StoryDetailsModal__status-timestamp"
|
|
|
|
timestamp={status.updatedAt}
|
|
|
|
>
|
|
|
|
{formatDateTimeLong(i18n, status.updatedAt)}
|
|
|
|
</Time>
|
|
|
|
)}
|
|
|
|
</div>
|
|
|
|
);
|
|
|
|
})}
|
|
|
|
</div>
|
|
|
|
);
|
|
|
|
})}
|
|
|
|
</div>
|
|
|
|
);
|
|
|
|
} else {
|
|
|
|
content = (
|
|
|
|
<div className="StoryDetailsModal__contact-container">
|
|
|
|
<div className="StoryDetailsModal__contact-group">
|
|
|
|
<div className="StoryDetailsModal__contact-group__header">
|
2023-03-30 00:03:25 +00:00
|
|
|
{i18n('icu:sent')}
|
2022-07-25 18:55:44 +00:00
|
|
|
</div>
|
|
|
|
<div className="StoryDetailsModal__contact">
|
|
|
|
<Avatar
|
|
|
|
acceptedMessageRequest={sender.acceptedMessageRequest}
|
|
|
|
avatarPath={sender.avatarPath}
|
|
|
|
badge={getPreferredBadge(sender.badges)}
|
|
|
|
color={sender.color}
|
|
|
|
conversationType="direct"
|
|
|
|
i18n={i18n}
|
|
|
|
isMe={sender.isMe}
|
|
|
|
profileName={sender.profileName}
|
|
|
|
sharedGroupNames={sender.sharedGroupNames}
|
2022-12-09 20:37:45 +00:00
|
|
|
size={AvatarSize.THIRTY_TWO}
|
2022-07-25 18:55:44 +00:00
|
|
|
theme={ThemeType.dark}
|
|
|
|
title={sender.title}
|
|
|
|
/>
|
|
|
|
<div className="StoryDetailsModal__contact__text">
|
|
|
|
<div className="StoryDetailsModal__contact__name">
|
|
|
|
<ContactName title={sender.title} />
|
|
|
|
</div>
|
|
|
|
</div>
|
|
|
|
<Time
|
|
|
|
className="StoryDetailsModal__status-timestamp"
|
|
|
|
timestamp={timestamp}
|
|
|
|
>
|
|
|
|
{formatDateTimeLong(i18n, timestamp)}
|
|
|
|
</Time>
|
|
|
|
</div>
|
|
|
|
</div>
|
|
|
|
</div>
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
2022-09-09 18:35:00 +00:00
|
|
|
const timeRemaining = expirationTimestamp
|
2022-11-16 20:18:02 +00:00
|
|
|
? DurationInSeconds.fromMillis(expirationTimestamp - Date.now())
|
2022-09-09 18:35:00 +00:00
|
|
|
: undefined;
|
|
|
|
|
2022-11-22 22:33:15 +00:00
|
|
|
const menuOptions = [
|
|
|
|
{
|
|
|
|
icon: 'StoryDetailsModal__copy-icon',
|
2023-03-30 00:03:25 +00:00
|
|
|
label: i18n('icu:StoryDetailsModal__copy-timestamp'),
|
2022-11-22 22:33:15 +00:00
|
|
|
onClick: () => {
|
2022-12-21 18:41:48 +00:00
|
|
|
void window.navigator.clipboard.writeText(String(timestamp));
|
2022-11-22 22:33:15 +00:00
|
|
|
},
|
|
|
|
},
|
|
|
|
];
|
|
|
|
|
|
|
|
if (isInternalUser && attachment) {
|
|
|
|
menuOptions.push({
|
|
|
|
icon: 'StoryDetailsModal__download-icon',
|
2023-03-30 00:03:25 +00:00
|
|
|
label: i18n('icu:StoryDetailsModal__download-attachment'),
|
2022-11-22 22:33:15 +00:00
|
|
|
onClick: () => {
|
|
|
|
saveAttachment(attachment);
|
|
|
|
},
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
2022-07-25 18:55:44 +00:00
|
|
|
return (
|
|
|
|
<Modal
|
2022-09-27 20:24:21 +00:00
|
|
|
modalName="StoryDetailsModal"
|
2022-07-25 18:55:44 +00:00
|
|
|
hasXButton
|
|
|
|
i18n={i18n}
|
|
|
|
moduleClassName="StoryDetailsModal"
|
|
|
|
onClose={onClose}
|
|
|
|
useFocusTrap={false}
|
|
|
|
theme={Theme.Dark}
|
|
|
|
title={
|
|
|
|
<ContextMenu
|
|
|
|
i18n={i18n}
|
2022-11-22 22:33:15 +00:00
|
|
|
menuOptions={menuOptions}
|
2022-07-25 18:55:44 +00:00
|
|
|
moduleClassName="StoryDetailsModal__debugger"
|
|
|
|
popperOptions={{
|
|
|
|
placement: 'bottom',
|
|
|
|
strategy: 'absolute',
|
|
|
|
}}
|
|
|
|
theme={Theme.Dark}
|
|
|
|
>
|
|
|
|
<div>
|
|
|
|
<Intl
|
|
|
|
i18n={i18n}
|
2023-03-30 00:03:25 +00:00
|
|
|
id="icu:StoryDetailsModal__sent-time"
|
2023-03-27 23:37:39 +00:00
|
|
|
components={{
|
|
|
|
time: (
|
|
|
|
<Time
|
|
|
|
className="StoryDetailsModal__debugger__button__text"
|
|
|
|
timestamp={timestamp}
|
|
|
|
>
|
|
|
|
{formatDateTimeLong(i18n, timestamp)}
|
|
|
|
</Time>
|
|
|
|
),
|
|
|
|
}}
|
2022-07-25 18:55:44 +00:00
|
|
|
/>
|
|
|
|
</div>
|
2022-11-22 22:33:15 +00:00
|
|
|
{attachment && (
|
2022-07-25 18:55:44 +00:00
|
|
|
<div>
|
|
|
|
<Intl
|
|
|
|
i18n={i18n}
|
2023-03-30 00:03:25 +00:00
|
|
|
id="icu:StoryDetailsModal__file-size"
|
2023-03-27 23:37:39 +00:00
|
|
|
components={{
|
|
|
|
size: (
|
|
|
|
<span className="StoryDetailsModal__debugger__button__text">
|
|
|
|
{formatFileSize(attachment.size)}
|
|
|
|
</span>
|
|
|
|
),
|
|
|
|
}}
|
2022-07-25 18:55:44 +00:00
|
|
|
/>
|
|
|
|
</div>
|
|
|
|
)}
|
2022-09-09 18:35:00 +00:00
|
|
|
{timeRemaining && timeRemaining > 0 && (
|
|
|
|
<div>
|
|
|
|
<Intl
|
|
|
|
i18n={i18n}
|
2023-03-30 00:03:25 +00:00
|
|
|
id="icu:StoryDetailsModal__disappears-in"
|
2023-03-27 23:37:39 +00:00
|
|
|
components={{
|
|
|
|
countdown: (
|
|
|
|
<span className="StoryDetailsModal__debugger__button__text">
|
|
|
|
{formatRelativeTime(i18n, timeRemaining, {
|
|
|
|
largest: 2,
|
|
|
|
})}
|
|
|
|
</span>
|
|
|
|
),
|
|
|
|
}}
|
2022-09-09 18:35:00 +00:00
|
|
|
/>
|
|
|
|
</div>
|
|
|
|
)}
|
2022-07-25 18:55:44 +00:00
|
|
|
</ContextMenu>
|
|
|
|
}
|
|
|
|
>
|
|
|
|
{content}
|
|
|
|
</Modal>
|
|
|
|
);
|
2022-11-18 00:45:19 +00:00
|
|
|
}
|