2023-01-03 19:55:46 +00:00
|
|
|
// Copyright 2021 Signal Messenger, LLC
|
2022-03-04 21:14:52 +00:00
|
|
|
// SPDX-License-Identifier: AGPL-3.0-only
|
|
|
|
|
2022-07-06 19:06:20 +00:00
|
|
|
import type { ThunkAction, ThunkDispatch } from 'redux-thunk';
|
2022-10-13 16:14:50 +00:00
|
|
|
import { isEqual, pick } from 'lodash';
|
2022-11-02 00:36:16 +00:00
|
|
|
|
2023-01-13 20:07:26 +00:00
|
|
|
import type { ReadonlyDeep } from 'type-fest';
|
2022-11-02 00:36:16 +00:00
|
|
|
import * as Errors from '../../types/errors';
|
2022-08-04 19:23:24 +00:00
|
|
|
import type { AttachmentType } from '../../types/Attachment';
|
2023-04-14 18:16:28 +00:00
|
|
|
import type { DraftBodyRanges } from '../../types/BodyRange';
|
2022-03-04 21:14:52 +00:00
|
|
|
import type { MessageAttributesType } from '../../model-types.d';
|
2022-04-15 00:08:46 +00:00
|
|
|
import type {
|
|
|
|
MessageChangedActionType,
|
|
|
|
MessageDeletedActionType,
|
2022-08-02 19:31:55 +00:00
|
|
|
MessagesAddedActionType,
|
2023-03-20 22:23:53 +00:00
|
|
|
TargetedConversationChangedActionType,
|
2022-04-15 00:08:46 +00:00
|
|
|
} from './conversations';
|
2022-03-04 21:14:52 +00:00
|
|
|
import type { NoopActionType } from './noop';
|
|
|
|
import type { StateType as RootStateType } from '../reducer';
|
2022-10-11 17:59:02 +00:00
|
|
|
import type { StoryViewTargetType, StoryViewType } from '../../types/Stories';
|
2022-03-04 21:14:52 +00:00
|
|
|
import type { SyncType } from '../../jobs/helpers/syncHelpers';
|
2023-08-10 16:43:33 +00:00
|
|
|
import type { StoryDistributionIdString } from '../../types/StoryDistributionId';
|
|
|
|
import type { ServiceIdString } from '../../types/ServiceId';
|
2023-08-16 20:54:39 +00:00
|
|
|
import { isAciString } from '../../types/ServiceId';
|
2022-03-04 21:14:52 +00:00
|
|
|
import * as log from '../../logging/log';
|
2023-03-20 22:23:53 +00:00
|
|
|
import { TARGETED_CONVERSATION_CHANGED } from './conversations';
|
2022-11-09 21:11:45 +00:00
|
|
|
import { SIGNAL_ACI } from '../../types/SignalConversation';
|
2022-03-29 01:10:08 +00:00
|
|
|
import dataInterface from '../../sql/Client';
|
2022-03-04 21:14:52 +00:00
|
|
|
import { ReadStatus } from '../../messages/MessageReadStatus';
|
2023-02-07 19:33:04 +00:00
|
|
|
import { SendStatus } from '../../messages/MessageSendState';
|
2022-08-19 18:05:31 +00:00
|
|
|
import { SafetyNumberChangeSource } from '../../components/SafetyNumberChangeDialog';
|
2022-07-06 19:06:20 +00:00
|
|
|
import { StoryViewDirectionType, StoryViewModeType } from '../../types/Stories';
|
2023-01-05 21:58:13 +00:00
|
|
|
import { assertDev, strictAssert } from '../../util/assert';
|
2022-12-21 18:41:48 +00:00
|
|
|
import { drop } from '../../util/drop';
|
2022-08-19 18:05:31 +00:00
|
|
|
import { blockSendUntilConversationsAreVerified } from '../../util/blockSendUntilConversationsAreVerified';
|
2022-10-13 16:14:50 +00:00
|
|
|
import { deleteStoryForEveryone as doDeleteStoryForEveryone } from '../../util/deleteStoryForEveryone';
|
2022-11-04 13:22:07 +00:00
|
|
|
import { deleteGroupStoryReplyForEveryone as doDeleteGroupStoryReplyForEveryone } from '../../util/deleteGroupStoryReplyForEveryone';
|
2022-03-04 21:14:52 +00:00
|
|
|
import { enqueueReactionForSend } from '../../reactions/enqueueReactionForSend';
|
|
|
|
import { getMessageById } from '../../messages/getMessageById';
|
2022-11-09 02:38:19 +00:00
|
|
|
import { markOnboardingStoryAsRead } from '../../util/markOnboardingStoryAsRead';
|
2022-03-04 21:14:52 +00:00
|
|
|
import { markViewed } from '../../services/MessageUpdater';
|
2022-03-29 01:10:08 +00:00
|
|
|
import { queueAttachmentDownloads } from '../../util/queueAttachmentDownloads';
|
|
|
|
import { replaceIndex } from '../../util/replaceIndex';
|
2022-11-16 20:18:02 +00:00
|
|
|
import type { DurationInSeconds } from '../../util/durations';
|
2022-10-31 21:28:28 +00:00
|
|
|
import { hasFailed, isDownloaded, isDownloading } from '../../types/Attachment';
|
2022-09-22 00:55:23 +00:00
|
|
|
import {
|
|
|
|
getConversationSelector,
|
|
|
|
getHideStoryConversationIds,
|
|
|
|
} from '../selectors/conversations';
|
2022-10-31 21:28:28 +00:00
|
|
|
import {
|
|
|
|
getStories,
|
|
|
|
getStoryDownloadableAttachment,
|
|
|
|
} from '../selectors/stories';
|
2022-08-02 19:31:55 +00:00
|
|
|
import { getStoryDataFromMessageAttributes } from '../../services/storyLoader';
|
2022-07-06 19:06:20 +00:00
|
|
|
import { isGroup } from '../../util/whatTypeOfConversation';
|
2022-08-02 19:31:55 +00:00
|
|
|
import { isNotNil } from '../../util/isNotNil';
|
|
|
|
import { isStory } from '../../messages/helpers';
|
|
|
|
import { sendStoryMessage as doSendStoryMessage } from '../../util/sendStoryMessage';
|
2022-12-09 17:35:34 +00:00
|
|
|
import type { BoundActionCreatorsMapObject } from '../../hooks/useBoundActions';
|
2022-03-04 21:14:52 +00:00
|
|
|
import { useBoundActions } from '../../hooks/useBoundActions';
|
2022-08-19 18:05:31 +00:00
|
|
|
import { verifyStoryListMembers as doVerifyStoryListMembers } from '../../util/verifyStoryListMembers';
|
2022-03-04 21:14:52 +00:00
|
|
|
import { viewSyncJobQueue } from '../../jobs/viewSyncJobQueue';
|
2022-11-11 04:10:30 +00:00
|
|
|
import { getOwn } from '../../util/getOwn';
|
2022-12-20 01:04:47 +00:00
|
|
|
import { SHOW_TOAST } from './toast';
|
|
|
|
import { ToastType } from '../../types/Toast';
|
|
|
|
import type { ShowToastActionType } from './toast';
|
2023-02-06 17:24:34 +00:00
|
|
|
import {
|
|
|
|
conversationJobQueue,
|
|
|
|
conversationQueueJobEnum,
|
|
|
|
} from '../../jobs/conversationJobQueue';
|
|
|
|
import { ReceiptType } from '../../types/Receipt';
|
2022-03-04 21:14:52 +00:00
|
|
|
|
2023-01-13 20:07:26 +00:00
|
|
|
export type StoryDataType = ReadonlyDeep<
|
|
|
|
{
|
|
|
|
attachment?: AttachmentType;
|
|
|
|
hasReplies?: boolean;
|
|
|
|
hasRepliesFromSelf?: boolean;
|
|
|
|
messageId: string;
|
|
|
|
startedDownload?: boolean;
|
|
|
|
} & Pick<
|
|
|
|
MessageAttributesType,
|
2023-04-10 16:31:45 +00:00
|
|
|
| 'bodyRanges'
|
2023-01-13 20:07:26 +00:00
|
|
|
| 'canReplyToStory'
|
|
|
|
| 'conversationId'
|
|
|
|
| 'deletedForEveryone'
|
|
|
|
| 'reactions'
|
|
|
|
| 'readAt'
|
|
|
|
| 'readStatus'
|
|
|
|
| 'sendStateByConversationId'
|
|
|
|
| 'source'
|
2023-08-16 20:54:39 +00:00
|
|
|
| 'sourceServiceId'
|
2023-01-13 20:07:26 +00:00
|
|
|
| 'storyDistributionListId'
|
|
|
|
| 'timestamp'
|
|
|
|
| 'type'
|
|
|
|
| 'storyRecipientsVersion'
|
|
|
|
> & {
|
|
|
|
// don't want the fields to be optional as in MessageAttributesType
|
|
|
|
expireTimer: DurationInSeconds | undefined;
|
|
|
|
expirationStartTimestamp: number | undefined;
|
|
|
|
sourceDevice: number;
|
|
|
|
}
|
|
|
|
>;
|
2022-03-04 21:14:52 +00:00
|
|
|
|
2023-01-13 20:07:26 +00:00
|
|
|
export type SelectedStoryDataType = ReadonlyDeep<{
|
2022-07-06 19:06:20 +00:00
|
|
|
currentIndex: number;
|
2022-07-29 20:22:55 +00:00
|
|
|
messageId: string;
|
2022-07-06 19:06:20 +00:00
|
|
|
numStories: number;
|
2022-08-22 17:44:23 +00:00
|
|
|
storyViewMode: StoryViewModeType;
|
2022-10-17 16:33:07 +00:00
|
|
|
unviewedStoryConversationIdsSorted: Array<string>;
|
|
|
|
viewTarget?: StoryViewTargetType;
|
2023-01-13 20:07:26 +00:00
|
|
|
}>;
|
2022-07-06 19:06:20 +00:00
|
|
|
|
2023-01-13 20:07:26 +00:00
|
|
|
export type AddStoryData = ReadonlyDeep<
|
2022-11-02 00:36:16 +00:00
|
|
|
| {
|
|
|
|
type: 'Media';
|
|
|
|
file: File;
|
|
|
|
sending?: boolean;
|
|
|
|
}
|
|
|
|
| {
|
|
|
|
type: 'Text';
|
|
|
|
sending?: boolean;
|
|
|
|
}
|
2023-01-13 20:07:26 +00:00
|
|
|
| undefined
|
|
|
|
>;
|
2022-11-02 00:36:16 +00:00
|
|
|
|
2023-01-13 20:07:26 +00:00
|
|
|
// eslint-disable-next-line local-rules/type-alias-readonlydeep
|
2022-11-11 04:10:30 +00:00
|
|
|
export type RecipientsByConversation = Record<
|
|
|
|
string, // conversationId
|
|
|
|
{
|
2023-08-10 16:43:33 +00:00
|
|
|
serviceIds: Array<ServiceIdString>;
|
2022-11-11 04:10:30 +00:00
|
|
|
|
|
|
|
byDistributionId?: Record<
|
2023-08-10 16:43:33 +00:00
|
|
|
StoryDistributionIdString,
|
2022-11-11 04:10:30 +00:00
|
|
|
{
|
2023-08-10 16:43:33 +00:00
|
|
|
serviceIds: Array<ServiceIdString>;
|
2022-11-11 04:10:30 +00:00
|
|
|
}
|
|
|
|
>;
|
|
|
|
}
|
|
|
|
>;
|
|
|
|
|
2022-03-04 21:14:52 +00:00
|
|
|
// State
|
|
|
|
|
2023-01-13 20:07:26 +00:00
|
|
|
// eslint-disable-next-line local-rules/type-alias-readonlydeep
|
2022-11-10 04:24:42 +00:00
|
|
|
export type StoriesStateType = Readonly<{
|
2022-11-11 04:10:30 +00:00
|
|
|
addStoryData: AddStoryData;
|
|
|
|
hasAllStoriesUnmuted: boolean;
|
2022-11-10 04:24:42 +00:00
|
|
|
lastOpenedAtTimestamp: number | undefined;
|
|
|
|
replyState?: Readonly<{
|
2022-04-15 00:08:46 +00:00
|
|
|
messageId: string;
|
|
|
|
replies: Array<MessageAttributesType>;
|
2022-11-10 04:24:42 +00:00
|
|
|
}>;
|
|
|
|
selectedStoryData?: SelectedStoryDataType;
|
2022-11-11 04:10:30 +00:00
|
|
|
sendStoryModalData?: RecipientsByConversation;
|
2022-11-10 04:24:42 +00:00
|
|
|
stories: ReadonlyArray<StoryDataType>;
|
|
|
|
}>;
|
2022-03-04 21:14:52 +00:00
|
|
|
|
|
|
|
// Actions
|
|
|
|
|
2022-07-01 00:52:03 +00:00
|
|
|
const DOE_STORY = 'stories/DOE';
|
2022-08-19 18:05:31 +00:00
|
|
|
const LIST_MEMBERS_VERIFIED = 'stories/LIST_MEMBERS_VERIFIED';
|
2022-04-15 00:08:46 +00:00
|
|
|
const LOAD_STORY_REPLIES = 'stories/LOAD_STORY_REPLIES';
|
2022-03-29 01:10:08 +00:00
|
|
|
const MARK_STORY_READ = 'stories/MARK_STORY_READ';
|
2022-08-11 22:26:26 +00:00
|
|
|
const QUEUE_STORY_DOWNLOAD = 'stories/QUEUE_STORY_DOWNLOAD';
|
2022-08-19 18:05:31 +00:00
|
|
|
const SEND_STORY_MODAL_OPEN_STATE_CHANGED =
|
|
|
|
'stories/SEND_STORY_MODAL_OPEN_STATE_CHANGED';
|
2022-03-29 01:10:08 +00:00
|
|
|
const STORY_CHANGED = 'stories/STORY_CHANGED';
|
2023-08-09 00:53:06 +00:00
|
|
|
const CLEAR_STORIES_TAB_STATE = 'stories/CLEAR_STORIES_TAB_STATE';
|
|
|
|
const MARK_STORIES_TAB_VIEWED = 'stories/MARK_STORIES_TAB_VIEWED';
|
2022-07-06 19:06:20 +00:00
|
|
|
const VIEW_STORY = 'stories/VIEW_STORY';
|
2022-11-04 13:22:07 +00:00
|
|
|
const STORY_REPLY_DELETED = 'stories/STORY_REPLY_DELETED';
|
2022-10-20 19:16:37 +00:00
|
|
|
const REMOVE_ALL_STORIES = 'stories/REMOVE_ALL_STORIES';
|
2022-11-02 00:36:16 +00:00
|
|
|
const SET_ADD_STORY_DATA = 'stories/SET_ADD_STORY_DATA';
|
|
|
|
const SET_STORY_SENDING = 'stories/SET_STORY_SENDING';
|
2022-11-10 04:24:42 +00:00
|
|
|
const SET_HAS_ALL_STORIES_UNMUTED = 'stories/SET_HAS_ALL_STORIES_UNMUTED';
|
2022-03-04 21:14:52 +00:00
|
|
|
|
2023-01-13 20:07:26 +00:00
|
|
|
type DOEStoryActionType = ReadonlyDeep<{
|
2022-07-01 00:52:03 +00:00
|
|
|
type: typeof DOE_STORY;
|
|
|
|
payload: string;
|
2023-01-13 20:07:26 +00:00
|
|
|
}>;
|
2022-07-01 00:52:03 +00:00
|
|
|
|
2023-01-13 20:07:26 +00:00
|
|
|
type ListMembersVerified = ReadonlyDeep<{
|
2022-08-19 18:05:31 +00:00
|
|
|
type: typeof LIST_MEMBERS_VERIFIED;
|
|
|
|
payload: {
|
2022-11-11 04:10:30 +00:00
|
|
|
conversationId: string;
|
2023-08-10 16:43:33 +00:00
|
|
|
distributionId: StoryDistributionIdString | undefined;
|
|
|
|
serviceIds: Array<ServiceIdString>;
|
2022-08-19 18:05:31 +00:00
|
|
|
};
|
2023-01-13 20:07:26 +00:00
|
|
|
}>;
|
2022-08-19 18:05:31 +00:00
|
|
|
|
2023-01-13 20:07:26 +00:00
|
|
|
// eslint-disable-next-line local-rules/type-alias-readonlydeep
|
2022-04-15 00:08:46 +00:00
|
|
|
type LoadStoryRepliesActionType = {
|
|
|
|
type: typeof LOAD_STORY_REPLIES;
|
|
|
|
payload: {
|
|
|
|
messageId: string;
|
|
|
|
replies: Array<MessageAttributesType>;
|
|
|
|
};
|
|
|
|
};
|
|
|
|
|
2023-01-13 20:07:26 +00:00
|
|
|
type MarkStoryReadActionType = ReadonlyDeep<{
|
2022-03-29 01:10:08 +00:00
|
|
|
type: typeof MARK_STORY_READ;
|
2022-09-21 23:54:48 +00:00
|
|
|
payload: {
|
|
|
|
messageId: string;
|
|
|
|
readAt: number;
|
|
|
|
};
|
2023-01-13 20:07:26 +00:00
|
|
|
}>;
|
2022-03-04 21:14:52 +00:00
|
|
|
|
2023-01-13 20:07:26 +00:00
|
|
|
type QueueStoryDownloadActionType = ReadonlyDeep<{
|
2022-08-11 22:26:26 +00:00
|
|
|
type: typeof QUEUE_STORY_DOWNLOAD;
|
|
|
|
payload: string;
|
2023-01-13 20:07:26 +00:00
|
|
|
}>;
|
2022-08-11 22:26:26 +00:00
|
|
|
|
2023-01-13 20:07:26 +00:00
|
|
|
type SendStoryModalOpenStateChanged = ReadonlyDeep<{
|
2022-08-19 18:05:31 +00:00
|
|
|
type: typeof SEND_STORY_MODAL_OPEN_STATE_CHANGED;
|
|
|
|
payload: number | undefined;
|
2023-01-13 20:07:26 +00:00
|
|
|
}>;
|
2022-08-19 18:05:31 +00:00
|
|
|
|
2023-01-13 20:07:26 +00:00
|
|
|
type StoryChangedActionType = ReadonlyDeep<{
|
2022-03-29 01:10:08 +00:00
|
|
|
type: typeof STORY_CHANGED;
|
|
|
|
payload: StoryDataType;
|
2023-01-13 20:07:26 +00:00
|
|
|
}>;
|
2022-03-29 01:10:08 +00:00
|
|
|
|
2023-08-09 00:53:06 +00:00
|
|
|
type ClearStoriesTabStateActionType = ReadonlyDeep<{
|
|
|
|
type: typeof CLEAR_STORIES_TAB_STATE;
|
|
|
|
}>;
|
|
|
|
|
|
|
|
type MarkStoriesTabViewedActionType = ReadonlyDeep<{
|
|
|
|
type: typeof MARK_STORIES_TAB_VIEWED;
|
2023-01-13 20:07:26 +00:00
|
|
|
}>;
|
2022-03-04 21:14:52 +00:00
|
|
|
|
2023-01-13 20:07:26 +00:00
|
|
|
type ViewStoryActionType = ReadonlyDeep<{
|
2022-07-06 19:06:20 +00:00
|
|
|
type: typeof VIEW_STORY;
|
2022-08-22 17:44:23 +00:00
|
|
|
payload: SelectedStoryDataType | undefined;
|
2023-01-13 20:07:26 +00:00
|
|
|
}>;
|
2022-07-06 19:06:20 +00:00
|
|
|
|
2023-01-13 20:07:26 +00:00
|
|
|
type StoryReplyDeletedActionType = ReadonlyDeep<{
|
2022-11-04 13:22:07 +00:00
|
|
|
type: typeof STORY_REPLY_DELETED;
|
|
|
|
payload: string;
|
2023-01-13 20:07:26 +00:00
|
|
|
}>;
|
2022-11-04 13:22:07 +00:00
|
|
|
|
2023-01-13 20:07:26 +00:00
|
|
|
type RemoveAllStoriesActionType = ReadonlyDeep<{
|
2022-10-20 19:16:37 +00:00
|
|
|
type: typeof REMOVE_ALL_STORIES;
|
2023-01-13 20:07:26 +00:00
|
|
|
}>;
|
2022-10-20 19:16:37 +00:00
|
|
|
|
2023-01-13 20:07:26 +00:00
|
|
|
type SetAddStoryDataType = ReadonlyDeep<{
|
2022-11-02 00:36:16 +00:00
|
|
|
type: typeof SET_ADD_STORY_DATA;
|
|
|
|
payload: AddStoryData;
|
2023-01-13 20:07:26 +00:00
|
|
|
}>;
|
2022-11-02 00:36:16 +00:00
|
|
|
|
2023-01-13 20:07:26 +00:00
|
|
|
type SetStorySendingType = ReadonlyDeep<{
|
2022-11-02 00:36:16 +00:00
|
|
|
type: typeof SET_STORY_SENDING;
|
|
|
|
payload: boolean;
|
2023-01-13 20:07:26 +00:00
|
|
|
}>;
|
2022-11-02 00:36:16 +00:00
|
|
|
|
2023-01-13 20:07:26 +00:00
|
|
|
type SetHasAllStoriesUnmutedType = ReadonlyDeep<{
|
2022-11-10 04:24:42 +00:00
|
|
|
type: typeof SET_HAS_ALL_STORIES_UNMUTED;
|
|
|
|
payload: boolean;
|
2023-01-13 20:07:26 +00:00
|
|
|
}>;
|
2022-11-10 04:24:42 +00:00
|
|
|
|
2023-01-13 20:07:26 +00:00
|
|
|
// eslint-disable-next-line local-rules/type-alias-readonlydeep
|
2022-03-04 21:14:52 +00:00
|
|
|
export type StoriesActionType =
|
2022-07-01 00:52:03 +00:00
|
|
|
| DOEStoryActionType
|
2022-08-19 18:05:31 +00:00
|
|
|
| ListMembersVerified
|
2022-04-15 00:08:46 +00:00
|
|
|
| LoadStoryRepliesActionType
|
2022-03-29 01:10:08 +00:00
|
|
|
| MarkStoryReadActionType
|
2022-04-15 00:08:46 +00:00
|
|
|
| MessageChangedActionType
|
2022-03-04 21:14:52 +00:00
|
|
|
| MessageDeletedActionType
|
2022-08-02 19:31:55 +00:00
|
|
|
| MessagesAddedActionType
|
2022-08-11 22:26:26 +00:00
|
|
|
| QueueStoryDownloadActionType
|
2022-08-19 18:05:31 +00:00
|
|
|
| SendStoryModalOpenStateChanged
|
2022-03-29 01:10:08 +00:00
|
|
|
| StoryChangedActionType
|
2023-08-09 00:53:06 +00:00
|
|
|
| ClearStoriesTabStateActionType
|
|
|
|
| MarkStoriesTabViewedActionType
|
2022-10-20 19:16:37 +00:00
|
|
|
| ViewStoryActionType
|
2022-11-04 13:22:07 +00:00
|
|
|
| StoryReplyDeletedActionType
|
2022-11-02 00:36:16 +00:00
|
|
|
| RemoveAllStoriesActionType
|
2023-03-20 22:23:53 +00:00
|
|
|
| TargetedConversationChangedActionType
|
2022-11-02 00:36:16 +00:00
|
|
|
| SetAddStoryDataType
|
2022-11-10 04:24:42 +00:00
|
|
|
| SetStorySendingType
|
|
|
|
| SetHasAllStoriesUnmutedType;
|
2022-03-04 21:14:52 +00:00
|
|
|
|
|
|
|
// Action Creators
|
|
|
|
|
2022-11-04 13:22:07 +00:00
|
|
|
function deleteGroupStoryReply(
|
|
|
|
messageId: string
|
|
|
|
): ThunkAction<void, RootStateType, unknown, StoryReplyDeletedActionType> {
|
|
|
|
return async dispatch => {
|
|
|
|
await window.Signal.Data.removeMessage(messageId);
|
|
|
|
dispatch({
|
|
|
|
type: STORY_REPLY_DELETED,
|
|
|
|
payload: messageId,
|
|
|
|
});
|
|
|
|
};
|
|
|
|
}
|
|
|
|
|
|
|
|
function deleteGroupStoryReplyForEveryone(
|
|
|
|
replyMessageId: string
|
|
|
|
): ThunkAction<void, RootStateType, unknown, NoopActionType> {
|
|
|
|
return async dispatch => {
|
|
|
|
await doDeleteGroupStoryReplyForEveryone(replyMessageId);
|
|
|
|
|
|
|
|
// the call above re-uses the sync-message processing code to update the UI
|
|
|
|
// we don't need to do anything here
|
|
|
|
dispatch({
|
|
|
|
type: 'NOOP',
|
|
|
|
payload: null,
|
|
|
|
});
|
|
|
|
};
|
|
|
|
}
|
|
|
|
|
2022-07-01 00:52:03 +00:00
|
|
|
function deleteStoryForEveryone(
|
|
|
|
story: StoryViewType
|
|
|
|
): ThunkAction<void, RootStateType, unknown, DOEStoryActionType> {
|
2022-07-13 23:09:18 +00:00
|
|
|
return async (dispatch, getState) => {
|
2022-07-01 00:52:03 +00:00
|
|
|
if (!story.sendState) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
const { stories } = getState().stories;
|
2022-10-13 16:14:50 +00:00
|
|
|
const storyData = stories.find(item => item.messageId === story.messageId);
|
|
|
|
if (!storyData) {
|
|
|
|
log.warn('deleteStoryForEveryone: Could not find story in redux data');
|
|
|
|
return;
|
2022-07-13 23:09:18 +00:00
|
|
|
}
|
2022-10-13 16:14:50 +00:00
|
|
|
await doDeleteStoryForEveryone(stories, storyData);
|
2022-07-13 23:09:18 +00:00
|
|
|
|
2022-07-01 00:52:03 +00:00
|
|
|
dispatch({
|
|
|
|
type: DOE_STORY,
|
|
|
|
payload: story.messageId,
|
|
|
|
});
|
|
|
|
};
|
|
|
|
}
|
|
|
|
|
2022-04-15 00:08:46 +00:00
|
|
|
function loadStoryReplies(
|
|
|
|
conversationId: string,
|
|
|
|
messageId: string
|
|
|
|
): ThunkAction<void, RootStateType, unknown, LoadStoryRepliesActionType> {
|
2022-05-11 22:20:47 +00:00
|
|
|
return async (dispatch, getState) => {
|
|
|
|
const conversation = getConversationSelector(getState())(conversationId);
|
2023-03-04 03:03:15 +00:00
|
|
|
const replies = await dataInterface.getOlderMessagesByConversation({
|
2022-04-15 00:08:46 +00:00
|
|
|
conversationId,
|
2023-03-04 03:03:15 +00:00
|
|
|
limit: 9000,
|
|
|
|
storyId: messageId,
|
|
|
|
includeStoryReplies: !isGroup(conversation),
|
|
|
|
});
|
2022-04-15 00:08:46 +00:00
|
|
|
|
|
|
|
dispatch({
|
|
|
|
type: LOAD_STORY_REPLIES,
|
|
|
|
payload: {
|
|
|
|
messageId,
|
|
|
|
replies,
|
|
|
|
},
|
|
|
|
});
|
|
|
|
};
|
|
|
|
}
|
|
|
|
|
2022-03-04 21:14:52 +00:00
|
|
|
function markStoryRead(
|
|
|
|
messageId: string
|
2022-03-29 01:10:08 +00:00
|
|
|
): ThunkAction<void, RootStateType, unknown, MarkStoryReadActionType> {
|
2022-03-04 21:14:52 +00:00
|
|
|
return async (dispatch, getState) => {
|
|
|
|
const { stories } = getState().stories;
|
|
|
|
|
|
|
|
const matchingStory = stories.find(story => story.messageId === messageId);
|
|
|
|
|
|
|
|
if (!matchingStory) {
|
|
|
|
log.warn(`markStoryRead: no matching story found: ${messageId}`);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2022-08-04 00:38:41 +00:00
|
|
|
if (
|
|
|
|
!isDownloaded(matchingStory.attachment) &&
|
|
|
|
!hasFailed(matchingStory.attachment)
|
|
|
|
) {
|
2022-10-03 23:10:20 +00:00
|
|
|
log.warn(
|
|
|
|
`markStoryRead: not downloaded: ${messageId} ${
|
|
|
|
matchingStory.attachment?.error
|
|
|
|
? `error: ${matchingStory.attachment?.error}`
|
|
|
|
: ''
|
|
|
|
}`
|
|
|
|
);
|
2022-04-08 15:40:15 +00:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2022-03-04 21:14:52 +00:00
|
|
|
if (matchingStory.readStatus !== ReadStatus.Unread) {
|
2022-10-03 23:10:20 +00:00
|
|
|
log.warn(
|
|
|
|
`markStoryRead: not unread, ${messageId} read status: ${matchingStory.readStatus}`
|
|
|
|
);
|
2022-03-04 21:14:52 +00:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
const message = await getMessageById(messageId);
|
|
|
|
|
|
|
|
if (!message) {
|
2022-10-03 23:10:20 +00:00
|
|
|
log.warn(`markStoryRead: no message found ${messageId}`);
|
2022-03-04 21:14:52 +00:00
|
|
|
return;
|
|
|
|
}
|
2023-03-09 01:40:26 +00:00
|
|
|
|
2023-08-16 20:54:39 +00:00
|
|
|
const authorId = message.attributes.sourceServiceId;
|
2023-01-05 21:58:13 +00:00
|
|
|
strictAssert(
|
|
|
|
authorId,
|
|
|
|
'markStoryRead: The message needs a sender to mark it read!'
|
|
|
|
);
|
2023-08-16 20:54:39 +00:00
|
|
|
strictAssert(
|
|
|
|
isAciString(authorId),
|
|
|
|
'markStoryRead: The message needs a sender ACI to mark it read!'
|
|
|
|
);
|
2022-03-04 21:14:52 +00:00
|
|
|
|
2023-08-16 20:54:39 +00:00
|
|
|
const isSignalOnboardingStory = authorId === SIGNAL_ACI;
|
2022-11-09 02:38:19 +00:00
|
|
|
|
|
|
|
if (isSignalOnboardingStory) {
|
2023-04-18 15:35:29 +00:00
|
|
|
const updatedMessages = await markOnboardingStoryAsRead();
|
|
|
|
if (updatedMessages) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
log.warn(
|
|
|
|
'markStoryRead: Failed to mark onboarding story read normally; failing over'
|
|
|
|
);
|
2022-11-09 02:38:19 +00:00
|
|
|
}
|
|
|
|
|
2022-03-29 01:10:08 +00:00
|
|
|
const storyReadDate = Date.now();
|
|
|
|
|
2022-08-22 22:13:30 +00:00
|
|
|
message.set(markViewed(message.attributes, storyReadDate));
|
2023-03-09 01:40:26 +00:00
|
|
|
drop(
|
|
|
|
dataInterface.saveMessage(message.attributes, {
|
2023-08-10 16:43:33 +00:00
|
|
|
ourAci: window.textsecure.storage.user.getCheckedAci(),
|
2023-03-09 01:40:26 +00:00
|
|
|
})
|
|
|
|
);
|
2022-03-04 21:14:52 +00:00
|
|
|
|
2023-02-06 17:24:34 +00:00
|
|
|
const conversationId = message.get('conversationId');
|
|
|
|
|
2022-03-04 21:14:52 +00:00
|
|
|
const viewedReceipt = {
|
|
|
|
messageId,
|
2023-02-06 17:24:34 +00:00
|
|
|
conversationId,
|
2022-03-04 21:14:52 +00:00
|
|
|
senderE164: message.attributes.source,
|
2023-08-16 20:54:39 +00:00
|
|
|
senderAci: authorId,
|
2022-03-04 21:14:52 +00:00
|
|
|
timestamp: message.attributes.sent_at,
|
2022-08-15 21:53:33 +00:00
|
|
|
isDirectConversation: false,
|
2022-03-04 21:14:52 +00:00
|
|
|
};
|
|
|
|
const viewSyncs: Array<SyncType> = [viewedReceipt];
|
|
|
|
|
2023-04-18 15:35:29 +00:00
|
|
|
if (
|
|
|
|
!isSignalOnboardingStory &&
|
|
|
|
!window.ConversationController.areWePrimaryDevice()
|
|
|
|
) {
|
2022-12-21 18:41:48 +00:00
|
|
|
drop(viewSyncJobQueue.add({ viewSyncs }));
|
2022-03-04 21:14:52 +00:00
|
|
|
}
|
|
|
|
|
2023-04-18 15:35:29 +00:00
|
|
|
if (
|
|
|
|
!isSignalOnboardingStory &&
|
|
|
|
window.Events.getStoryViewReceiptsEnabled()
|
|
|
|
) {
|
2023-02-06 17:24:34 +00:00
|
|
|
drop(
|
|
|
|
conversationJobQueue.add({
|
|
|
|
type: conversationQueueJobEnum.enum.Receipts,
|
|
|
|
conversationId,
|
|
|
|
receiptsType: ReceiptType.Viewed,
|
|
|
|
receipts: [viewedReceipt],
|
|
|
|
})
|
|
|
|
);
|
2022-10-25 22:18:42 +00:00
|
|
|
}
|
2022-03-04 21:14:52 +00:00
|
|
|
|
2022-03-29 01:10:08 +00:00
|
|
|
await dataInterface.addNewStoryRead({
|
2023-01-05 21:58:13 +00:00
|
|
|
authorId,
|
2022-03-29 01:10:08 +00:00
|
|
|
conversationId: message.attributes.conversationId,
|
2022-07-08 20:46:25 +00:00
|
|
|
storyId: messageId,
|
2022-03-29 01:10:08 +00:00
|
|
|
storyReadDate,
|
|
|
|
});
|
|
|
|
|
|
|
|
dispatch({
|
|
|
|
type: MARK_STORY_READ,
|
2022-09-21 23:54:48 +00:00
|
|
|
payload: {
|
|
|
|
messageId,
|
|
|
|
readAt: storyReadDate,
|
|
|
|
},
|
2022-03-29 01:10:08 +00:00
|
|
|
});
|
|
|
|
};
|
|
|
|
}
|
|
|
|
|
|
|
|
function queueStoryDownload(
|
|
|
|
storyId: string
|
2022-04-25 17:25:50 +00:00
|
|
|
): ThunkAction<
|
|
|
|
void,
|
|
|
|
RootStateType,
|
|
|
|
unknown,
|
2022-10-31 21:28:28 +00:00
|
|
|
NoopActionType | QueueStoryDownloadActionType
|
2022-04-25 17:25:50 +00:00
|
|
|
> {
|
2022-07-01 00:52:03 +00:00
|
|
|
return async (dispatch, getState) => {
|
|
|
|
const { stories } = getState().stories;
|
|
|
|
const story = stories.find(item => item.messageId === storyId);
|
2022-03-29 01:10:08 +00:00
|
|
|
|
|
|
|
if (!story) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2022-10-31 21:28:28 +00:00
|
|
|
const attachment = getStoryDownloadableAttachment(story);
|
2022-03-29 01:10:08 +00:00
|
|
|
|
|
|
|
if (!attachment) {
|
|
|
|
log.warn('queueStoryDownload: No attachment found for story', {
|
|
|
|
storyId,
|
|
|
|
});
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2022-08-04 00:38:41 +00:00
|
|
|
if (hasFailed(attachment)) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2022-03-29 01:10:08 +00:00
|
|
|
if (isDownloaded(attachment)) {
|
2022-04-25 17:25:50 +00:00
|
|
|
if (!attachment.path) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2022-03-29 01:10:08 +00:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2022-08-11 22:26:26 +00:00
|
|
|
// isDownloading checks for the downloadJobId which is set by
|
|
|
|
// queueAttachmentDownloads but we optimistically set story.startedDownload
|
|
|
|
// in redux to prevent race conditions from queuing up multiple attachment
|
|
|
|
// downloads before the attachment save takes place.
|
|
|
|
if (isDownloading(attachment) || story.startedDownload) {
|
2022-03-29 01:10:08 +00:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2022-07-01 00:52:03 +00:00
|
|
|
const message = await getMessageById(storyId);
|
|
|
|
|
|
|
|
if (message) {
|
|
|
|
// We want to ensure that we re-hydrate the story reply context with the
|
|
|
|
// completed attachment download.
|
|
|
|
message.set({ storyReplyContext: undefined });
|
2022-03-29 01:10:08 +00:00
|
|
|
|
2022-08-11 22:26:26 +00:00
|
|
|
dispatch({
|
|
|
|
type: QUEUE_STORY_DOWNLOAD,
|
|
|
|
payload: storyId,
|
|
|
|
});
|
|
|
|
|
2022-10-31 21:28:28 +00:00
|
|
|
const updatedFields = await queueAttachmentDownloads(message.attributes);
|
|
|
|
if (updatedFields) {
|
|
|
|
message.set(updatedFields);
|
|
|
|
}
|
2022-08-11 22:26:26 +00:00
|
|
|
return;
|
2022-07-01 00:52:03 +00:00
|
|
|
}
|
2022-03-29 01:10:08 +00:00
|
|
|
|
2022-03-04 21:14:52 +00:00
|
|
|
dispatch({
|
|
|
|
type: 'NOOP',
|
|
|
|
payload: null,
|
|
|
|
});
|
|
|
|
};
|
|
|
|
}
|
|
|
|
|
|
|
|
function reactToStory(
|
|
|
|
nextReaction: string,
|
2022-04-28 22:06:28 +00:00
|
|
|
messageId: string
|
2022-12-20 01:04:47 +00:00
|
|
|
): ThunkAction<
|
|
|
|
void,
|
|
|
|
RootStateType,
|
|
|
|
unknown,
|
|
|
|
ShowToastActionType | NoopActionType
|
|
|
|
> {
|
2022-03-04 21:14:52 +00:00
|
|
|
return async dispatch => {
|
|
|
|
try {
|
|
|
|
await enqueueReactionForSend({
|
|
|
|
messageId,
|
|
|
|
emoji: nextReaction,
|
2022-04-28 22:06:28 +00:00
|
|
|
remove: false,
|
2022-03-04 21:14:52 +00:00
|
|
|
});
|
2022-12-20 01:04:47 +00:00
|
|
|
dispatch({
|
|
|
|
type: 'NOOP',
|
|
|
|
payload: null,
|
|
|
|
});
|
2022-03-04 21:14:52 +00:00
|
|
|
} catch (error) {
|
|
|
|
log.error('Error enqueuing reaction', error, messageId, nextReaction);
|
2022-12-20 01:04:47 +00:00
|
|
|
dispatch({
|
|
|
|
type: SHOW_TOAST,
|
|
|
|
payload: {
|
|
|
|
toastType: ToastType.ReactionFailed,
|
|
|
|
},
|
|
|
|
});
|
2022-03-04 21:14:52 +00:00
|
|
|
}
|
|
|
|
};
|
|
|
|
}
|
|
|
|
|
|
|
|
function replyToStory(
|
|
|
|
conversationId: string,
|
2022-03-11 23:14:32 +00:00
|
|
|
messageBody: string,
|
2023-04-14 18:16:28 +00:00
|
|
|
bodyRanges: DraftBodyRanges,
|
2022-03-04 21:14:52 +00:00
|
|
|
timestamp: number,
|
|
|
|
story: StoryViewType
|
2022-11-23 04:05:33 +00:00
|
|
|
): ThunkAction<void, RootStateType, unknown, StoryChangedActionType> {
|
|
|
|
return async (dispatch, getState) => {
|
2022-04-15 00:08:46 +00:00
|
|
|
const conversation = window.ConversationController.get(conversationId);
|
|
|
|
|
|
|
|
if (!conversation) {
|
|
|
|
log.error('replyToStory: conversation does not exist', conversationId);
|
|
|
|
return;
|
|
|
|
}
|
2022-03-04 21:14:52 +00:00
|
|
|
|
2022-10-26 00:23:59 +00:00
|
|
|
await conversation.enqueueMessageForSend(
|
2022-04-11 20:57:44 +00:00
|
|
|
{
|
|
|
|
body: messageBody,
|
|
|
|
attachments: [],
|
2023-04-14 18:16:28 +00:00
|
|
|
bodyRanges,
|
2022-04-11 20:57:44 +00:00
|
|
|
},
|
2022-03-04 21:14:52 +00:00
|
|
|
{
|
|
|
|
storyId: story.messageId,
|
|
|
|
timestamp,
|
|
|
|
}
|
|
|
|
);
|
|
|
|
|
2022-11-23 04:05:33 +00:00
|
|
|
const { stories } = getState().stories;
|
|
|
|
|
|
|
|
const storyData = stories.find(s => s.messageId === story.messageId);
|
|
|
|
if (!storyData) {
|
|
|
|
log.error('replyToStory: story not found', story.messageId);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
// for group stories, this happens automatically through LOAD_STORY_REPLIES
|
|
|
|
// but 1:1 we need to update manually
|
|
|
|
dispatch(
|
|
|
|
storyChanged({
|
|
|
|
...storyData,
|
|
|
|
hasReplies: true,
|
|
|
|
hasRepliesFromSelf: true,
|
|
|
|
})
|
|
|
|
);
|
2022-03-04 21:14:52 +00:00
|
|
|
};
|
|
|
|
}
|
|
|
|
|
2022-08-02 19:31:55 +00:00
|
|
|
function sendStoryMessage(
|
2023-08-10 16:43:33 +00:00
|
|
|
listIds: Array<StoryDistributionIdString>,
|
2022-08-09 03:26:21 +00:00
|
|
|
conversationIds: Array<string>,
|
2023-05-10 00:40:19 +00:00
|
|
|
attachment: AttachmentType,
|
|
|
|
bodyRanges: DraftBodyRanges | undefined
|
2022-11-02 00:36:16 +00:00
|
|
|
): ThunkAction<
|
|
|
|
void,
|
|
|
|
RootStateType,
|
|
|
|
unknown,
|
|
|
|
SendStoryModalOpenStateChanged | SetStorySendingType | SetAddStoryDataType
|
|
|
|
> {
|
2022-08-19 18:05:31 +00:00
|
|
|
return async (dispatch, getState) => {
|
|
|
|
const { stories } = getState();
|
2023-08-09 00:53:06 +00:00
|
|
|
const { lastOpenedAtTimestamp, sendStoryModalData } = stories;
|
2022-11-02 00:36:16 +00:00
|
|
|
|
|
|
|
// Add spinners in the story creator
|
|
|
|
dispatch({
|
|
|
|
type: SET_STORY_SENDING,
|
|
|
|
payload: true,
|
|
|
|
});
|
|
|
|
|
2022-09-15 19:17:15 +00:00
|
|
|
assertDev(
|
2023-08-09 00:53:06 +00:00
|
|
|
lastOpenedAtTimestamp,
|
|
|
|
'sendStoryMessage: lastOpenedAtTimestamp is undefined, cannot send'
|
2022-08-19 18:05:31 +00:00
|
|
|
);
|
2022-09-15 19:17:15 +00:00
|
|
|
assertDev(
|
2022-08-19 18:05:31 +00:00
|
|
|
sendStoryModalData,
|
|
|
|
'sendStoryMessage: sendStoryModalData is not defined, cannot send'
|
|
|
|
);
|
2022-08-02 19:31:55 +00:00
|
|
|
|
2023-01-01 11:41:40 +00:00
|
|
|
log.info('sendStoryMessage: Verifying trust for all recipients');
|
2022-08-19 18:05:31 +00:00
|
|
|
|
2022-11-11 04:10:30 +00:00
|
|
|
const result = await blockSendUntilConversationsAreVerified(
|
|
|
|
sendStoryModalData,
|
|
|
|
SafetyNumberChangeSource.Story,
|
2023-08-09 00:53:06 +00:00
|
|
|
Date.now() - lastOpenedAtTimestamp
|
2022-11-11 04:10:30 +00:00
|
|
|
);
|
2022-11-02 00:36:16 +00:00
|
|
|
|
2022-11-11 04:10:30 +00:00
|
|
|
if (!result) {
|
|
|
|
log.info('sendStoryMessage: failed to verify untrusted; stopping send');
|
2022-11-02 00:36:16 +00:00
|
|
|
dispatch({
|
2022-11-11 04:10:30 +00:00
|
|
|
type: SET_STORY_SENDING,
|
|
|
|
payload: false,
|
2022-11-02 00:36:16 +00:00
|
|
|
});
|
2022-11-11 04:10:30 +00:00
|
|
|
return;
|
2022-08-19 18:05:31 +00:00
|
|
|
}
|
|
|
|
|
2022-11-02 00:36:16 +00:00
|
|
|
try {
|
2023-05-10 00:40:19 +00:00
|
|
|
await doSendStoryMessage(
|
|
|
|
listIds,
|
|
|
|
conversationIds,
|
|
|
|
attachment,
|
|
|
|
bodyRanges
|
|
|
|
);
|
2022-11-02 00:36:16 +00:00
|
|
|
|
|
|
|
// Note: Only when we've successfully queued the message do we dismiss the story
|
|
|
|
// composer view.
|
2022-11-11 04:10:30 +00:00
|
|
|
dispatch({
|
|
|
|
type: SEND_STORY_MODAL_OPEN_STATE_CHANGED,
|
|
|
|
payload: undefined,
|
|
|
|
});
|
2022-11-02 00:36:16 +00:00
|
|
|
dispatch({
|
|
|
|
type: SET_ADD_STORY_DATA,
|
|
|
|
payload: undefined,
|
|
|
|
});
|
|
|
|
} catch (error) {
|
|
|
|
log.error('sendStoryMessage:', Errors.toLogFormat(error));
|
|
|
|
|
|
|
|
// Get rid of spinners in the story creator
|
|
|
|
dispatch({
|
|
|
|
type: SET_STORY_SENDING,
|
|
|
|
payload: false,
|
|
|
|
});
|
|
|
|
}
|
2022-08-02 19:31:55 +00:00
|
|
|
};
|
|
|
|
}
|
|
|
|
|
2022-03-29 01:10:08 +00:00
|
|
|
function storyChanged(story: StoryDataType): StoryChangedActionType {
|
|
|
|
return {
|
|
|
|
type: STORY_CHANGED,
|
|
|
|
payload: story,
|
|
|
|
};
|
|
|
|
}
|
|
|
|
|
2022-08-19 18:05:31 +00:00
|
|
|
function sendStoryModalOpenStateChanged(
|
|
|
|
value: boolean
|
|
|
|
): ThunkAction<void, RootStateType, unknown, SendStoryModalOpenStateChanged> {
|
|
|
|
return (dispatch, getState) => {
|
|
|
|
const { stories } = getState();
|
|
|
|
|
|
|
|
if (!stories.sendStoryModalData && value) {
|
|
|
|
dispatch({
|
|
|
|
type: SEND_STORY_MODAL_OPEN_STATE_CHANGED,
|
|
|
|
payload: Date.now(),
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
if (stories.sendStoryModalData && !value) {
|
|
|
|
dispatch({
|
|
|
|
type: SEND_STORY_MODAL_OPEN_STATE_CHANGED,
|
|
|
|
payload: undefined,
|
|
|
|
});
|
|
|
|
}
|
|
|
|
};
|
|
|
|
}
|
|
|
|
|
2023-08-09 00:53:06 +00:00
|
|
|
function clearStoriesTabState(): ClearStoriesTabStateActionType {
|
2022-03-04 21:14:52 +00:00
|
|
|
return {
|
2023-08-09 00:53:06 +00:00
|
|
|
type: CLEAR_STORIES_TAB_STATE,
|
|
|
|
};
|
|
|
|
}
|
|
|
|
|
|
|
|
function markStoriesTabViewed(): MarkStoriesTabViewedActionType {
|
|
|
|
return {
|
|
|
|
type: MARK_STORIES_TAB_VIEWED,
|
2022-03-04 21:14:52 +00:00
|
|
|
};
|
|
|
|
}
|
|
|
|
|
2022-11-11 04:10:30 +00:00
|
|
|
function verifyStoryListMembers({
|
|
|
|
conversationId,
|
|
|
|
distributionId,
|
2023-08-10 16:43:33 +00:00
|
|
|
serviceIds,
|
2022-11-11 04:10:30 +00:00
|
|
|
}: {
|
|
|
|
conversationId: string;
|
2023-08-10 16:43:33 +00:00
|
|
|
distributionId: StoryDistributionIdString | undefined;
|
|
|
|
serviceIds: Array<ServiceIdString>;
|
2022-11-11 04:10:30 +00:00
|
|
|
}): ThunkAction<void, RootStateType, unknown, ListMembersVerified> {
|
2022-08-19 18:05:31 +00:00
|
|
|
return async (dispatch, getState) => {
|
|
|
|
const { stories } = getState();
|
|
|
|
const { sendStoryModalData } = stories;
|
|
|
|
|
|
|
|
if (!sendStoryModalData) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2023-08-10 16:43:33 +00:00
|
|
|
if (!serviceIds.length) {
|
2022-08-19 18:05:31 +00:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2022-11-11 04:10:30 +00:00
|
|
|
// This will fetch the latest identity key for these contacts, which will ensure that
|
|
|
|
// the later verified/trusted checks will flag that change.
|
2023-08-10 16:43:33 +00:00
|
|
|
await doVerifyStoryListMembers(serviceIds);
|
2022-08-19 18:05:31 +00:00
|
|
|
|
|
|
|
dispatch({
|
|
|
|
type: LIST_MEMBERS_VERIFIED,
|
|
|
|
payload: {
|
2022-11-11 04:10:30 +00:00
|
|
|
conversationId,
|
|
|
|
distributionId,
|
2023-08-10 16:43:33 +00:00
|
|
|
serviceIds,
|
2022-08-19 18:05:31 +00:00
|
|
|
},
|
|
|
|
});
|
|
|
|
};
|
|
|
|
}
|
|
|
|
|
2022-10-17 16:33:07 +00:00
|
|
|
const getSelectedStoryDataForDistributionListId = (
|
|
|
|
getState: () => RootStateType,
|
|
|
|
distributionListId: string | undefined,
|
|
|
|
selectedStoryId?: string
|
|
|
|
): {
|
|
|
|
currentIndex: number;
|
|
|
|
numStories: number;
|
|
|
|
storiesByConversationId: Array<StoryDataType>;
|
|
|
|
} => {
|
|
|
|
const state = getState();
|
|
|
|
const { stories } = state.stories;
|
|
|
|
|
|
|
|
const storiesByDistributionList = stories.filter(
|
|
|
|
item =>
|
|
|
|
item.storyDistributionListId === distributionListId &&
|
|
|
|
!item.deletedForEveryone
|
|
|
|
);
|
|
|
|
|
|
|
|
const numStories = storiesByDistributionList.length;
|
|
|
|
const currentIndex = selectedStoryId
|
|
|
|
? storiesByDistributionList.findIndex(
|
|
|
|
item => item.messageId === selectedStoryId
|
|
|
|
)
|
|
|
|
: 0;
|
|
|
|
|
|
|
|
return {
|
|
|
|
currentIndex,
|
|
|
|
numStories,
|
|
|
|
storiesByConversationId: [],
|
|
|
|
};
|
|
|
|
};
|
|
|
|
|
2022-07-06 19:06:20 +00:00
|
|
|
const getSelectedStoryDataForConversationId = (
|
2022-10-31 21:28:28 +00:00
|
|
|
dispatch: ThunkDispatch<RootStateType, unknown, NoopActionType>,
|
2022-07-06 19:06:20 +00:00
|
|
|
getState: () => RootStateType,
|
2022-11-29 22:19:50 +00:00
|
|
|
{
|
|
|
|
conversationId,
|
|
|
|
onlyFromSelf,
|
|
|
|
selectedStoryId,
|
|
|
|
}: {
|
|
|
|
conversationId: string;
|
|
|
|
onlyFromSelf: boolean;
|
|
|
|
selectedStoryId?: string;
|
|
|
|
}
|
2022-07-06 19:06:20 +00:00
|
|
|
): {
|
|
|
|
currentIndex: number;
|
|
|
|
hasUnread: boolean;
|
|
|
|
numStories: number;
|
|
|
|
storiesByConversationId: Array<StoryDataType>;
|
|
|
|
} => {
|
|
|
|
const state = getState();
|
|
|
|
const { stories } = state.stories;
|
|
|
|
|
2023-08-10 16:43:33 +00:00
|
|
|
const ourAci = window.storage.user.getCheckedAci();
|
2022-07-06 19:06:20 +00:00
|
|
|
const storiesByConversationId = stories.filter(
|
2022-11-29 22:19:50 +00:00
|
|
|
item =>
|
|
|
|
item.conversationId === conversationId &&
|
|
|
|
!item.deletedForEveryone &&
|
2023-08-16 20:54:39 +00:00
|
|
|
(!onlyFromSelf || item.sourceServiceId === ourAci)
|
2022-07-06 19:06:20 +00:00
|
|
|
);
|
|
|
|
|
|
|
|
// Find the index of the storyId provided, or if none provided then find the
|
2022-10-17 16:33:07 +00:00
|
|
|
// oldest unviewed story from the user. If all stories are read then we can
|
2022-07-06 19:06:20 +00:00
|
|
|
// start at the first story.
|
2022-10-08 02:02:46 +00:00
|
|
|
let currentIndex: number | undefined;
|
2022-07-06 19:06:20 +00:00
|
|
|
let hasUnread = false;
|
|
|
|
storiesByConversationId.forEach((item, index) => {
|
|
|
|
if (selectedStoryId && item.messageId === selectedStoryId) {
|
|
|
|
currentIndex = index;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (
|
|
|
|
!selectedStoryId &&
|
2022-10-08 02:02:46 +00:00
|
|
|
currentIndex === undefined &&
|
2022-07-06 19:06:20 +00:00
|
|
|
item.readStatus === ReadStatus.Unread
|
|
|
|
) {
|
|
|
|
hasUnread = true;
|
|
|
|
currentIndex = index;
|
|
|
|
}
|
|
|
|
});
|
|
|
|
|
|
|
|
const numStories = storiesByConversationId.length;
|
|
|
|
|
|
|
|
// Queue all undownloaded stories once we're viewing someone's stories
|
2022-10-31 21:28:28 +00:00
|
|
|
storiesByConversationId.forEach(({ attachment, messageId }) => {
|
|
|
|
if (isDownloaded(attachment) || isDownloading(attachment)) {
|
2022-07-06 19:06:20 +00:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2022-10-31 21:28:28 +00:00
|
|
|
queueStoryDownload(messageId)(dispatch, getState, null);
|
2022-07-06 19:06:20 +00:00
|
|
|
});
|
|
|
|
|
|
|
|
return {
|
2022-10-08 02:02:46 +00:00
|
|
|
currentIndex: currentIndex ?? 0,
|
2022-07-06 19:06:20 +00:00
|
|
|
hasUnread,
|
|
|
|
numStories,
|
|
|
|
storiesByConversationId,
|
|
|
|
};
|
|
|
|
};
|
|
|
|
|
2023-01-13 20:07:26 +00:00
|
|
|
export type ViewUserStoriesActionCreatorType = ReadonlyDeep<
|
|
|
|
(opts: {
|
|
|
|
conversationId: string;
|
|
|
|
storyViewMode?: StoryViewModeType;
|
|
|
|
viewTarget?: StoryViewTargetType;
|
|
|
|
}) => unknown
|
|
|
|
>;
|
2022-08-22 17:44:23 +00:00
|
|
|
|
|
|
|
const viewUserStories: ViewUserStoriesActionCreatorType = ({
|
|
|
|
conversationId,
|
|
|
|
storyViewMode,
|
2022-10-17 16:33:07 +00:00
|
|
|
viewTarget,
|
2022-08-22 17:44:23 +00:00
|
|
|
}): ThunkAction<void, RootStateType, unknown, ViewStoryActionType> => {
|
2022-07-06 19:06:20 +00:00
|
|
|
return (dispatch, getState) => {
|
|
|
|
const { currentIndex, hasUnread, numStories, storiesByConversationId } =
|
2022-11-29 22:19:50 +00:00
|
|
|
getSelectedStoryDataForConversationId(dispatch, getState, {
|
|
|
|
conversationId,
|
|
|
|
onlyFromSelf: false,
|
|
|
|
});
|
2022-07-06 19:06:20 +00:00
|
|
|
|
|
|
|
const story = storiesByConversationId[currentIndex];
|
2022-10-17 16:33:07 +00:00
|
|
|
const state = getState();
|
2022-07-06 19:06:20 +00:00
|
|
|
|
2022-10-17 16:33:07 +00:00
|
|
|
const hiddenConversationIds = new Set(getHideStoryConversationIds(state));
|
2022-09-22 18:56:39 +00:00
|
|
|
|
|
|
|
let inferredStoryViewMode: StoryViewModeType;
|
|
|
|
if (storyViewMode) {
|
|
|
|
inferredStoryViewMode = storyViewMode;
|
|
|
|
} else if (hiddenConversationIds.has(conversationId)) {
|
|
|
|
inferredStoryViewMode = StoryViewModeType.Hidden;
|
|
|
|
} else if (hasUnread) {
|
|
|
|
inferredStoryViewMode = StoryViewModeType.Unread;
|
|
|
|
} else {
|
|
|
|
inferredStoryViewMode = StoryViewModeType.All;
|
|
|
|
}
|
|
|
|
|
2022-10-17 16:33:07 +00:00
|
|
|
let unviewedStoryConversationIdsSorted: Array<string> = [];
|
|
|
|
if (
|
|
|
|
inferredStoryViewMode === StoryViewModeType.Unread ||
|
|
|
|
inferredStoryViewMode === StoryViewModeType.Hidden
|
|
|
|
) {
|
|
|
|
const storiesSelectorState = getStories(state);
|
|
|
|
const conversationStories =
|
|
|
|
inferredStoryViewMode === StoryViewModeType.Hidden
|
|
|
|
? storiesSelectorState.hiddenStories
|
|
|
|
: storiesSelectorState.stories;
|
|
|
|
unviewedStoryConversationIdsSorted = conversationStories
|
|
|
|
.filter(item => item.storyView.isUnread)
|
|
|
|
.map(item => item.conversationId);
|
|
|
|
}
|
|
|
|
|
2022-07-06 19:06:20 +00:00
|
|
|
dispatch({
|
|
|
|
type: VIEW_STORY,
|
|
|
|
payload: {
|
2022-08-22 17:44:23 +00:00
|
|
|
currentIndex,
|
|
|
|
messageId: story.messageId,
|
|
|
|
numStories,
|
2022-09-22 18:56:39 +00:00
|
|
|
storyViewMode: inferredStoryViewMode,
|
2022-10-17 16:33:07 +00:00
|
|
|
unviewedStoryConversationIdsSorted,
|
|
|
|
viewTarget,
|
2022-07-06 19:06:20 +00:00
|
|
|
},
|
|
|
|
});
|
|
|
|
};
|
2022-08-22 17:44:23 +00:00
|
|
|
};
|
2022-07-06 19:06:20 +00:00
|
|
|
|
2022-10-20 19:16:37 +00:00
|
|
|
function removeAllStories(): RemoveAllStoriesActionType {
|
|
|
|
return {
|
|
|
|
type: REMOVE_ALL_STORIES,
|
|
|
|
};
|
|
|
|
}
|
|
|
|
|
2023-01-13 20:07:26 +00:00
|
|
|
type ViewStoryOptionsType = ReadonlyDeep<
|
2022-09-22 00:55:23 +00:00
|
|
|
| {
|
|
|
|
closeViewer: true;
|
|
|
|
}
|
|
|
|
| {
|
|
|
|
storyId: string;
|
|
|
|
storyViewMode: StoryViewModeType;
|
|
|
|
viewDirection?: StoryViewDirectionType;
|
2022-10-11 17:59:02 +00:00
|
|
|
viewTarget?: StoryViewTargetType;
|
2023-01-13 20:07:26 +00:00
|
|
|
}
|
|
|
|
>;
|
2022-09-22 00:55:23 +00:00
|
|
|
|
2023-01-13 20:07:26 +00:00
|
|
|
export type ViewStoryActionCreatorType = ReadonlyDeep<
|
|
|
|
(opts: ViewStoryOptionsType) => unknown
|
|
|
|
>;
|
2022-07-25 18:55:44 +00:00
|
|
|
|
2023-01-13 20:07:26 +00:00
|
|
|
export type DispatchableViewStoryType = ReadonlyDeep<
|
|
|
|
(
|
|
|
|
opts: ViewStoryOptionsType
|
|
|
|
) => ThunkAction<void, RootStateType, unknown, ViewStoryActionType>
|
|
|
|
>;
|
2022-09-22 00:55:23 +00:00
|
|
|
|
2022-08-22 17:44:23 +00:00
|
|
|
const viewStory: ViewStoryActionCreatorType = (
|
|
|
|
opts
|
|
|
|
): ThunkAction<void, RootStateType, unknown, ViewStoryActionType> => {
|
2022-07-06 19:06:20 +00:00
|
|
|
return (dispatch, getState) => {
|
2022-08-22 17:44:23 +00:00
|
|
|
if ('closeViewer' in opts) {
|
2022-07-06 19:06:20 +00:00
|
|
|
dispatch({
|
|
|
|
type: VIEW_STORY,
|
|
|
|
payload: undefined,
|
|
|
|
});
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2022-10-11 17:59:02 +00:00
|
|
|
const { viewTarget, storyId, storyViewMode, viewDirection } = opts;
|
2022-08-22 17:44:23 +00:00
|
|
|
|
2022-07-06 19:06:20 +00:00
|
|
|
const state = getState();
|
2022-10-17 16:33:07 +00:00
|
|
|
const { selectedStoryData, stories } = state.stories;
|
|
|
|
|
|
|
|
const unviewedStoryConversationIdsSorted =
|
|
|
|
selectedStoryData?.unviewedStoryConversationIdsSorted || [];
|
2022-07-06 19:06:20 +00:00
|
|
|
|
|
|
|
// Spec:
|
|
|
|
// When opening the story viewer you should always be taken to the oldest
|
|
|
|
// un viewed story of the user you tapped on
|
|
|
|
// If all stories from a user are viewed, opening the viewer should take
|
|
|
|
// you to their oldest story
|
|
|
|
|
2022-07-29 18:12:47 +00:00
|
|
|
const story = stories.find(
|
|
|
|
item => item.messageId === storyId && !item.deletedForEveryone
|
|
|
|
);
|
2022-07-06 19:06:20 +00:00
|
|
|
|
|
|
|
if (!story) {
|
2022-08-22 17:44:23 +00:00
|
|
|
log.warn('stories.viewStory: No story found', storyId);
|
|
|
|
dispatch({
|
|
|
|
type: VIEW_STORY,
|
|
|
|
payload: undefined,
|
|
|
|
});
|
2022-07-06 19:06:20 +00:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
const { currentIndex, numStories, storiesByConversationId } =
|
2022-10-20 00:34:53 +00:00
|
|
|
storyViewMode === StoryViewModeType.MyStories &&
|
|
|
|
story.storyDistributionListId
|
2022-10-17 16:33:07 +00:00
|
|
|
? getSelectedStoryDataForDistributionListId(
|
|
|
|
getState,
|
|
|
|
story.storyDistributionListId,
|
|
|
|
storyId
|
|
|
|
)
|
2022-11-29 22:19:50 +00:00
|
|
|
: getSelectedStoryDataForConversationId(dispatch, getState, {
|
|
|
|
conversationId: story.conversationId,
|
|
|
|
onlyFromSelf: storyViewMode === StoryViewModeType.MyStories,
|
|
|
|
selectedStoryId: storyId,
|
|
|
|
});
|
2022-07-06 19:06:20 +00:00
|
|
|
|
|
|
|
// Go directly to the storyId selected
|
|
|
|
if (!viewDirection) {
|
2023-02-07 19:33:04 +00:00
|
|
|
const hasFailedSend = Object.values(
|
|
|
|
story.sendStateByConversationId || {}
|
|
|
|
).some(({ status }) => status === SendStatus.Failed);
|
|
|
|
|
2022-07-06 19:06:20 +00:00
|
|
|
dispatch({
|
|
|
|
type: VIEW_STORY,
|
|
|
|
payload: {
|
2022-08-22 17:44:23 +00:00
|
|
|
currentIndex,
|
|
|
|
messageId: storyId,
|
|
|
|
numStories,
|
2022-10-17 16:33:07 +00:00
|
|
|
storyViewMode,
|
|
|
|
unviewedStoryConversationIdsSorted,
|
2023-02-07 19:33:04 +00:00
|
|
|
viewTarget: hasFailedSend ? undefined : viewTarget,
|
2022-10-17 16:33:07 +00:00
|
|
|
},
|
|
|
|
});
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2022-10-27 01:03:43 +00:00
|
|
|
if (storyViewMode === StoryViewModeType.Single) {
|
|
|
|
// Close the viewer we were just looking at a single story.
|
|
|
|
dispatch({
|
|
|
|
type: VIEW_STORY,
|
|
|
|
payload: undefined,
|
|
|
|
});
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2022-10-17 16:33:07 +00:00
|
|
|
// When paging through all sent stories
|
|
|
|
// Note the order is reversed[1][2] here because we sort the stories by
|
|
|
|
// recency in descending order but the story viewer plays them in
|
|
|
|
// ascending order.
|
|
|
|
if (storyViewMode === StoryViewModeType.MyStories) {
|
|
|
|
const { myStories } = getStories(state);
|
|
|
|
|
|
|
|
let currentStoryIndex = -1;
|
|
|
|
const currentDistributionListIndex = myStories.findIndex(item => {
|
|
|
|
for (let i = item.stories.length - 1; i >= 0; i -= 1) {
|
|
|
|
const myStory = item.stories[i];
|
|
|
|
if (myStory.messageId === storyId) {
|
|
|
|
// [1] reversed
|
|
|
|
currentStoryIndex = item.stories.length - 1 - i;
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return false;
|
|
|
|
});
|
|
|
|
|
|
|
|
if (currentDistributionListIndex < 0 || currentStoryIndex < 0) {
|
|
|
|
log.warn('stories.viewStory: No current story found for MyStories', {
|
|
|
|
currentDistributionListIndex,
|
|
|
|
currentStoryIndex,
|
|
|
|
myStories: myStories.length,
|
|
|
|
});
|
|
|
|
dispatch({
|
|
|
|
type: VIEW_STORY,
|
|
|
|
payload: undefined,
|
|
|
|
});
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
let nextSentStoryId: string | undefined;
|
|
|
|
let nextSentStoryIndex = -1;
|
|
|
|
let nextNumStories = numStories;
|
|
|
|
|
|
|
|
// [2] reversed
|
|
|
|
const currentStories = myStories[currentDistributionListIndex].stories
|
|
|
|
.slice()
|
|
|
|
.reverse();
|
|
|
|
|
|
|
|
if (viewDirection === StoryViewDirectionType.Next) {
|
|
|
|
if (currentStoryIndex < currentStories.length - 1) {
|
|
|
|
nextSentStoryIndex = currentStoryIndex + 1;
|
|
|
|
nextSentStoryId = currentStories[nextSentStoryIndex].messageId;
|
|
|
|
} else if (currentDistributionListIndex < myStories.length - 1) {
|
|
|
|
const nextSentStoryContainer =
|
|
|
|
myStories[currentDistributionListIndex + 1];
|
|
|
|
|
|
|
|
nextNumStories = nextSentStoryContainer.stories.length;
|
|
|
|
nextSentStoryIndex = 0;
|
|
|
|
nextSentStoryId =
|
|
|
|
nextSentStoryContainer.stories[nextNumStories - 1].messageId;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (viewDirection === StoryViewDirectionType.Previous) {
|
|
|
|
if (currentStoryIndex > 0) {
|
|
|
|
nextSentStoryIndex = currentStoryIndex - 1;
|
|
|
|
nextSentStoryId = currentStories[nextSentStoryIndex].messageId;
|
|
|
|
} else if (currentDistributionListIndex > 0) {
|
|
|
|
const nextSentStoryContainer =
|
|
|
|
myStories[currentDistributionListIndex - 1];
|
|
|
|
|
|
|
|
nextNumStories = nextSentStoryContainer.stories.length;
|
|
|
|
nextSentStoryIndex = nextNumStories - 1;
|
|
|
|
nextSentStoryId = nextSentStoryContainer.stories[0].messageId;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!nextSentStoryId) {
|
|
|
|
dispatch({
|
|
|
|
type: VIEW_STORY,
|
|
|
|
payload: undefined,
|
|
|
|
});
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
dispatch({
|
|
|
|
type: VIEW_STORY,
|
|
|
|
payload: {
|
|
|
|
currentIndex: nextSentStoryIndex,
|
|
|
|
messageId: nextSentStoryId,
|
|
|
|
numStories: nextNumStories,
|
2022-07-06 19:06:20 +00:00
|
|
|
storyViewMode,
|
2022-10-17 16:33:07 +00:00
|
|
|
unviewedStoryConversationIdsSorted,
|
2022-07-06 19:06:20 +00:00
|
|
|
},
|
|
|
|
});
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Next story within the same user's stories
|
|
|
|
if (
|
|
|
|
viewDirection === StoryViewDirectionType.Next &&
|
|
|
|
currentIndex < numStories - 1
|
|
|
|
) {
|
|
|
|
const nextIndex = currentIndex + 1;
|
|
|
|
const nextStory = storiesByConversationId[nextIndex];
|
|
|
|
|
|
|
|
dispatch({
|
|
|
|
type: VIEW_STORY,
|
|
|
|
payload: {
|
2022-08-22 17:44:23 +00:00
|
|
|
currentIndex: nextIndex,
|
|
|
|
messageId: nextStory.messageId,
|
|
|
|
numStories,
|
2022-07-06 19:06:20 +00:00
|
|
|
storyViewMode,
|
2022-10-17 16:33:07 +00:00
|
|
|
unviewedStoryConversationIdsSorted,
|
2022-07-06 19:06:20 +00:00
|
|
|
},
|
|
|
|
});
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Prev story within the same user's stories
|
|
|
|
if (viewDirection === StoryViewDirectionType.Previous && currentIndex > 0) {
|
|
|
|
const nextIndex = currentIndex - 1;
|
|
|
|
const nextStory = storiesByConversationId[nextIndex];
|
|
|
|
|
|
|
|
dispatch({
|
|
|
|
type: VIEW_STORY,
|
|
|
|
payload: {
|
2022-08-22 17:44:23 +00:00
|
|
|
currentIndex: nextIndex,
|
|
|
|
messageId: nextStory.messageId,
|
|
|
|
numStories,
|
2022-07-06 19:06:20 +00:00
|
|
|
storyViewMode,
|
2022-10-17 16:33:07 +00:00
|
|
|
unviewedStoryConversationIdsSorted,
|
2022-07-06 19:06:20 +00:00
|
|
|
},
|
|
|
|
});
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2022-08-22 17:44:23 +00:00
|
|
|
// We were just viewing a single user's stories. Close the viewer.
|
|
|
|
if (storyViewMode === StoryViewModeType.User) {
|
|
|
|
dispatch({
|
|
|
|
type: VIEW_STORY,
|
|
|
|
payload: undefined,
|
|
|
|
});
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2022-10-08 02:02:46 +00:00
|
|
|
const storiesSelectorState = getStories(state);
|
|
|
|
const conversationStories =
|
|
|
|
storyViewMode === StoryViewModeType.Hidden
|
|
|
|
? storiesSelectorState.hiddenStories
|
|
|
|
: storiesSelectorState.stories;
|
|
|
|
const conversationStoryIndex = conversationStories.findIndex(
|
|
|
|
item => item.conversationId === story.conversationId
|
|
|
|
);
|
|
|
|
|
2022-07-06 19:06:20 +00:00
|
|
|
// Are there any unviewed stories left? If so we should play the unviewed
|
2022-10-17 16:33:07 +00:00
|
|
|
// stories first.
|
|
|
|
if (storyViewMode === StoryViewModeType.Unread) {
|
|
|
|
const frozenConversationStoryIndex =
|
|
|
|
unviewedStoryConversationIdsSorted.findIndex(
|
|
|
|
conversationId => conversationId === story.conversationId
|
|
|
|
);
|
2022-09-22 00:55:23 +00:00
|
|
|
|
2022-10-17 16:33:07 +00:00
|
|
|
let nextUnreadConversationId: string | undefined;
|
|
|
|
if (viewDirection === StoryViewDirectionType.Previous) {
|
|
|
|
nextUnreadConversationId =
|
|
|
|
unviewedStoryConversationIdsSorted[frozenConversationStoryIndex - 1];
|
|
|
|
} else if (viewDirection === StoryViewDirectionType.Next) {
|
|
|
|
nextUnreadConversationId =
|
|
|
|
unviewedStoryConversationIdsSorted[frozenConversationStoryIndex + 1];
|
|
|
|
}
|
|
|
|
|
|
|
|
if (nextUnreadConversationId) {
|
2022-07-06 19:06:20 +00:00
|
|
|
const nextSelectedStoryData = getSelectedStoryDataForConversationId(
|
|
|
|
dispatch,
|
|
|
|
getState,
|
2022-11-29 22:19:50 +00:00
|
|
|
{
|
|
|
|
conversationId: nextUnreadConversationId,
|
|
|
|
onlyFromSelf: false,
|
|
|
|
}
|
2022-07-06 19:06:20 +00:00
|
|
|
);
|
2022-10-08 02:02:46 +00:00
|
|
|
|
2022-07-06 19:06:20 +00:00
|
|
|
dispatch({
|
|
|
|
type: VIEW_STORY,
|
|
|
|
payload: {
|
2022-08-22 17:44:23 +00:00
|
|
|
currentIndex: nextSelectedStoryData.currentIndex,
|
2022-10-08 02:02:46 +00:00
|
|
|
messageId:
|
|
|
|
nextSelectedStoryData.storiesByConversationId[
|
|
|
|
nextSelectedStoryData.currentIndex
|
|
|
|
].messageId,
|
2022-08-22 17:44:23 +00:00
|
|
|
numStories: nextSelectedStoryData.numStories,
|
2022-07-06 19:06:20 +00:00
|
|
|
storyViewMode,
|
2022-10-17 16:33:07 +00:00
|
|
|
unviewedStoryConversationIdsSorted,
|
2022-07-06 19:06:20 +00:00
|
|
|
},
|
|
|
|
});
|
|
|
|
return;
|
|
|
|
}
|
2022-09-22 00:55:23 +00:00
|
|
|
|
2022-10-17 16:33:07 +00:00
|
|
|
// Close the viewer if we were viewing unviewed stories only and we did
|
|
|
|
// not find any more unviewed.
|
|
|
|
dispatch({
|
|
|
|
type: VIEW_STORY,
|
|
|
|
payload: undefined,
|
|
|
|
});
|
|
|
|
return;
|
2022-07-06 19:06:20 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
if (conversationStoryIndex < 0) {
|
2022-08-22 17:44:23 +00:00
|
|
|
log.warn('stories.viewStory: No stories found for conversation', {
|
|
|
|
storiesLength: conversationStories.length,
|
|
|
|
});
|
|
|
|
dispatch({
|
|
|
|
type: VIEW_STORY,
|
|
|
|
payload: undefined,
|
|
|
|
});
|
2022-07-06 19:06:20 +00:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Find the next user's stories
|
|
|
|
if (
|
|
|
|
viewDirection === StoryViewDirectionType.Next &&
|
|
|
|
conversationStoryIndex < conversationStories.length - 1
|
|
|
|
) {
|
|
|
|
// Spec:
|
|
|
|
// Tapping right advances you to the next un viewed story
|
|
|
|
// If all stories are viewed, advance to the next viewed story
|
|
|
|
// When you reach the newest story from a user, tapping right again
|
|
|
|
// should take you to the next user's oldest un viewed story or oldest
|
|
|
|
// story if all stories for the next user are viewed.
|
|
|
|
// When you reach the newest story from the last user in the story list,
|
|
|
|
// tapping right should close the viewer
|
|
|
|
// Touch area for tapping right should be 80% of width of the screen
|
|
|
|
const nextConversationStoryIndex = conversationStoryIndex + 1;
|
|
|
|
const conversationStory = conversationStories[nextConversationStoryIndex];
|
|
|
|
|
|
|
|
const nextSelectedStoryData = getSelectedStoryDataForConversationId(
|
|
|
|
dispatch,
|
|
|
|
getState,
|
2022-11-29 22:19:50 +00:00
|
|
|
{
|
|
|
|
conversationId: conversationStory.conversationId,
|
|
|
|
onlyFromSelf: false,
|
|
|
|
}
|
2022-07-06 19:06:20 +00:00
|
|
|
);
|
|
|
|
|
|
|
|
dispatch({
|
|
|
|
type: VIEW_STORY,
|
|
|
|
payload: {
|
2022-08-22 17:44:23 +00:00
|
|
|
currentIndex: 0,
|
|
|
|
messageId: nextSelectedStoryData.storiesByConversationId[0].messageId,
|
|
|
|
numStories: nextSelectedStoryData.numStories,
|
2022-07-06 19:06:20 +00:00
|
|
|
storyViewMode,
|
2022-10-17 16:33:07 +00:00
|
|
|
unviewedStoryConversationIdsSorted,
|
2022-07-06 19:06:20 +00:00
|
|
|
},
|
|
|
|
});
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Find the previous user's stories
|
|
|
|
if (
|
|
|
|
viewDirection === StoryViewDirectionType.Previous &&
|
|
|
|
conversationStoryIndex > 0
|
|
|
|
) {
|
|
|
|
// Spec:
|
|
|
|
// Tapping left takes you back to the previous story
|
|
|
|
// When you reach the oldest story from a user, tapping left again takes
|
|
|
|
// you to the previous users oldest un viewed story or newest viewed
|
|
|
|
// story if all stories are viewed
|
|
|
|
// If you tap left on the oldest story from the first user in the story
|
|
|
|
// list, it should re-start playback on that story
|
|
|
|
// Touch area for tapping left should be 20% of width of the screen
|
|
|
|
const nextConversationStoryIndex = conversationStoryIndex - 1;
|
|
|
|
const conversationStory = conversationStories[nextConversationStoryIndex];
|
|
|
|
|
|
|
|
const nextSelectedStoryData = getSelectedStoryDataForConversationId(
|
|
|
|
dispatch,
|
|
|
|
getState,
|
2022-11-29 22:19:50 +00:00
|
|
|
{
|
|
|
|
conversationId: conversationStory.conversationId,
|
|
|
|
onlyFromSelf: false,
|
|
|
|
}
|
2022-07-06 19:06:20 +00:00
|
|
|
);
|
|
|
|
|
|
|
|
dispatch({
|
|
|
|
type: VIEW_STORY,
|
|
|
|
payload: {
|
2022-08-22 17:44:23 +00:00
|
|
|
currentIndex: 0,
|
|
|
|
messageId: nextSelectedStoryData.storiesByConversationId[0].messageId,
|
|
|
|
numStories: nextSelectedStoryData.numStories,
|
2022-07-06 19:06:20 +00:00
|
|
|
storyViewMode,
|
2022-10-17 16:33:07 +00:00
|
|
|
unviewedStoryConversationIdsSorted,
|
2022-07-06 19:06:20 +00:00
|
|
|
},
|
|
|
|
});
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Could not meet any criteria, close the viewer
|
|
|
|
dispatch({
|
|
|
|
type: VIEW_STORY,
|
|
|
|
payload: undefined,
|
|
|
|
});
|
|
|
|
};
|
|
|
|
};
|
|
|
|
|
2022-11-02 00:36:16 +00:00
|
|
|
function setAddStoryData(addStoryData: AddStoryData): SetAddStoryDataType {
|
|
|
|
return {
|
|
|
|
type: SET_ADD_STORY_DATA,
|
|
|
|
payload: addStoryData,
|
|
|
|
};
|
|
|
|
}
|
|
|
|
|
|
|
|
function setStorySending(sending: boolean): SetStorySendingType {
|
|
|
|
return {
|
|
|
|
type: SET_STORY_SENDING,
|
|
|
|
payload: sending,
|
|
|
|
};
|
|
|
|
}
|
|
|
|
|
2022-11-10 04:24:42 +00:00
|
|
|
function setHasAllStoriesUnmuted(
|
|
|
|
isUnmuted: boolean
|
|
|
|
): SetHasAllStoriesUnmutedType {
|
|
|
|
return {
|
|
|
|
type: SET_HAS_ALL_STORIES_UNMUTED,
|
|
|
|
payload: isUnmuted,
|
|
|
|
};
|
|
|
|
}
|
|
|
|
|
2022-10-26 23:17:39 +00:00
|
|
|
function setStoriesDisabled(
|
|
|
|
value: boolean
|
|
|
|
): ThunkAction<void, RootStateType, unknown, never> {
|
|
|
|
return async () => {
|
|
|
|
await window.Events.setHasStoriesDisabled(value);
|
|
|
|
};
|
|
|
|
}
|
|
|
|
|
2023-07-21 20:01:12 +00:00
|
|
|
function removeAllContactStories(
|
|
|
|
conversationId: string
|
|
|
|
): ThunkAction<void, RootStateType, unknown, NoopActionType> {
|
|
|
|
return async (dispatch, getState) => {
|
|
|
|
const logId = `removeAllContactStories(${conversationId})`;
|
|
|
|
const { stories } = getState().stories;
|
|
|
|
const messageIds = stories
|
|
|
|
.filter(item => item.conversationId === conversationId)
|
|
|
|
.map(({ messageId }) => messageId);
|
|
|
|
|
|
|
|
const messages = (
|
|
|
|
await Promise.all(
|
|
|
|
messageIds.map(async messageId => {
|
|
|
|
const message = await getMessageById(messageId);
|
|
|
|
|
|
|
|
if (!message) {
|
|
|
|
log.warn(`${logId}: no message found ${messageId}`);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
return message;
|
|
|
|
})
|
|
|
|
)
|
|
|
|
).filter(isNotNil);
|
|
|
|
|
|
|
|
log.info(`${logId}: removing ${messages.length} stories`);
|
|
|
|
|
|
|
|
await Promise.all([
|
|
|
|
messages.map(m => m.cleanup()),
|
|
|
|
await dataInterface.removeMessages(messageIds),
|
|
|
|
]);
|
|
|
|
|
|
|
|
dispatch({
|
|
|
|
type: 'NOOP',
|
|
|
|
payload: null,
|
|
|
|
});
|
|
|
|
};
|
|
|
|
}
|
|
|
|
|
2022-07-06 19:06:20 +00:00
|
|
|
export const actions = {
|
|
|
|
deleteStoryForEveryone,
|
|
|
|
loadStoryReplies,
|
|
|
|
markStoryRead,
|
|
|
|
queueStoryDownload,
|
|
|
|
reactToStory,
|
2022-10-20 19:16:37 +00:00
|
|
|
removeAllStories,
|
2022-07-06 19:06:20 +00:00
|
|
|
replyToStory,
|
2022-08-02 19:31:55 +00:00
|
|
|
sendStoryMessage,
|
2022-08-19 18:05:31 +00:00
|
|
|
sendStoryModalOpenStateChanged,
|
2022-07-06 19:06:20 +00:00
|
|
|
storyChanged,
|
2023-08-09 00:53:06 +00:00
|
|
|
clearStoriesTabState,
|
|
|
|
markStoriesTabViewed,
|
2022-08-19 18:05:31 +00:00
|
|
|
verifyStoryListMembers,
|
2022-07-06 19:06:20 +00:00
|
|
|
viewUserStories,
|
|
|
|
viewStory,
|
2022-11-04 13:22:07 +00:00
|
|
|
deleteGroupStoryReply,
|
|
|
|
deleteGroupStoryReplyForEveryone,
|
2022-11-02 00:36:16 +00:00
|
|
|
setAddStoryData,
|
2022-10-26 23:17:39 +00:00
|
|
|
setStoriesDisabled,
|
2022-11-10 04:24:42 +00:00
|
|
|
setHasAllStoriesUnmuted,
|
2022-11-02 00:36:16 +00:00
|
|
|
setStorySending,
|
2023-07-21 20:01:12 +00:00
|
|
|
removeAllContactStories,
|
2022-07-06 19:06:20 +00:00
|
|
|
};
|
|
|
|
|
2022-12-09 17:35:34 +00:00
|
|
|
export const useStoriesActions = (): BoundActionCreatorsMapObject<
|
|
|
|
typeof actions
|
|
|
|
> => useBoundActions(actions);
|
2022-07-06 19:06:20 +00:00
|
|
|
|
2022-03-04 21:14:52 +00:00
|
|
|
// Reducer
|
|
|
|
|
|
|
|
export function getEmptyState(
|
|
|
|
overrideState: Partial<StoriesStateType> = {}
|
|
|
|
): StoriesStateType {
|
|
|
|
return {
|
2022-08-23 17:37:48 +00:00
|
|
|
lastOpenedAtTimestamp: undefined,
|
2022-11-02 00:36:16 +00:00
|
|
|
addStoryData: undefined,
|
2022-03-04 21:14:52 +00:00
|
|
|
stories: [],
|
2022-11-10 04:24:42 +00:00
|
|
|
hasAllStoriesUnmuted: false,
|
2022-03-04 21:14:52 +00:00
|
|
|
...overrideState,
|
|
|
|
};
|
|
|
|
}
|
|
|
|
|
|
|
|
export function reducer(
|
|
|
|
state: Readonly<StoriesStateType> = getEmptyState(),
|
|
|
|
action: Readonly<StoriesActionType>
|
|
|
|
): StoriesStateType {
|
2023-08-09 00:53:06 +00:00
|
|
|
if (action.type === MARK_STORIES_TAB_VIEWED) {
|
|
|
|
return {
|
|
|
|
...state,
|
|
|
|
lastOpenedAtTimestamp: Date.now(),
|
|
|
|
replyState: undefined,
|
|
|
|
sendStoryModalData: undefined,
|
|
|
|
};
|
|
|
|
}
|
2022-08-19 18:05:31 +00:00
|
|
|
|
2023-08-09 00:53:06 +00:00
|
|
|
if (action.type === CLEAR_STORIES_TAB_STATE) {
|
2022-03-04 21:14:52 +00:00
|
|
|
return {
|
|
|
|
...state,
|
2022-08-19 18:05:31 +00:00
|
|
|
replyState: undefined,
|
|
|
|
sendStoryModalData: undefined,
|
2023-08-09 00:53:06 +00:00
|
|
|
selectedStoryData: undefined,
|
|
|
|
addStoryData: undefined,
|
2022-03-04 21:14:52 +00:00
|
|
|
};
|
|
|
|
}
|
|
|
|
|
2022-11-04 13:22:07 +00:00
|
|
|
if (action.type === STORY_REPLY_DELETED) {
|
|
|
|
return {
|
|
|
|
...state,
|
|
|
|
replyState: state.replyState
|
|
|
|
? {
|
|
|
|
...state.replyState,
|
|
|
|
replies: state.replyState.replies.filter(
|
|
|
|
reply => reply.id !== action.payload
|
|
|
|
),
|
|
|
|
}
|
|
|
|
: undefined,
|
|
|
|
};
|
|
|
|
}
|
|
|
|
|
2022-03-04 21:14:52 +00:00
|
|
|
if (action.type === 'MESSAGE_DELETED') {
|
2022-04-15 00:08:46 +00:00
|
|
|
const nextStories = state.stories.filter(
|
|
|
|
story => story.messageId !== action.payload.id
|
|
|
|
);
|
|
|
|
|
|
|
|
if (nextStories.length === state.stories.length) {
|
|
|
|
return state;
|
|
|
|
}
|
|
|
|
|
2022-03-04 21:14:52 +00:00
|
|
|
return {
|
|
|
|
...state,
|
2022-04-15 00:08:46 +00:00
|
|
|
stories: nextStories,
|
2022-03-04 21:14:52 +00:00
|
|
|
};
|
|
|
|
}
|
|
|
|
|
2022-03-29 01:10:08 +00:00
|
|
|
if (action.type === STORY_CHANGED) {
|
2022-03-04 21:14:52 +00:00
|
|
|
const newStory = pick(action.payload, [
|
|
|
|
'attachment',
|
2023-04-10 16:31:45 +00:00
|
|
|
'bodyRanges',
|
2022-07-01 00:52:03 +00:00
|
|
|
'canReplyToStory',
|
2022-03-04 21:14:52 +00:00
|
|
|
'conversationId',
|
2022-04-15 00:08:46 +00:00
|
|
|
'deletedForEveryone',
|
2022-09-09 18:35:00 +00:00
|
|
|
'expirationStartTimestamp',
|
|
|
|
'expireTimer',
|
2022-10-22 06:26:16 +00:00
|
|
|
'hasReplies',
|
|
|
|
'hasRepliesFromSelf',
|
2022-03-04 21:14:52 +00:00
|
|
|
'messageId',
|
2022-04-28 22:06:28 +00:00
|
|
|
'reactions',
|
2022-09-21 23:54:48 +00:00
|
|
|
'readAt',
|
2022-03-04 21:14:52 +00:00
|
|
|
'readStatus',
|
2022-04-15 00:08:46 +00:00
|
|
|
'sendStateByConversationId',
|
2022-03-04 21:14:52 +00:00
|
|
|
'source',
|
2023-08-16 20:54:39 +00:00
|
|
|
'sourceServiceId',
|
2022-11-23 20:52:36 +00:00
|
|
|
'sourceDevice',
|
2022-07-01 00:52:03 +00:00
|
|
|
'storyDistributionListId',
|
2022-03-04 21:14:52 +00:00
|
|
|
'timestamp',
|
2022-04-15 00:08:46 +00:00
|
|
|
'type',
|
2022-03-04 21:14:52 +00:00
|
|
|
]);
|
|
|
|
|
2022-04-21 00:29:37 +00:00
|
|
|
const prevStoryIndex = state.stories.findIndex(
|
2022-03-04 21:14:52 +00:00
|
|
|
existingStory => existingStory.messageId === newStory.messageId
|
|
|
|
);
|
2022-04-21 00:29:37 +00:00
|
|
|
if (prevStoryIndex >= 0) {
|
|
|
|
const prevStory = state.stories[prevStoryIndex];
|
2022-03-29 01:10:08 +00:00
|
|
|
|
2023-04-10 16:31:45 +00:00
|
|
|
// Stories rarely need to change, here are the following exceptions...
|
|
|
|
|
|
|
|
// These only change because of initialization order - these fields are updated
|
|
|
|
// after the model is created:
|
|
|
|
const bodyRangesChanged =
|
|
|
|
newStory.bodyRanges?.length !== prevStory.bodyRanges?.length;
|
|
|
|
const hasExpirationChanged =
|
|
|
|
(newStory.expirationStartTimestamp &&
|
|
|
|
!prevStory.expirationStartTimestamp) ||
|
|
|
|
(newStory.expireTimer && !prevStory.expireTimer);
|
|
|
|
|
|
|
|
// These reflect changes in status over time:
|
2022-04-21 00:29:37 +00:00
|
|
|
const isDownloadingAttachment = isDownloading(newStory.attachment);
|
|
|
|
const hasAttachmentDownloaded =
|
|
|
|
!isDownloaded(prevStory.attachment) &&
|
|
|
|
isDownloaded(newStory.attachment);
|
2022-08-04 00:38:41 +00:00
|
|
|
const hasAttachmentFailed =
|
|
|
|
hasFailed(newStory.attachment) && !hasFailed(prevStory.attachment);
|
2022-04-21 00:29:37 +00:00
|
|
|
const readStatusChanged = prevStory.readStatus !== newStory.readStatus;
|
2022-04-28 22:06:28 +00:00
|
|
|
const reactionsChanged =
|
|
|
|
prevStory.reactions?.length !== newStory.reactions?.length;
|
2022-07-01 00:52:03 +00:00
|
|
|
const hasBeenDeleted =
|
|
|
|
!prevStory.deletedForEveryone && newStory.deletedForEveryone;
|
|
|
|
const hasSendStateChanged = !isEqual(
|
|
|
|
prevStory.sendStateByConversationId,
|
|
|
|
newStory.sendStateByConversationId
|
|
|
|
);
|
2022-11-23 04:05:33 +00:00
|
|
|
const hasHasRepliesChanged =
|
|
|
|
prevStory.hasReplies !== newStory.hasReplies ||
|
|
|
|
prevStory.hasRepliesFromSelf !== newStory.hasRepliesFromSelf;
|
2022-03-29 01:10:08 +00:00
|
|
|
|
2022-04-21 00:29:37 +00:00
|
|
|
const shouldReplace =
|
2023-04-10 16:31:45 +00:00
|
|
|
bodyRangesChanged ||
|
2022-04-28 22:06:28 +00:00
|
|
|
isDownloadingAttachment ||
|
|
|
|
hasAttachmentDownloaded ||
|
2022-08-04 00:38:41 +00:00
|
|
|
hasAttachmentFailed ||
|
2022-07-01 00:52:03 +00:00
|
|
|
hasBeenDeleted ||
|
2022-10-17 23:30:03 +00:00
|
|
|
hasExpirationChanged ||
|
2022-07-01 00:52:03 +00:00
|
|
|
hasSendStateChanged ||
|
2022-04-28 22:06:28 +00:00
|
|
|
readStatusChanged ||
|
2022-11-23 04:05:33 +00:00
|
|
|
reactionsChanged ||
|
|
|
|
hasHasRepliesChanged;
|
|
|
|
|
2022-04-21 00:29:37 +00:00
|
|
|
if (!shouldReplace) {
|
2022-04-15 00:08:46 +00:00
|
|
|
return state;
|
|
|
|
}
|
|
|
|
|
2022-07-29 18:12:47 +00:00
|
|
|
if (hasBeenDeleted) {
|
|
|
|
return {
|
|
|
|
...state,
|
|
|
|
stories: state.stories.filter(
|
|
|
|
existingStory => existingStory.messageId !== newStory.messageId
|
|
|
|
),
|
|
|
|
};
|
|
|
|
}
|
|
|
|
|
2022-03-29 01:10:08 +00:00
|
|
|
return {
|
|
|
|
...state,
|
2022-04-21 00:29:37 +00:00
|
|
|
stories: replaceIndex(state.stories, prevStoryIndex, newStory),
|
2022-03-29 01:10:08 +00:00
|
|
|
};
|
2022-03-04 21:14:52 +00:00
|
|
|
}
|
|
|
|
|
2022-04-21 00:29:37 +00:00
|
|
|
// Adding a new story
|
2022-03-29 01:10:08 +00:00
|
|
|
const stories = [...state.stories, newStory].sort((a, b) =>
|
|
|
|
a.timestamp > b.timestamp ? 1 : -1
|
2022-03-04 21:14:52 +00:00
|
|
|
);
|
|
|
|
|
|
|
|
return {
|
|
|
|
...state,
|
|
|
|
stories,
|
|
|
|
};
|
|
|
|
}
|
|
|
|
|
2022-03-29 01:10:08 +00:00
|
|
|
if (action.type === MARK_STORY_READ) {
|
2022-09-21 23:54:48 +00:00
|
|
|
const { messageId, readAt } = action.payload;
|
|
|
|
|
2022-03-29 01:10:08 +00:00
|
|
|
return {
|
|
|
|
...state,
|
|
|
|
stories: state.stories.map(story => {
|
2022-09-21 23:54:48 +00:00
|
|
|
if (story.messageId === messageId) {
|
2022-03-29 01:10:08 +00:00
|
|
|
return {
|
|
|
|
...story,
|
2022-09-21 23:54:48 +00:00
|
|
|
readAt,
|
2022-03-29 01:10:08 +00:00
|
|
|
readStatus: ReadStatus.Viewed,
|
|
|
|
};
|
|
|
|
}
|
|
|
|
|
|
|
|
return story;
|
|
|
|
}),
|
|
|
|
};
|
|
|
|
}
|
|
|
|
|
2022-04-15 00:08:46 +00:00
|
|
|
if (action.type === LOAD_STORY_REPLIES) {
|
|
|
|
return {
|
|
|
|
...state,
|
2022-10-22 06:26:16 +00:00
|
|
|
stories: state.stories.map(story => {
|
|
|
|
if (story.messageId === action.payload.messageId) {
|
|
|
|
return {
|
|
|
|
...story,
|
|
|
|
hasReplies: action.payload.replies.length > 0,
|
|
|
|
hasRepliesFromSelf: action.payload.replies.some(
|
|
|
|
reply => reply.type === 'outgoing'
|
|
|
|
),
|
|
|
|
};
|
|
|
|
}
|
|
|
|
|
|
|
|
return story;
|
|
|
|
}),
|
2022-04-15 00:08:46 +00:00
|
|
|
replyState: action.payload,
|
|
|
|
};
|
|
|
|
}
|
|
|
|
|
2022-08-02 19:31:55 +00:00
|
|
|
if (action.type === 'MESSAGES_ADDED' && action.payload.isJustSent) {
|
|
|
|
const stories = action.payload.messages.filter(isStory);
|
|
|
|
if (!stories.length) {
|
|
|
|
return state;
|
|
|
|
}
|
|
|
|
|
|
|
|
const newStories = stories
|
|
|
|
.map(messageAttrs => getStoryDataFromMessageAttributes(messageAttrs))
|
|
|
|
.filter(isNotNil);
|
|
|
|
|
|
|
|
if (!newStories.length) {
|
|
|
|
return state;
|
|
|
|
}
|
|
|
|
|
|
|
|
return {
|
|
|
|
...state,
|
|
|
|
stories: [...state.stories, ...newStories],
|
|
|
|
};
|
|
|
|
}
|
|
|
|
|
2022-04-15 00:08:46 +00:00
|
|
|
// For live updating of the story replies
|
|
|
|
if (
|
|
|
|
action.type === 'MESSAGE_CHANGED' &&
|
|
|
|
state.replyState &&
|
|
|
|
state.replyState.messageId === action.payload.data.storyId
|
|
|
|
) {
|
|
|
|
const { replyState } = state;
|
|
|
|
const messageIndex = replyState.replies.findIndex(
|
|
|
|
reply => reply.id === action.payload.id
|
|
|
|
);
|
|
|
|
|
|
|
|
// New message
|
|
|
|
if (messageIndex < 0) {
|
2022-10-26 00:23:59 +00:00
|
|
|
const storyIndex = state.stories.findIndex(
|
|
|
|
story => story.messageId === replyState.messageId
|
|
|
|
);
|
|
|
|
|
|
|
|
const stories =
|
|
|
|
storyIndex >= 0
|
|
|
|
? replaceIndex(state.stories, storyIndex, {
|
|
|
|
...state.stories[storyIndex],
|
|
|
|
hasReplies: true,
|
|
|
|
hasRepliesFromSelf:
|
|
|
|
state.stories[storyIndex].hasRepliesFromSelf ||
|
|
|
|
state.stories[storyIndex].conversationId ===
|
|
|
|
action.payload.conversationId,
|
|
|
|
})
|
|
|
|
: state.stories;
|
|
|
|
|
2022-04-15 00:08:46 +00:00
|
|
|
return {
|
|
|
|
...state,
|
2022-10-26 00:23:59 +00:00
|
|
|
stories,
|
2022-04-15 00:08:46 +00:00
|
|
|
replyState: {
|
|
|
|
messageId: replyState.messageId,
|
|
|
|
replies: [...replyState.replies, action.payload.data],
|
|
|
|
},
|
|
|
|
};
|
|
|
|
}
|
|
|
|
|
|
|
|
// Changed message, also handles DOE
|
|
|
|
return {
|
|
|
|
...state,
|
|
|
|
replyState: {
|
|
|
|
messageId: replyState.messageId,
|
|
|
|
replies: replaceIndex(
|
|
|
|
replyState.replies,
|
|
|
|
messageIndex,
|
|
|
|
action.payload.data
|
|
|
|
),
|
|
|
|
},
|
|
|
|
};
|
|
|
|
}
|
|
|
|
|
2022-07-01 00:52:03 +00:00
|
|
|
if (action.type === DOE_STORY) {
|
|
|
|
return {
|
|
|
|
...state,
|
2023-01-27 17:35:58 +00:00
|
|
|
selectedStoryData: undefined,
|
2022-07-29 18:12:47 +00:00
|
|
|
stories: state.stories.filter(
|
|
|
|
existingStory => existingStory.messageId !== action.payload
|
|
|
|
),
|
2022-07-01 00:52:03 +00:00
|
|
|
};
|
|
|
|
}
|
|
|
|
|
2022-07-06 19:06:20 +00:00
|
|
|
if (action.type === VIEW_STORY) {
|
|
|
|
return {
|
|
|
|
...state,
|
2022-08-22 17:44:23 +00:00
|
|
|
selectedStoryData: action.payload,
|
2022-07-06 19:06:20 +00:00
|
|
|
};
|
|
|
|
}
|
|
|
|
|
2022-10-20 19:16:37 +00:00
|
|
|
if (action.type === REMOVE_ALL_STORIES) {
|
|
|
|
return getEmptyState();
|
|
|
|
}
|
|
|
|
|
2022-08-11 22:26:26 +00:00
|
|
|
if (action.type === QUEUE_STORY_DOWNLOAD) {
|
|
|
|
const storyIndex = state.stories.findIndex(
|
|
|
|
story => story.messageId === action.payload
|
|
|
|
);
|
|
|
|
|
|
|
|
if (storyIndex < 0) {
|
|
|
|
return state;
|
|
|
|
}
|
|
|
|
|
|
|
|
const existingStory = state.stories[storyIndex];
|
|
|
|
|
|
|
|
return {
|
|
|
|
...state,
|
|
|
|
stories: replaceIndex(state.stories, storyIndex, {
|
|
|
|
...existingStory,
|
|
|
|
startedDownload: true,
|
|
|
|
}),
|
|
|
|
};
|
|
|
|
}
|
|
|
|
|
2022-08-19 18:05:31 +00:00
|
|
|
if (action.type === SEND_STORY_MODAL_OPEN_STATE_CHANGED) {
|
|
|
|
if (action.payload) {
|
|
|
|
return {
|
|
|
|
...state,
|
2022-11-11 04:10:30 +00:00
|
|
|
sendStoryModalData: {},
|
2022-08-19 18:05:31 +00:00
|
|
|
};
|
|
|
|
}
|
|
|
|
|
|
|
|
return {
|
|
|
|
...state,
|
|
|
|
sendStoryModalData: undefined,
|
|
|
|
};
|
|
|
|
}
|
|
|
|
|
|
|
|
if (action.type === LIST_MEMBERS_VERIFIED) {
|
2022-11-11 04:10:30 +00:00
|
|
|
const { sendStoryModalData } = state;
|
2023-08-10 16:43:33 +00:00
|
|
|
const { conversationId, distributionId, serviceIds } = action.payload;
|
2022-08-19 18:05:31 +00:00
|
|
|
|
2022-11-11 04:10:30 +00:00
|
|
|
const existing =
|
|
|
|
sendStoryModalData && getOwn(sendStoryModalData, conversationId);
|
|
|
|
|
|
|
|
if (distributionId) {
|
2023-08-10 16:43:33 +00:00
|
|
|
const existingServiceIds =
|
|
|
|
existing?.byDistributionId?.[distributionId]?.serviceIds;
|
2022-11-11 04:10:30 +00:00
|
|
|
|
2023-08-10 16:43:33 +00:00
|
|
|
const finalServiceIds = Array.from(
|
|
|
|
new Set([...(existingServiceIds || []), ...serviceIds])
|
2022-11-11 04:10:30 +00:00
|
|
|
);
|
|
|
|
|
|
|
|
return {
|
|
|
|
...state,
|
|
|
|
sendStoryModalData: {
|
|
|
|
...sendStoryModalData,
|
|
|
|
[conversationId]: {
|
|
|
|
...existing,
|
2023-08-10 16:43:33 +00:00
|
|
|
serviceIds: existing?.serviceIds || [],
|
2022-11-11 04:10:30 +00:00
|
|
|
byDistributionId: {
|
|
|
|
...existing?.byDistributionId,
|
|
|
|
[distributionId]: {
|
2023-08-10 16:43:33 +00:00
|
|
|
serviceIds: finalServiceIds,
|
2022-11-11 04:10:30 +00:00
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
};
|
|
|
|
}
|
|
|
|
|
2023-08-10 16:43:33 +00:00
|
|
|
const finalServiceIds = Array.from(
|
|
|
|
new Set([...(existing?.serviceIds || []), ...serviceIds])
|
2022-08-19 18:05:31 +00:00
|
|
|
);
|
|
|
|
|
|
|
|
return {
|
|
|
|
...state,
|
|
|
|
sendStoryModalData: {
|
|
|
|
...sendStoryModalData,
|
2022-11-11 04:10:30 +00:00
|
|
|
[conversationId]: {
|
|
|
|
...existing,
|
2023-08-10 16:43:33 +00:00
|
|
|
serviceIds: finalServiceIds,
|
2022-11-11 04:10:30 +00:00
|
|
|
},
|
2022-08-19 18:05:31 +00:00
|
|
|
},
|
|
|
|
};
|
|
|
|
}
|
|
|
|
|
2022-11-02 00:36:16 +00:00
|
|
|
if (action.type === SET_ADD_STORY_DATA) {
|
|
|
|
return {
|
|
|
|
...state,
|
|
|
|
addStoryData: action.payload,
|
|
|
|
};
|
|
|
|
}
|
|
|
|
|
|
|
|
if (action.type === SET_STORY_SENDING) {
|
|
|
|
const existing = state.addStoryData;
|
|
|
|
|
|
|
|
if (!existing) {
|
|
|
|
log.warn(
|
|
|
|
'stories/reducer: Set story sending, but no existing addStoryData'
|
|
|
|
);
|
|
|
|
return state;
|
|
|
|
}
|
|
|
|
|
|
|
|
return {
|
|
|
|
...state,
|
|
|
|
addStoryData: {
|
|
|
|
...existing,
|
|
|
|
sending: action.payload,
|
|
|
|
},
|
|
|
|
};
|
|
|
|
}
|
|
|
|
|
2022-11-10 04:24:42 +00:00
|
|
|
if (action.type === SET_HAS_ALL_STORIES_UNMUTED) {
|
|
|
|
return {
|
|
|
|
...state,
|
|
|
|
hasAllStoriesUnmuted: action.payload,
|
|
|
|
};
|
|
|
|
}
|
|
|
|
|
2023-03-20 22:23:53 +00:00
|
|
|
if (action.type === TARGETED_CONVERSATION_CHANGED) {
|
2023-03-07 22:59:44 +00:00
|
|
|
return {
|
|
|
|
...state,
|
|
|
|
replyState: undefined,
|
|
|
|
sendStoryModalData: undefined,
|
|
|
|
selectedStoryData: undefined,
|
|
|
|
};
|
|
|
|
}
|
|
|
|
|
2022-03-04 21:14:52 +00:00
|
|
|
return state;
|
|
|
|
}
|