signal-desktop/ts/components/SendStoryModal.tsx

1019 lines
33 KiB
TypeScript
Raw Normal View History

2022-08-02 19:31:55 +00:00
// Copyright 2022 Signal Messenger, LLC
// SPDX-License-Identifier: AGPL-3.0-only
2022-08-10 18:37:19 +00:00
import React, { useEffect, useMemo, useState } from 'react';
import { noop, sortBy } from 'lodash';
2022-08-10 18:37:19 +00:00
import { SearchInput } from './SearchInput';
import { filterAndSortConversationsByRecent } from '../util/filterAndSortConversations';
2022-08-02 19:31:55 +00:00
import type { ConversationType } from '../state/ducks/conversations';
import type { ConversationWithStoriesType } from '../state/selectors/conversations';
2022-08-02 19:31:55 +00:00
import type { LocalizerType } from '../types/Util';
import { ThemeType } from '../types/Util';
2022-08-10 18:37:19 +00:00
import type { PreferredBadgeSelectorType } from '../state/selectors/badges';
2022-08-23 17:24:55 +00:00
import type { PropsType as StoriesSettingsModalPropsType } from './StoriesSettingsModal';
2022-10-27 01:47:45 +00:00
import {
getI18nForMyStory,
2022-10-27 01:47:45 +00:00
getListViewers,
DistributionListSettingsModal,
EditDistributionListModal,
EditMyStoryPrivacy,
2022-10-27 01:47:45 +00:00
Page as StoriesSettingsPage,
} from './StoriesSettingsModal';
2022-08-30 19:13:32 +00:00
import type { StoryDistributionListWithMembersDataType } from '../types/Stories';
import type { StoryDistributionIdString } from '../types/StoryDistributionId';
import type { ServiceIdString } from '../types/ServiceId';
import { Alert } from './Alert';
2022-08-02 19:31:55 +00:00
import { Avatar, AvatarSize } from './Avatar';
import { Button, ButtonSize, ButtonVariant } from './Button';
2022-08-02 19:31:55 +00:00
import { Checkbox } from './Checkbox';
2022-08-30 19:13:32 +00:00
import { ConfirmationDialog } from './ConfirmationDialog';
2022-08-10 18:37:19 +00:00
import { ContextMenu } from './ContextMenu';
2022-10-27 01:47:45 +00:00
import { MY_STORY_ID, getStoryDistributionListName } from '../types/Stories';
import type { RenderModalPage, ModalPropsType } from './Modal';
import { PagedModal, ModalPage } from './Modal';
2022-08-02 19:31:55 +00:00
import { StoryDistributionListName } from './StoryDistributionListName';
import { isNotNil } from '../util/isNotNil';
import { StoryImage } from './StoryImage';
import type { AttachmentType } from '../types/Attachment';
import { useConfirmDiscard } from '../hooks/useConfirmDiscard';
import { getStoryBackground } from '../util/getStoryBackground';
import { makeObjectUrl, revokeObjectUrl } from '../types/VisualAttachment';
2023-04-20 17:03:43 +00:00
import { UserText } from './UserText';
import { Theme } from '../util/theme';
2022-08-02 19:31:55 +00:00
export type PropsType = {
draftAttachment: AttachmentType;
2022-08-10 18:37:19 +00:00
candidateConversations: Array<ConversationType>;
2022-08-30 19:13:32 +00:00
distributionLists: Array<StoryDistributionListWithMembersDataType>;
2022-08-10 18:37:19 +00:00
getPreferredBadge: PreferredBadgeSelectorType;
groupConversations: Array<ConversationType>;
groupStories: Array<ConversationWithStoriesType>;
2022-08-23 17:24:55 +00:00
hasFirstStoryPostExperience: boolean;
ourConversationId: string | undefined;
2022-08-02 19:31:55 +00:00
i18n: LocalizerType;
me: ConversationType;
onClose: () => unknown;
onDeleteList: (listId: StoryDistributionIdString) => unknown;
2022-08-10 18:37:19 +00:00
onDistributionListCreated: (
name: string,
2023-08-16 20:54:39 +00:00
viewerServiceIds: Array<ServiceIdString>
) => Promise<StoryDistributionIdString>;
onSelectedStoryList: (options: {
conversationId: string;
distributionId: StoryDistributionIdString | undefined;
serviceIds: Array<ServiceIdString>;
}) => unknown;
2022-08-10 18:37:19 +00:00
onSend: (
listIds: Array<StoryDistributionIdString>,
2022-08-10 18:37:19 +00:00
conversationIds: Array<string>
) => unknown;
2022-08-02 19:31:55 +00:00
signalConnections: Array<ConversationType>;
theme: ThemeType;
toggleGroupsForStorySend: (cids: Array<string>) => Promise<void>;
mostRecentActiveStoryTimestampByGroupOrDistributionList: Record<
string,
number
>;
2023-02-24 23:18:57 +00:00
onMediaPlaybackStart: () => void;
2022-08-23 17:24:55 +00:00
} & Pick<
StoriesSettingsModalPropsType,
| 'onHideMyStoriesFrom'
| 'onRemoveMembers'
2022-08-30 19:13:32 +00:00
| 'onRepliesNReactionsChanged'
2022-08-23 17:24:55 +00:00
| 'onViewersUpdated'
| 'setMyStoriesToAllSignalConnections'
| 'toggleSignalConnectionsModal'
>;
2022-08-10 18:37:19 +00:00
enum SendStoryPage {
ChooseGroups = 'ChooseGroups',
2022-08-30 19:13:32 +00:00
EditingDistributionList = 'EditingDistributionList',
2022-08-23 17:24:55 +00:00
SendStory = 'SendStory',
SetMyStoriesPrivacy = 'SetMyStoriesPrivacy',
2022-08-10 18:37:19 +00:00
}
const Page = {
...SendStoryPage,
...StoriesSettingsPage,
2022-08-02 19:31:55 +00:00
};
2022-08-10 18:37:19 +00:00
type PageType = SendStoryPage | StoriesSettingsPage;
function getListMemberServiceIds(
2022-08-30 19:13:32 +00:00
list: StoryDistributionListWithMembersDataType,
signalConnections: Array<ConversationType>
): Array<ServiceIdString> {
const memberServiceIds = list.members
2023-08-16 20:54:39 +00:00
.map(({ serviceId }) => serviceId)
.filter(isNotNil);
2022-08-30 19:13:32 +00:00
if (list.id === MY_STORY_ID && list.isBlockList) {
2023-08-16 20:54:39 +00:00
const excludeServiceIds = new Set<ServiceIdString>(memberServiceIds);
return signalConnections
2023-08-16 20:54:39 +00:00
.map(conversation => conversation.serviceId)
.filter(isNotNil)
2023-08-16 20:54:39 +00:00
.filter(serviceId => !excludeServiceIds.has(serviceId));
}
return memberServiceIds;
}
2022-11-18 00:45:19 +00:00
export function SendStoryModal({
draftAttachment,
2022-08-10 18:37:19 +00:00
candidateConversations,
2022-08-02 19:31:55 +00:00
distributionLists,
2022-08-10 18:37:19 +00:00
getPreferredBadge,
groupConversations,
groupStories,
2022-08-23 17:24:55 +00:00
hasFirstStoryPostExperience,
2022-08-02 19:31:55 +00:00
i18n,
me,
ourConversationId,
2022-08-02 19:31:55 +00:00
onClose,
2022-08-30 19:13:32 +00:00
onDeleteList,
2022-08-10 18:37:19 +00:00
onDistributionListCreated,
2022-08-23 17:24:55 +00:00
onHideMyStoriesFrom,
onRemoveMembers,
2022-08-30 19:13:32 +00:00
onRepliesNReactionsChanged,
onSelectedStoryList,
2022-08-30 19:13:32 +00:00
onSend,
2022-08-23 17:24:55 +00:00
onViewersUpdated,
setMyStoriesToAllSignalConnections,
2022-08-02 19:31:55 +00:00
signalConnections,
theme,
2022-08-30 19:13:32 +00:00
toggleGroupsForStorySend,
mostRecentActiveStoryTimestampByGroupOrDistributionList,
2022-08-23 17:24:55 +00:00
toggleSignalConnectionsModal,
2023-02-24 23:18:57 +00:00
onMediaPlaybackStart,
2022-11-18 00:45:19 +00:00
}: PropsType): JSX.Element {
2022-08-10 18:37:19 +00:00
const [page, setPage] = useState<PageType>(Page.SendStory);
const [confirmDiscardModal, confirmDiscardIf] = useConfirmDiscard(i18n);
const [selectedListIds, setSelectedListIds] = useState<
Set<StoryDistributionIdString>
>(new Set());
2022-08-10 18:37:19 +00:00
const [selectedGroupIds, setSelectedGroupIds] = useState<Set<string>>(
new Set()
);
const selectedStoryNames = useMemo(
2022-08-02 19:31:55 +00:00
() =>
distributionLists
.filter(list => selectedListIds.has(list.id))
2022-08-10 18:37:19 +00:00
.map(list => list.name)
.concat(
groupStories
.filter(group => selectedGroupIds.has(group.id))
.map(group => group.title)
),
[distributionLists, groupStories, selectedGroupIds, selectedListIds]
2022-08-02 19:31:55 +00:00
);
2022-08-10 18:37:19 +00:00
const [searchTerm, setSearchTerm] = useState('');
const [filteredConversations, setFilteredConversations] = useState(
filterAndSortConversationsByRecent(
groupConversations,
searchTerm,
undefined
)
);
const normalizedSearchTerm = searchTerm.trim();
useEffect(() => {
const timeout = setTimeout(() => {
setFilteredConversations(
filterAndSortConversationsByRecent(
groupConversations,
normalizedSearchTerm,
undefined
)
);
}, 200);
return () => {
clearTimeout(timeout);
};
}, [groupConversations, normalizedSearchTerm, setFilteredConversations]);
const [chosenGroupIds, setChosenGroupIds] = useState<Set<string>>(
new Set<string>()
);
const chosenGroupNames = useMemo(
() =>
filteredConversations
.filter(group => chosenGroupIds.has(group.id))
.map(group => group.title),
[filteredConversations, chosenGroupIds]
);
const [selectedContacts, setSelectedContacts] = useState<
Array<ConversationType>
>([]);
const [hasAnnouncementsOnlyAlert, setHasAnnouncementsOnlyAlert] =
useState(false);
2022-08-30 19:13:32 +00:00
const [confirmRemoveGroupId, setConfirmRemoveGroupId] = useState<
string | undefined
>();
const [confirmDeleteList, setConfirmDeleteList] = useState<
{ id: StoryDistributionIdString; name: string } | undefined
2022-08-30 19:13:32 +00:00
>();
const [listIdToEdit, setListIdToEdit] = useState<string | undefined>();
useEffect(() => {
if (listIdToEdit) {
setPage(Page.EditingDistributionList);
} else {
setPage(Page.SendStory);
}
}, [listIdToEdit]);
const listToEdit = useMemo(() => {
if (!listIdToEdit) {
return;
}
return distributionLists.find(list => list.id === listIdToEdit);
}, [distributionLists, listIdToEdit]);
2023-08-16 20:54:39 +00:00
// myStoriesPrivacy, myStoriesPrivacyServiceIds, and myStories are only used
2022-08-30 19:13:32 +00:00
// during the first time posting to My Stories experience where we have
// to select the privacy settings.
const ogMyStories = useMemo(
() => distributionLists.find(list => list.id === MY_STORY_ID),
2022-08-30 19:13:32 +00:00
[distributionLists]
2022-08-23 17:24:55 +00:00
);
const initialMyStories: StoryDistributionListWithMembersDataType = useMemo(
2022-08-30 19:13:32 +00:00
() => ({
2022-08-23 17:24:55 +00:00
allowsReplies: true,
id: MY_STORY_ID,
2023-03-30 00:03:25 +00:00
name: i18n('icu:Stories__mine'),
2022-08-30 19:13:32 +00:00
isBlockList: ogMyStories?.isBlockList ?? true,
members: ogMyStories?.members || [],
}),
[i18n, ogMyStories]
);
const [stagedMyStories, setStagedMyStories] =
useState<StoryDistributionListWithMembersDataType>(initialMyStories);
let selectedNames: string | undefined;
if (page === Page.ChooseGroups) {
selectedNames = chosenGroupNames.join(', ');
} else {
selectedNames = selectedStoryNames
.map(listName => getStoryDistributionListName(i18n, undefined, listName))
.join(', ');
}
2022-08-30 19:13:32 +00:00
const [objectUrl, setObjectUrl] = useState<string | undefined>(undefined);
useEffect(() => {
let url: undefined | string;
if (draftAttachment.url) {
setObjectUrl(draftAttachment.url);
} else if (draftAttachment.data) {
url = makeObjectUrl(draftAttachment.data, draftAttachment.contentType);
setObjectUrl(url);
}
return () => {
if (url) {
revokeObjectUrl(url);
}
};
}, [setObjectUrl, draftAttachment]);
const modalCommonProps: Pick<ModalPropsType, 'hasXButton' | 'i18n'> = {
hasXButton: true,
i18n,
};
2022-08-30 19:13:32 +00:00
let modal: RenderModalPage;
if (page === Page.SetMyStoriesPrivacy) {
const footer = (
<>
<div />
<div>
<Button
onClick={() => setPage(Page.SendStory)}
variant={ButtonVariant.Secondary}
>
2023-03-30 00:03:25 +00:00
{i18n('icu:cancel')}
</Button>
<Button
onClick={() => {
2023-08-16 20:54:39 +00:00
const serviceIds = stagedMyStories.members
.map(convo => convo.serviceId)
.filter(isNotNil);
if (stagedMyStories.isBlockList) {
if (stagedMyStories.members.length) {
2023-08-16 20:54:39 +00:00
onHideMyStoriesFrom(serviceIds);
} else {
setMyStoriesToAllSignalConnections();
}
} else {
2023-08-16 20:54:39 +00:00
onViewersUpdated(MY_STORY_ID, serviceIds);
}
2022-08-30 19:13:32 +00:00
setSelectedContacts([]);
setPage(Page.SendStory);
}}
variant={ButtonVariant.Primary}
>
2023-03-30 00:03:25 +00:00
{i18n('icu:save')}
</Button>
</div>
</>
);
modal = handleClose => (
<ModalPage
modalName="SendStoryModal__my-stories-privacy"
2023-03-30 00:03:25 +00:00
title={i18n('icu:SendStoryModal__my-stories-privacy')}
modalFooter={footer}
onClose={handleClose}
{...modalCommonProps}
>
<EditMyStoryPrivacy
hasDisclaimerAbove
i18n={i18n}
kind="privacy"
myStories={stagedMyStories}
signalConnectionsCount={signalConnections.length}
onClickExclude={() => {
let nextSelectedContacts = stagedMyStories.members;
if (!stagedMyStories.isBlockList) {
setStagedMyStories(myStories => ({
...myStories,
isBlockList: true,
members: [],
}));
nextSelectedContacts = [];
}
setSelectedContacts(nextSelectedContacts);
setPage(Page.HideStoryFrom);
}}
onClickOnlyShareWith={() => {
if (!stagedMyStories.isBlockList) {
setSelectedContacts(stagedMyStories.members);
} else {
setStagedMyStories(myStories => ({
...myStories,
isBlockList: false,
members: [],
}));
}
setPage(Page.AddViewer);
}}
setSelectedContacts={setSelectedContacts}
setMyStoriesToAllSignalConnections={() => {
2022-08-30 19:13:32 +00:00
setStagedMyStories(myStories => ({
...myStories,
isBlockList: true,
2022-08-30 19:13:32 +00:00
members: [],
}));
setSelectedContacts([]);
}}
toggleSignalConnectionsModal={toggleSignalConnectionsModal}
/>
</ModalPage>
2022-08-23 17:24:55 +00:00
);
2022-08-30 19:13:32 +00:00
} else if (page === Page.EditingDistributionList && listToEdit) {
modal = handleClose => (
<DistributionListSettingsModal
2022-08-30 19:13:32 +00:00
getPreferredBadge={getPreferredBadge}
i18n={i18n}
listToEdit={listToEdit}
signalConnectionsCount={signalConnections.length}
onRemoveMembers={onRemoveMembers}
2022-08-30 19:13:32 +00:00
onRepliesNReactionsChanged={onRepliesNReactionsChanged}
setConfirmDeleteList={setConfirmDeleteList}
2022-08-30 19:13:32 +00:00
setMyStoriesToAllSignalConnections={setMyStoriesToAllSignalConnections}
setPage={setPage}
setSelectedContacts={setSelectedContacts}
toggleSignalConnectionsModal={toggleSignalConnectionsModal}
theme={theme}
onBackButtonClick={() =>
confirmDiscardIf(selectedContacts.length > 0, () =>
setListIdToEdit(undefined)
)
}
onClose={handleClose}
2022-08-30 19:13:32 +00:00
/>
);
2022-08-23 17:24:55 +00:00
} else if (
page === Page.ChooseViewers ||
page === Page.NameStory ||
page === Page.AddViewer ||
page === Page.HideStoryFrom
) {
modal = handleClose => (
<EditDistributionListModal
2022-08-10 18:37:19 +00:00
candidateConversations={candidateConversations}
getPreferredBadge={getPreferredBadge}
i18n={i18n}
2023-08-16 20:54:39 +00:00
onCreateList={async (name, serviceIds) => {
const newDistributionListId = await onDistributionListCreated(
name,
2023-08-16 20:54:39 +00:00
serviceIds
);
setSelectedContacts([]);
setSelectedListIds(
listIds => new Set([...listIds, newDistributionListId])
);
2022-08-10 18:37:19 +00:00
setPage(Page.SendStory);
}}
2023-08-16 20:54:39 +00:00
onViewersUpdated={serviceIds => {
2022-08-30 19:13:32 +00:00
if (listIdToEdit && page === Page.AddViewer) {
2023-08-16 20:54:39 +00:00
onViewersUpdated(listIdToEdit, serviceIds);
2022-08-30 19:13:32 +00:00
setPage(Page.EditingDistributionList);
} else if (page === Page.ChooseViewers) {
2022-08-10 18:37:19 +00:00
setPage(Page.NameStory);
2022-08-30 19:13:32 +00:00
} else if (listIdToEdit && page === Page.HideStoryFrom) {
2023-08-16 20:54:39 +00:00
onHideMyStoriesFrom(serviceIds);
2022-08-30 19:13:32 +00:00
setPage(Page.SendStory);
2022-08-23 17:24:55 +00:00
} else if (page === Page.HideStoryFrom || page === Page.AddViewer) {
2023-08-16 20:54:39 +00:00
const serviceIdSet = new Set(serviceIds);
const members = candidateConversations.filter(convo =>
2023-08-16 20:54:39 +00:00
convo.serviceId ? serviceIdSet.has(convo.serviceId) : false
);
setStagedMyStories(myStories => ({
...myStories,
members,
}));
2022-08-23 17:24:55 +00:00
setPage(Page.SetMyStoriesPrivacy);
2022-08-10 18:37:19 +00:00
} else {
setPage(Page.SendStory);
}
}}
page={page}
onClose={handleClose}
onBackButtonClick={() =>
confirmDiscardIf(selectedContacts.length > 0, () => {
if (listIdToEdit) {
if (
page === Page.AddViewer ||
page === Page.HideStoryFrom ||
page === Page.ChooseViewers
) {
setPage(Page.EditingDistributionList);
} else {
setListIdToEdit(undefined);
}
} else if (page === Page.HideStoryFrom || page === Page.AddViewer) {
setSelectedContacts([]);
setStagedMyStories(initialMyStories);
setPage(Page.SetMyStoriesPrivacy);
} else if (page === Page.ChooseViewers) {
setSelectedContacts([]);
setPage(Page.SendStory);
} else if (page === Page.NameStory) {
setPage(Page.ChooseViewers);
}
})
}
2022-08-10 18:37:19 +00:00
selectedContacts={selectedContacts}
setSelectedContacts={setSelectedContacts}
theme={theme}
2022-08-10 18:37:19 +00:00
/>
);
} else if (page === Page.ChooseGroups) {
const footer = (
2022-08-10 18:37:19 +00:00
<>
<div className="SendStoryModal__selected-lists">{selectedNames}</div>
{selectedNames.length > 0 && (
<button
2023-03-30 00:03:25 +00:00
aria-label={i18n('icu:ok')}
className="SendStoryModal__ok"
disabled={!chosenGroupIds.size}
onClick={async () => {
await toggleGroupsForStorySend(Array.from(chosenGroupIds));
setChosenGroupIds(new Set());
setSelectedGroupIds(chosenGroupIds);
setPage(Page.SendStory);
}}
type="button"
/>
)}
</>
);
modal = handleClose => (
<ModalPage
modalName="SendStoryModal__choose-groups"
2023-03-30 00:03:25 +00:00
title={i18n('icu:SendStoryModal__choose-groups')}
moduleClassName="SendStoryModal"
modalFooter={footer}
onClose={handleClose}
{...modalCommonProps}
>
2022-08-10 18:37:19 +00:00
<SearchInput
disabled={groupConversations.length === 0}
i18n={i18n}
2023-03-30 00:03:25 +00:00
placeholder={i18n('icu:contactSearchPlaceholder')}
2022-08-10 18:37:19 +00:00
moduleClassName="StoriesSettingsModal__search"
onChange={event => {
setSearchTerm(event.target.value);
}}
value={searchTerm}
/>
{filteredConversations.length ? (
filteredConversations.map(group => (
<Checkbox
checked={chosenGroupIds.has(group.id)}
key={group.id}
label={group.title}
moduleClassName="SendStoryModal__distribution-list"
name="SendStoryModal__distribution-list"
onChange={(value: boolean) => {
if (group.announcementsOnly && !group.areWeAdmin) {
setHasAnnouncementsOnlyAlert(true);
return;
}
2022-08-10 18:37:19 +00:00
setChosenGroupIds(groupIds => {
if (value) {
groupIds.add(group.id);
} else {
groupIds.delete(group.id);
}
return new Set([...groupIds]);
});
}}
>
{({ id, checkboxNode }) => (
<>
<label
className="SendStoryModal__distribution-list__label"
htmlFor={id}
>
<Avatar
acceptedMessageRequest={group.acceptedMessageRequest}
avatarPath={group.avatarPath}
badge={undefined}
color={group.color}
conversationType={group.type}
i18n={i18n}
isMe={false}
sharedGroupNames={[]}
2022-12-09 20:37:45 +00:00
size={AvatarSize.THIRTY_TWO}
2022-08-10 18:37:19 +00:00
title={group.title}
/>
<div className="SendStoryModal__distribution-list__info">
<div className="SendStoryModal__distribution-list__name">
2023-04-20 17:03:43 +00:00
<UserText text={group.title} />
2022-08-10 18:37:19 +00:00
</div>
<div className="SendStoryModal__distribution-list__description">
{i18n('icu:ConversationHero--members', {
count: group.membersCount,
})}
2022-08-10 18:37:19 +00:00
</div>
</div>
</label>
{checkboxNode}
</>
)}
</Checkbox>
))
) : (
<div className="module-ForwardMessageModal__no-candidate-contacts">
2023-03-30 00:03:25 +00:00
{i18n('icu:noGroupsFound')}
2022-08-10 18:37:19 +00:00
</div>
)}
</ModalPage>
2022-08-10 18:37:19 +00:00
);
} else {
const footer = (
2022-08-10 18:37:19 +00:00
<>
<div className="SendStoryModal__selected-lists">{selectedNames}</div>
{selectedNames.length > 0 && (
<button
2023-03-30 00:03:25 +00:00
aria-label={i18n('icu:SendStoryModal__send')}
className="SendStoryModal__send"
disabled={!selectedListIds.size && !selectedGroupIds.size}
onClick={() => {
onSend(Array.from(selectedListIds), Array.from(selectedGroupIds));
}}
type="button"
/>
)}
</>
);
const attachment = {
...draftAttachment,
url: objectUrl,
};
// my stories always first, the rest sorted by recency
const fullList = sortBy(
[...groupStories, ...distributionLists],
listOrGroup => {
if (listOrGroup.id === MY_STORY_ID) {
return Number.NEGATIVE_INFINITY;
}
return (
(mostRecentActiveStoryTimestampByGroupOrDistributionList[
listOrGroup.id
] ?? 0) * -1
);
}
);
const renderDistributionList = (
list: StoryDistributionListWithMembersDataType
): JSX.Element => {
return (
<Checkbox
checked={selectedListIds.has(list.id)}
key={list.id}
label={getStoryDistributionListName(i18n, list.id, list.name)}
moduleClassName="SendStoryModal__distribution-list"
name="SendStoryModal__distribution-list"
onChange={(value: boolean) => {
if (
list.id === MY_STORY_ID &&
hasFirstStoryPostExperience &&
value
) {
setPage(Page.SetMyStoriesPrivacy);
return;
}
setSelectedListIds(listIds => {
if (value) {
listIds.add(list.id);
} else {
listIds.delete(list.id);
}
return new Set([...listIds]);
});
if (value && ourConversationId) {
onSelectedStoryList({
conversationId: ourConversationId,
distributionId: list.id,
serviceIds: getListMemberServiceIds(list, signalConnections),
});
}
}}
>
{({ id, checkboxNode }) => (
<ContextMenu
i18n={i18n}
menuOptions={
list.id === MY_STORY_ID
? [
{
2023-03-30 00:03:25 +00:00
label: i18n('icu:StoriesSettings__context-menu'),
icon: 'SendStoryModal__icon--delete',
onClick: () => setListIdToEdit(list.id),
},
]
: [
{
2023-03-30 00:03:25 +00:00
label: i18n('icu:StoriesSettings__context-menu'),
icon: 'SendStoryModal__icon--settings',
onClick: () => setListIdToEdit(list.id),
},
{
2023-03-30 00:03:25 +00:00
label: i18n('icu:SendStoryModal__delete-story'),
icon: 'SendStoryModal__icon--delete',
onClick: () => setConfirmDeleteList(list),
},
]
}
moduleClassName="SendStoryModal__distribution-list-context"
onClick={noop}
popperOptions={{
placement: 'bottom',
strategy: 'absolute',
}}
theme={theme === ThemeType.dark ? Theme.Dark : Theme.Light}
>
<label
className="SendStoryModal__distribution-list__label"
htmlFor={id}
>
{list.id === MY_STORY_ID ? (
<Avatar
acceptedMessageRequest={me.acceptedMessageRequest}
avatarPath={me.avatarPath}
badge={undefined}
color={me.color}
conversationType={me.type}
i18n={i18n}
isMe
sharedGroupNames={me.sharedGroupNames}
2022-12-09 20:37:45 +00:00
size={AvatarSize.THIRTY_TWO}
storyRing={undefined}
title={me.title}
/>
) : (
<span className="StoriesSettingsModal__list__avatar--custom" />
)}
<div className="SendStoryModal__distribution-list__info">
<div className="SendStoryModal__distribution-list__name">
<StoryDistributionListName
i18n={i18n}
id={list.id}
name={list.name}
/>
</div>
<div className="SendStoryModal__distribution-list__description">
{hasFirstStoryPostExperience && list.id === MY_STORY_ID ? (
2023-03-30 00:03:25 +00:00
i18n('icu:SendStoryModal__choose-who-can-view')
) : (
<>
<span className="SendStoryModal__rtl-span">
{list.id === MY_STORY_ID
? getI18nForMyStory(list, i18n)
2023-03-30 00:03:25 +00:00
: i18n('icu:SendStoryModal__custom-story')}
</span>
<span className="SendStoryModal__rtl-span">
&nbsp;&middot;&nbsp;
</span>
<span className="SendStoryModal__rtl-span">
{list.isBlockList && list.members.length > 0
? i18n('icu:SendStoryModal__excluded', {
count: list.members.length,
})
: getListViewers(list, i18n, signalConnections)}
</span>
</>
)}
</div>
</div>
</label>
{checkboxNode}
</ContextMenu>
)}
</Checkbox>
);
};
const renderGroup = (group: ConversationWithStoriesType) => {
return (
<Checkbox
checked={selectedGroupIds.has(group.id)}
key={group.id}
label={group.title}
moduleClassName="SendStoryModal__distribution-list"
name="SendStoryModal__distribution-list"
onChange={(value: boolean) => {
if (!group.memberships) {
return;
}
if (group.announcementsOnly && !group.areWeAdmin) {
setHasAnnouncementsOnlyAlert(true);
return;
}
setSelectedGroupIds(groupIds => {
if (value) {
groupIds.add(group.id);
} else {
groupIds.delete(group.id);
}
return new Set([...groupIds]);
});
if (value) {
onSelectedStoryList({
conversationId: group.id,
distributionId: undefined,
2023-08-16 20:54:39 +00:00
serviceIds: group.memberships.map(({ aci }) => aci),
});
}
}}
>
{({ id, checkboxNode }) => (
<ContextMenu
i18n={i18n}
menuOptions={[
{
2023-03-30 00:03:25 +00:00
label: i18n('icu:SendStoryModal__delete-story'),
icon: 'SendStoryModal__icon--delete',
onClick: () => setConfirmRemoveGroupId(group.id),
},
]}
moduleClassName="SendStoryModal__distribution-list-context"
onClick={noop}
popperOptions={{
placement: 'bottom',
strategy: 'absolute',
}}
theme={theme === ThemeType.dark ? Theme.Dark : Theme.Light}
>
<label
className="SendStoryModal__distribution-list__label"
htmlFor={id}
>
<Avatar
acceptedMessageRequest={group.acceptedMessageRequest}
avatarPath={group.avatarPath}
badge={undefined}
color={group.color}
conversationType={group.type}
i18n={i18n}
isMe={false}
sharedGroupNames={[]}
2022-12-09 20:37:45 +00:00
size={AvatarSize.THIRTY_TWO}
storyRing={group.hasStories}
title={group.title}
/>
<div className="SendStoryModal__distribution-list__info">
<div className="SendStoryModal__distribution-list__name">
2023-04-20 17:03:43 +00:00
<UserText text={group.title} />
</div>
<div className="SendStoryModal__distribution-list__description">
<span className="SendStoryModal__rtl-span">
2023-03-30 00:03:25 +00:00
{i18n('icu:SendStoryModal__group-story')}
</span>
<span className="SendStoryModal__rtl-span">
&nbsp;&middot;&nbsp;
</span>
<span className="SendStoryModal__rtl-span">
{i18n('icu:ConversationHero--members', {
count: group.membersCount,
})}
</span>
</div>
</div>
</label>
{checkboxNode}
</ContextMenu>
)}
</Checkbox>
);
};
modal = handleClose => (
<ModalPage
modalName="SendStoryModal__title"
2023-03-30 00:03:25 +00:00
title={i18n('icu:SendStoryModal__title')}
moduleClassName="SendStoryModal"
modalFooter={footer}
onClose={handleClose}
{...modalCommonProps}
>
<div
className="SendStoryModal__story-preview"
style={{ backgroundImage: getStoryBackground(attachment) }}
>
<StoryImage
i18n={i18n}
2023-03-30 00:03:25 +00:00
firstName={i18n('icu:you')}
queueStoryDownload={noop}
storyId="story-id"
label="label"
moduleClassName="SendStoryModal__story"
attachment={attachment}
2023-02-24 23:18:57 +00:00
onMediaPlaybackStart={onMediaPlaybackStart}
/>
</div>
2022-08-10 18:37:19 +00:00
<div className="SendStoryModal__top-bar">
2023-03-30 00:03:25 +00:00
{i18n('icu:stories')}
2022-08-10 18:37:19 +00:00
<ContextMenu
2023-03-30 00:03:25 +00:00
aria-label={i18n('icu:SendStoryModal__new')}
2022-08-10 18:37:19 +00:00
i18n={i18n}
menuOptions={[
{
2023-03-30 00:03:25 +00:00
label: i18n('icu:SendStoryModal__new-custom--title'),
description: i18n(
'icu:SendStoryModal__new-custom--description'
),
icon: 'SendStoryModal__icon--custom',
2022-08-10 18:37:19 +00:00
onClick: () => setPage(Page.ChooseViewers),
},
{
2023-03-30 00:03:25 +00:00
label: i18n('icu:SendStoryModal__new-group--title'),
description: i18n('icu:SendStoryModal__new-group--description'),
2022-08-10 18:37:19 +00:00
icon: 'SendStoryModal__icon--group',
onClick: () => setPage(Page.ChooseGroups),
},
]}
moduleClassName="SendStoryModal__new-story"
popperOptions={{
placement: 'bottom',
strategy: 'absolute',
}}
theme={theme === ThemeType.dark ? Theme.Dark : Theme.Light}
2022-08-10 18:37:19 +00:00
>
2022-11-04 13:22:07 +00:00
{({ openMenu, onKeyDown, ref, menuNode }) => (
<div>
<Button
ref={ref}
className="SendStoryModal__new-story__button"
variant={ButtonVariant.Secondary}
size={ButtonSize.Small}
onClick={openMenu}
onKeyDown={onKeyDown}
>
2023-03-30 00:03:25 +00:00
{i18n('icu:SendStoryModal__new')}
2022-11-04 13:22:07 +00:00
</Button>
{menuNode}
</div>
)}
2022-08-10 18:37:19 +00:00
</ContextMenu>
</div>
{fullList.map(listOrGroup =>
// only group has a type field
'type' in listOrGroup
? renderGroup(listOrGroup)
: renderDistributionList(listOrGroup)
)}
</ModalPage>
2022-08-10 18:37:19 +00:00
);
}
return (
2022-08-30 19:13:32 +00:00
<>
{!confirmDiscardModal && (
<PagedModal
modalName="SendStoryModal"
theme={theme === ThemeType.dark ? Theme.Dark : Theme.Light}
onClose={() => confirmDiscardIf(selectedContacts.length > 0, onClose)}
>
{modal}
</PagedModal>
)}
{hasAnnouncementsOnlyAlert && (
<Alert
2023-03-30 00:03:25 +00:00
body={i18n('icu:SendStoryModal__announcements-only')}
i18n={i18n}
onClose={() => setHasAnnouncementsOnlyAlert(false)}
theme={theme === ThemeType.dark ? Theme.Dark : Theme.Light}
/>
)}
2022-08-30 19:13:32 +00:00
{confirmRemoveGroupId && (
<ConfirmationDialog
2022-09-27 20:24:21 +00:00
dialogName="SendStoryModal.confirmRemoveGroupId"
2022-08-30 19:13:32 +00:00
actions={[
{
action: () => {
void toggleGroupsForStorySend([confirmRemoveGroupId]);
2022-08-30 19:13:32 +00:00
setConfirmRemoveGroupId(undefined);
},
style: 'negative',
2023-03-30 00:03:25 +00:00
text: i18n('icu:delete'),
2022-08-30 19:13:32 +00:00
},
]}
i18n={i18n}
onClose={() => {
setConfirmRemoveGroupId(undefined);
}}
theme={theme === ThemeType.dark ? Theme.Dark : Theme.Light}
2022-08-30 19:13:32 +00:00
>
2023-03-30 00:03:25 +00:00
{i18n('icu:SendStoryModal__confirm-remove-group')}
2022-08-30 19:13:32 +00:00
</ConfirmationDialog>
)}
{confirmDeleteList && (
2022-08-30 19:13:32 +00:00
<ConfirmationDialog
2022-09-27 20:24:21 +00:00
dialogName="SendStoryModal.confirmDeleteList"
2022-08-30 19:13:32 +00:00
actions={[
{
action: () => {
onDeleteList(confirmDeleteList.id);
setConfirmDeleteList(undefined);
2022-08-30 19:13:32 +00:00
},
style: 'negative',
2023-03-30 00:03:25 +00:00
text: i18n('icu:delete'),
2022-08-30 19:13:32 +00:00
},
]}
i18n={i18n}
onClose={() => {
setConfirmDeleteList(undefined);
2022-08-30 19:13:32 +00:00
}}
theme={theme === ThemeType.dark ? Theme.Dark : Theme.Light}
2022-08-30 19:13:32 +00:00
>
2023-03-30 00:03:25 +00:00
{i18n('icu:StoriesSettings__delete-list--confirm', {
2023-03-27 23:37:39 +00:00
name: confirmDeleteList.name,
})}
2022-08-30 19:13:32 +00:00
</ConfirmationDialog>
)}
{confirmDiscardModal}
2022-08-30 19:13:32 +00:00
</>
2022-08-02 19:31:55 +00:00
);
2022-11-18 00:45:19 +00:00
}