Handle Safety Number changes while sending a story
This commit is contained in:
parent
d036803df9
commit
0fb45f045d
13 changed files with 392 additions and 44 deletions
|
@ -17,6 +17,7 @@ import { isInSystemContacts } from '../util/isInSystemContacts';
|
|||
export enum SafetyNumberChangeSource {
|
||||
Calling = 'Calling',
|
||||
MessageSend = 'MessageSend',
|
||||
Story = 'Story',
|
||||
}
|
||||
|
||||
export type SafetyNumberProps = {
|
||||
|
|
|
@ -22,6 +22,7 @@ import { MY_STORIES_ID, getStoryDistributionListName } from '../types/Stories';
|
|||
import { Modal } from './Modal';
|
||||
import { StoryDistributionListName } from './StoryDistributionListName';
|
||||
import { Theme } from '../util/theme';
|
||||
import { isNotNil } from '../util/isNotNil';
|
||||
|
||||
export type PropsType = {
|
||||
candidateConversations: Array<ConversationType>;
|
||||
|
@ -36,6 +37,7 @@ export type PropsType = {
|
|||
name: string,
|
||||
viewerUuids: Array<UUIDStringType>
|
||||
) => unknown;
|
||||
onSelectedStoryList: (memberUuids: Array<string>) => unknown;
|
||||
onSend: (
|
||||
listIds: Array<UUIDStringType>,
|
||||
conversationIds: Array<string>
|
||||
|
@ -56,6 +58,21 @@ const Page = {
|
|||
|
||||
type PageType = SendStoryPage | StoriesSettingsPage;
|
||||
|
||||
function getListMemberUuids(
|
||||
list: StoryDistributionListDataType,
|
||||
signalConnections: Array<ConversationType>
|
||||
): Array<string> {
|
||||
if (list.id === MY_STORIES_ID && list.isBlockList) {
|
||||
const excludeUuids = new Set<string>(list.memberUuids);
|
||||
return signalConnections
|
||||
.map(conversation => conversation.uuid)
|
||||
.filter(isNotNil)
|
||||
.filter(uuid => !excludeUuids.has(uuid));
|
||||
}
|
||||
|
||||
return list.memberUuids;
|
||||
}
|
||||
|
||||
function getListViewers(
|
||||
list: StoryDistributionListDataType,
|
||||
i18n: LocalizerType,
|
||||
|
@ -85,6 +102,7 @@ export const SendStoryModal = ({
|
|||
onClose,
|
||||
onDistributionListCreated,
|
||||
onSend,
|
||||
onSelectedStoryList,
|
||||
signalConnections,
|
||||
tagGroupsAsNewGroupStory,
|
||||
}: PropsType): JSX.Element => {
|
||||
|
@ -300,6 +318,11 @@ export const SendStoryModal = ({
|
|||
}
|
||||
return new Set([...listIds]);
|
||||
});
|
||||
if (value) {
|
||||
onSelectedStoryList(
|
||||
getListMemberUuids(list, signalConnections)
|
||||
);
|
||||
}
|
||||
}}
|
||||
>
|
||||
{({ id, checkboxNode }) => (
|
||||
|
@ -352,6 +375,10 @@ export const SendStoryModal = ({
|
|||
moduleClassName="SendStoryModal__distribution-list"
|
||||
name="SendStoryModal__distribution-list"
|
||||
onChange={(value: boolean) => {
|
||||
if (!group.memberships) {
|
||||
return;
|
||||
}
|
||||
|
||||
setSelectedGroupIds(groupIds => {
|
||||
if (value) {
|
||||
groupIds.add(group.id);
|
||||
|
@ -360,6 +387,9 @@ export const SendStoryModal = ({
|
|||
}
|
||||
return new Set([...groupIds]);
|
||||
});
|
||||
if (value) {
|
||||
onSelectedStoryList(group.memberships.map(({ uuid }) => uuid));
|
||||
}
|
||||
}}
|
||||
>
|
||||
{({ id, checkboxNode }) => (
|
||||
|
|
|
@ -43,6 +43,7 @@ export type PropsType = {
|
|||
name: string,
|
||||
viewerUuids: Array<UUIDStringType>
|
||||
) => unknown;
|
||||
onSelectedStoryList: (memberUuids: Array<string>) => unknown;
|
||||
onSend: (
|
||||
listIds: Array<UUIDStringType>,
|
||||
conversationIds: Array<string>,
|
||||
|
@ -51,6 +52,7 @@ export type PropsType = {
|
|||
processAttachment: (
|
||||
file: File
|
||||
) => Promise<void | InMemoryAttachmentDraftType>;
|
||||
sendStoryModalOpenStateChanged: (isOpen: boolean) => unknown;
|
||||
signalConnections: Array<ConversationType>;
|
||||
tagGroupsAsNewGroupStory: (cids: Array<string>) => unknown;
|
||||
} & Pick<StickerButtonProps, 'installedPacks' | 'recentStickers'>;
|
||||
|
@ -69,9 +71,11 @@ export const StoryCreator = ({
|
|||
me,
|
||||
onClose,
|
||||
onDistributionListCreated,
|
||||
onSelectedStoryList,
|
||||
onSend,
|
||||
processAttachment,
|
||||
recentStickers,
|
||||
sendStoryModalOpenStateChanged,
|
||||
signalConnections,
|
||||
tagGroupsAsNewGroupStory,
|
||||
}: PropsType): JSX.Element => {
|
||||
|
@ -112,6 +116,10 @@ export const StoryCreator = ({
|
|||
};
|
||||
}, [file, processAttachment]);
|
||||
|
||||
useEffect(() => {
|
||||
sendStoryModalOpenStateChanged(Boolean(draftAttachment));
|
||||
}, [draftAttachment, sendStoryModalOpenStateChanged]);
|
||||
|
||||
return (
|
||||
<>
|
||||
{draftAttachment && (
|
||||
|
@ -125,6 +133,7 @@ export const StoryCreator = ({
|
|||
me={me}
|
||||
onClose={() => setDraftAttachment(undefined)}
|
||||
onDistributionListCreated={onDistributionListCreated}
|
||||
onSelectedStoryList={onSelectedStoryList}
|
||||
onSend={(listIds, groupIds) => {
|
||||
onSend(listIds, groupIds, draftAttachment);
|
||||
setDraftAttachment(undefined);
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue