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-11-22 22:33:15 +00:00
|
|
|
import type { saveAttachment } from '../util/saveAttachment';
|
|
|
|
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-11-22 22:33:15 +00:00
|
|
|
saveAttachment: typeof saveAttachment;
|
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();
|
|
|
|
|
|
|
|
function getI18nKey(sendStatus: SendStatus | undefined): string {
|
|
|
|
if (sendStatus === SendStatus.Failed) {
|
|
|
|
return 'MessageDetailsHeader--Failed';
|
|
|
|
}
|
|
|
|
|
|
|
|
if (sendStatus === SendStatus.Viewed) {
|
|
|
|
return 'MessageDetailsHeader--Viewed';
|
|
|
|
}
|
|
|
|
|
|
|
|
if (sendStatus === SendStatus.Read) {
|
|
|
|
return 'MessageDetailsHeader--Read';
|
|
|
|
}
|
|
|
|
|
|
|
|
if (sendStatus === SendStatus.Delivered) {
|
|
|
|
return 'MessageDetailsHeader--Delivered';
|
|
|
|
}
|
|
|
|
|
|
|
|
if (sendStatus === SendStatus.Sent) {
|
|
|
|
return 'MessageDetailsHeader--Sent';
|
|
|
|
}
|
|
|
|
|
|
|
|
if (sendStatus === SendStatus.Pending) {
|
|
|
|
return 'MessageDetailsHeader--Pending';
|
|
|
|
}
|
|
|
|
|
|
|
|
return 'from';
|
|
|
|
}
|
|
|
|
|
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;
|
|
|
|
}
|
|
|
|
|
|
|
|
const i18nKey = getI18nKey(sendStatus);
|
|
|
|
|
|
|
|
const sortedContacts = [...contacts].sort((a, b) =>
|
|
|
|
contactSortCollator.compare(a.recipient.title, b.recipient.title)
|
|
|
|
);
|
|
|
|
|
|
|
|
return (
|
|
|
|
<div key={i18nKey} className="StoryDetailsModal__contact-group">
|
|
|
|
<div className="StoryDetailsModal__contact-group__header">
|
|
|
|
{i18n(i18nKey)}
|
|
|
|
</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">
|
|
|
|
{i18n('sent')}
|
|
|
|
</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',
|
|
|
|
label: i18n('StoryDetailsModal__copy-timestamp'),
|
|
|
|
onClick: () => {
|
|
|
|
window.navigator.clipboard.writeText(String(timestamp));
|
|
|
|
},
|
|
|
|
},
|
|
|
|
];
|
|
|
|
|
|
|
|
if (isInternalUser && attachment) {
|
|
|
|
menuOptions.push({
|
|
|
|
icon: 'StoryDetailsModal__download-icon',
|
|
|
|
label: i18n('StoryDetailsModal__download-attachment'),
|
|
|
|
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}
|
|
|
|
id="StoryDetailsModal__sent-time"
|
|
|
|
components={[
|
|
|
|
<Time
|
|
|
|
className="StoryDetailsModal__debugger__button__text"
|
|
|
|
timestamp={timestamp}
|
|
|
|
>
|
|
|
|
{formatDateTimeLong(i18n, timestamp)}
|
|
|
|
</Time>,
|
|
|
|
]}
|
|
|
|
/>
|
|
|
|
</div>
|
2022-11-22 22:33:15 +00:00
|
|
|
{attachment && (
|
2022-07-25 18:55:44 +00:00
|
|
|
<div>
|
|
|
|
<Intl
|
|
|
|
i18n={i18n}
|
|
|
|
id="StoryDetailsModal__file-size"
|
|
|
|
components={[
|
|
|
|
<span className="StoryDetailsModal__debugger__button__text">
|
2022-11-22 22:33:15 +00:00
|
|
|
{formatFileSize(attachment.size)}
|
2022-07-25 18:55:44 +00:00
|
|
|
</span>,
|
|
|
|
]}
|
|
|
|
/>
|
|
|
|
</div>
|
|
|
|
)}
|
2022-09-09 18:35:00 +00:00
|
|
|
{timeRemaining && timeRemaining > 0 && (
|
|
|
|
<div>
|
|
|
|
<Intl
|
|
|
|
i18n={i18n}
|
|
|
|
id="StoryDetailsModal__disappears-in"
|
|
|
|
components={[
|
|
|
|
<span className="StoryDetailsModal__debugger__button__text">
|
2022-11-16 20:18:02 +00:00
|
|
|
{formatRelativeTime(i18n, timeRemaining, {
|
2022-09-09 18:35:00 +00:00
|
|
|
largest: 2,
|
|
|
|
})}
|
|
|
|
</span>,
|
|
|
|
]}
|
|
|
|
/>
|
|
|
|
</div>
|
|
|
|
)}
|
2022-07-25 18:55:44 +00:00
|
|
|
</ContextMenu>
|
|
|
|
}
|
|
|
|
>
|
|
|
|
{content}
|
|
|
|
</Modal>
|
|
|
|
);
|
2022-11-18 00:45:19 +00:00
|
|
|
}
|