2022-07-01 00:52:03 +00:00
|
|
|
// Copyright 2022 Signal Messenger, LLC
|
|
|
|
// SPDX-License-Identifier: AGPL-3.0-only
|
|
|
|
|
|
|
|
import React from 'react';
|
|
|
|
import classNames from 'classnames';
|
|
|
|
import type { ConversationType } from '../state/ducks/conversations';
|
|
|
|
import type { LocalizerType } from '../types/Util';
|
2022-08-19 18:36:47 +00:00
|
|
|
import type { ShowToastActionCreatorType } from '../state/ducks/toast';
|
2022-10-14 21:04:26 +00:00
|
|
|
import type { StorySendStateType, StoryViewType } from '../types/Stories';
|
2022-07-01 00:52:03 +00:00
|
|
|
import { Avatar, AvatarSize } from './Avatar';
|
2022-08-25 00:34:17 +00:00
|
|
|
import { HasStories } from '../types/Stories';
|
2022-07-01 00:52:03 +00:00
|
|
|
import { StoryImage } from './StoryImage';
|
|
|
|
import { getAvatarColor } from '../types/Colors';
|
2022-08-24 21:39:10 +00:00
|
|
|
import { MessageTimestamp } from './conversation/MessageTimestamp';
|
2022-07-01 00:52:03 +00:00
|
|
|
|
2022-08-19 18:36:47 +00:00
|
|
|
import { StoriesAddStoryButton } from './StoriesAddStoryButton';
|
2022-10-14 21:04:26 +00:00
|
|
|
import { isFailed, isPending } from '../messages/MessageSendState';
|
2022-08-19 18:36:47 +00:00
|
|
|
|
2022-07-01 00:52:03 +00:00
|
|
|
export type PropsType = {
|
|
|
|
hasMultiple: boolean;
|
|
|
|
i18n: LocalizerType;
|
|
|
|
me: ConversationType;
|
|
|
|
newestStory?: StoryViewType;
|
2022-08-05 23:24:49 +00:00
|
|
|
onAddStory: () => unknown;
|
2022-07-01 00:52:03 +00:00
|
|
|
onClick: () => unknown;
|
|
|
|
queueStoryDownload: (storyId: string) => unknown;
|
2022-08-19 18:36:47 +00:00
|
|
|
showToast: ShowToastActionCreatorType;
|
2022-07-01 00:52:03 +00:00
|
|
|
};
|
|
|
|
|
2022-10-14 21:04:26 +00:00
|
|
|
enum ResolvedSendStatus {
|
|
|
|
Failed,
|
|
|
|
Sending,
|
|
|
|
Sent,
|
|
|
|
}
|
|
|
|
|
|
|
|
function resolveSendStatus(
|
|
|
|
sendStates: Array<StorySendStateType>
|
|
|
|
): ResolvedSendStatus {
|
|
|
|
let anyPending = false;
|
|
|
|
for (const sendState of sendStates) {
|
|
|
|
if (isFailed(sendState.status)) {
|
|
|
|
// Immediately return if any send failed
|
|
|
|
return ResolvedSendStatus.Failed;
|
|
|
|
}
|
|
|
|
if (isPending(sendState.status)) {
|
|
|
|
// Don't return yet in case we have a failure
|
|
|
|
anyPending = true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if (anyPending) {
|
|
|
|
return ResolvedSendStatus.Sending;
|
|
|
|
}
|
|
|
|
return ResolvedSendStatus.Sent;
|
|
|
|
}
|
|
|
|
|
2022-07-01 00:52:03 +00:00
|
|
|
export const MyStoriesButton = ({
|
|
|
|
hasMultiple,
|
|
|
|
i18n,
|
|
|
|
me,
|
|
|
|
newestStory,
|
2022-08-05 23:24:49 +00:00
|
|
|
onAddStory,
|
2022-07-01 00:52:03 +00:00
|
|
|
onClick,
|
|
|
|
queueStoryDownload,
|
2022-08-19 18:36:47 +00:00
|
|
|
showToast,
|
2022-07-01 00:52:03 +00:00
|
|
|
}: PropsType): JSX.Element => {
|
|
|
|
const {
|
|
|
|
acceptedMessageRequest,
|
|
|
|
avatarPath,
|
|
|
|
color,
|
|
|
|
isMe,
|
|
|
|
profileName,
|
|
|
|
sharedGroupNames,
|
|
|
|
title,
|
|
|
|
} = me;
|
|
|
|
|
2022-08-19 18:36:47 +00:00
|
|
|
if (!newestStory) {
|
|
|
|
return (
|
|
|
|
<StoriesAddStoryButton
|
|
|
|
i18n={i18n}
|
2022-08-25 00:34:17 +00:00
|
|
|
moduleClassName="StoryListItem StoryListItem--active-opactiy"
|
2022-08-19 18:36:47 +00:00
|
|
|
onAddStory={onAddStory}
|
|
|
|
showToast={showToast}
|
|
|
|
>
|
2022-08-05 23:24:49 +00:00
|
|
|
<div className="MyStories__avatar-container">
|
|
|
|
<Avatar
|
|
|
|
acceptedMessageRequest={acceptedMessageRequest}
|
|
|
|
avatarPath={avatarPath}
|
|
|
|
badge={undefined}
|
|
|
|
color={getAvatarColor(color)}
|
|
|
|
conversationType="direct"
|
|
|
|
i18n={i18n}
|
|
|
|
isMe={Boolean(isMe)}
|
|
|
|
profileName={profileName}
|
|
|
|
sharedGroupNames={sharedGroupNames}
|
|
|
|
size={AvatarSize.FORTY_EIGHT}
|
|
|
|
title={title}
|
|
|
|
/>
|
|
|
|
<div
|
|
|
|
aria-label={i18n('Stories__add')}
|
|
|
|
className="MyStories__avatar__add-story"
|
|
|
|
/>
|
2022-07-01 00:52:03 +00:00
|
|
|
</div>
|
2022-08-19 18:36:47 +00:00
|
|
|
<div className="StoryListItem__info">
|
|
|
|
<>
|
|
|
|
<div className="StoryListItem__info--title">
|
|
|
|
{i18n('Stories__mine')}
|
|
|
|
</div>
|
|
|
|
<div className="StoryListItem__info--timestamp">
|
|
|
|
{i18n('Stories__add')}
|
|
|
|
</div>
|
|
|
|
</>
|
|
|
|
</div>
|
|
|
|
</StoriesAddStoryButton>
|
|
|
|
);
|
|
|
|
}
|
2022-08-05 23:24:49 +00:00
|
|
|
|
2022-10-14 21:04:26 +00:00
|
|
|
const newStoryResolvedSendStatus = resolveSendStatus(
|
|
|
|
newestStory.sendState ?? []
|
|
|
|
);
|
|
|
|
|
2022-08-19 18:36:47 +00:00
|
|
|
return (
|
|
|
|
<div className="StoryListItem__button">
|
|
|
|
<div className="MyStories__avatar-container">
|
|
|
|
<StoriesAddStoryButton
|
|
|
|
i18n={i18n}
|
2022-08-25 00:34:17 +00:00
|
|
|
moduleClassName="StoryListItem--active-opacity"
|
2022-08-19 18:36:47 +00:00
|
|
|
onAddStory={onAddStory}
|
|
|
|
showToast={showToast}
|
|
|
|
>
|
|
|
|
<Avatar
|
|
|
|
acceptedMessageRequest={acceptedMessageRequest}
|
|
|
|
avatarPath={avatarPath}
|
|
|
|
badge={undefined}
|
|
|
|
color={getAvatarColor(color)}
|
|
|
|
conversationType="direct"
|
|
|
|
i18n={i18n}
|
|
|
|
isMe={Boolean(isMe)}
|
|
|
|
profileName={profileName}
|
|
|
|
sharedGroupNames={sharedGroupNames}
|
|
|
|
size={AvatarSize.FORTY_EIGHT}
|
2022-08-25 00:34:17 +00:00
|
|
|
storyRing={HasStories.Read}
|
2022-08-19 18:36:47 +00:00
|
|
|
title={title}
|
|
|
|
/>
|
2022-08-05 23:24:49 +00:00
|
|
|
<div
|
2022-08-19 18:36:47 +00:00
|
|
|
aria-label={i18n('Stories__add')}
|
|
|
|
className="MyStories__avatar__add-story"
|
|
|
|
/>
|
|
|
|
</StoriesAddStoryButton>
|
|
|
|
</div>
|
|
|
|
<div
|
2022-08-25 00:34:17 +00:00
|
|
|
className="StoryListItem__click-container StoryListItem--active-opacity"
|
2022-08-19 18:36:47 +00:00
|
|
|
onClick={onClick}
|
|
|
|
onKeyDown={ev => {
|
|
|
|
if (ev.key === 'Enter') {
|
|
|
|
onClick();
|
|
|
|
ev.stopPropagation();
|
|
|
|
ev.preventDefault();
|
|
|
|
}
|
|
|
|
}}
|
|
|
|
role="button"
|
|
|
|
tabIndex={0}
|
|
|
|
>
|
|
|
|
<div className="StoryListItem__info">
|
2022-08-25 00:34:17 +00:00
|
|
|
<div className="StoryListItem__info--title StoryListItem__chevron">
|
2022-08-24 21:39:10 +00:00
|
|
|
{i18n('Stories__mine')}
|
|
|
|
</div>
|
2022-10-14 21:04:26 +00:00
|
|
|
{newStoryResolvedSendStatus === ResolvedSendStatus.Sending && (
|
|
|
|
<span className="StoryListItem__info--sending">
|
|
|
|
{i18n('Stories__list--sending')}
|
|
|
|
</span>
|
|
|
|
)}
|
|
|
|
{newStoryResolvedSendStatus === ResolvedSendStatus.Failed && (
|
|
|
|
<span className="StoryListItem__info--send_failed">
|
|
|
|
{i18n('Stories__list--send_failed')}
|
|
|
|
</span>
|
|
|
|
)}
|
|
|
|
{newStoryResolvedSendStatus === ResolvedSendStatus.Sent && (
|
|
|
|
<MessageTimestamp
|
|
|
|
i18n={i18n}
|
|
|
|
isRelativeTime
|
|
|
|
module="StoryListItem__info--timestamp"
|
|
|
|
timestamp={newestStory.timestamp}
|
|
|
|
/>
|
|
|
|
)}
|
2022-08-19 18:36:47 +00:00
|
|
|
</div>
|
|
|
|
<div
|
|
|
|
aria-label={i18n('StoryListItem__label')}
|
|
|
|
className={classNames('StoryListItem__previews', {
|
|
|
|
'StoryListItem__previews--multiple': hasMultiple,
|
|
|
|
})}
|
|
|
|
>
|
|
|
|
{hasMultiple && <div className="StoryListItem__previews--more" />}
|
|
|
|
<StoryImage
|
|
|
|
attachment={newestStory.attachment}
|
|
|
|
firstName={i18n('you')}
|
|
|
|
i18n={i18n}
|
|
|
|
isMe
|
|
|
|
isThumbnail
|
|
|
|
label=""
|
|
|
|
moduleClassName="StoryListItem__previews--image"
|
|
|
|
queueStoryDownload={queueStoryDownload}
|
|
|
|
storyId={newestStory.messageId}
|
|
|
|
/>
|
2022-07-01 00:52:03 +00:00
|
|
|
</div>
|
2022-08-05 23:24:49 +00:00
|
|
|
</div>
|
2022-07-01 00:52:03 +00:00
|
|
|
</div>
|
|
|
|
);
|
|
|
|
};
|