2023-01-03 19:55:46 +00:00
|
|
|
// Copyright 2019 Signal Messenger, LLC
|
2020-10-30 20:34:04 +00:00
|
|
|
// SPDX-License-Identifier: AGPL-3.0-only
|
|
|
|
|
2021-10-26 19:15:33 +00:00
|
|
|
import type { ThunkAction } from 'redux-thunk';
|
2019-05-31 22:42:01 +00:00
|
|
|
import {
|
|
|
|
difference,
|
|
|
|
fromPairs,
|
|
|
|
omit,
|
|
|
|
orderBy,
|
|
|
|
pick,
|
|
|
|
values,
|
|
|
|
without,
|
|
|
|
} from 'lodash';
|
2020-12-04 20:41:40 +00:00
|
|
|
|
2023-04-22 01:52:25 +00:00
|
|
|
import { clipboard } from 'electron';
|
2023-01-13 20:07:26 +00:00
|
|
|
import type { ReadonlyDeep } from 'type-fest';
|
2022-12-05 22:56:23 +00:00
|
|
|
import type { AttachmentType } from '../../types/Attachment';
|
2021-10-26 19:15:33 +00:00
|
|
|
import type { StateType as RootStateType } from '../reducer';
|
2021-03-03 20:09:58 +00:00
|
|
|
import * as groups from '../../groups';
|
2021-07-19 19:26:06 +00:00
|
|
|
import * as log from '../../logging/log';
|
2020-12-09 23:21:34 +00:00
|
|
|
import { calling } from '../../services/calling';
|
2020-12-04 20:41:40 +00:00
|
|
|
import { getOwn } from '../../util/getOwn';
|
2022-09-15 19:17:15 +00:00
|
|
|
import { assertDev, strictAssert } from '../../util/assert';
|
2022-12-21 18:41:48 +00:00
|
|
|
import { drop } from '../../util/drop';
|
2022-11-16 20:18:02 +00:00
|
|
|
import type { DurationInSeconds } from '../../util/durations';
|
2021-06-25 23:52:56 +00:00
|
|
|
import * as universalExpireTimer from '../../util/universalExpireTimer';
|
2022-12-14 18:12:04 +00:00
|
|
|
import * as Attachment from '../../types/Attachment';
|
|
|
|
import { isFileDangerous } from '../../util/isFileDangerous';
|
2022-08-16 23:59:11 +00:00
|
|
|
import type {
|
2022-11-11 04:10:30 +00:00
|
|
|
ShowSendAnywayDialogActionType,
|
2022-08-16 23:59:11 +00:00
|
|
|
ToggleProfileEditorErrorActionType,
|
|
|
|
} from './globalModals';
|
|
|
|
import {
|
|
|
|
SHOW_SEND_ANYWAY_DIALOG,
|
|
|
|
TOGGLE_PROFILE_EDITOR_ERROR,
|
|
|
|
} from './globalModals';
|
2022-11-11 04:10:30 +00:00
|
|
|
import {
|
|
|
|
MODIFY_LIST,
|
|
|
|
DELETE_LIST,
|
|
|
|
HIDE_MY_STORIES_FROM,
|
|
|
|
VIEWERS_CHANGED,
|
|
|
|
} from './storyDistributionLists';
|
|
|
|
import type { StoryDistributionListsActionType } from './storyDistributionLists';
|
2022-04-05 00:38:22 +00:00
|
|
|
import type {
|
|
|
|
UUIDFetchStateKeyType,
|
|
|
|
UUIDFetchStateType,
|
|
|
|
} from '../../util/uuidFetchState';
|
2021-06-17 17:15:10 +00:00
|
|
|
|
2021-10-26 19:15:33 +00:00
|
|
|
import type {
|
2021-05-28 16:15:17 +00:00
|
|
|
AvatarColorType,
|
|
|
|
ConversationColorType,
|
|
|
|
CustomColorType,
|
|
|
|
} from '../../types/Colors';
|
2021-10-26 19:15:33 +00:00
|
|
|
import type {
|
2021-06-17 17:15:10 +00:00
|
|
|
ConversationAttributesType,
|
2023-04-20 16:31:59 +00:00
|
|
|
DraftEditMessageType,
|
|
|
|
LastMessageStatus,
|
2021-06-17 17:15:10 +00:00
|
|
|
MessageAttributesType,
|
|
|
|
} from '../../model-types.d';
|
2023-04-10 16:31:45 +00:00
|
|
|
import type {
|
2023-04-14 18:16:28 +00:00
|
|
|
DraftBodyRanges,
|
2023-04-10 16:31:45 +00:00
|
|
|
HydratedBodyRangesType,
|
|
|
|
} from '../../types/BodyRange';
|
2021-06-17 17:15:10 +00:00
|
|
|
import { CallMode } from '../../types/Calling';
|
2021-10-26 19:15:33 +00:00
|
|
|
import type { MediaItemType } from '../../types/MediaItem';
|
2021-10-26 22:59:08 +00:00
|
|
|
import type { UUIDStringType } from '../../types/UUID';
|
2022-11-11 04:10:30 +00:00
|
|
|
import { MY_STORY_ID, StorySendMode } from '../../types/Stories';
|
2022-11-22 18:43:43 +00:00
|
|
|
import * as Errors from '../../types/errors';
|
2021-03-03 20:09:58 +00:00
|
|
|
import {
|
|
|
|
getGroupSizeRecommendedLimit,
|
|
|
|
getGroupSizeHardLimit,
|
|
|
|
} from '../../groups/limits';
|
2021-07-29 14:29:07 +00:00
|
|
|
import { isMessageUnread } from '../../util/isMessageUnread';
|
2021-03-11 21:29:31 +00:00
|
|
|
import { toggleSelectedContactForGroupAddition } from '../../groups/toggleSelectedContactForGroupAddition';
|
2021-10-26 19:15:33 +00:00
|
|
|
import type { GroupNameCollisionsWithIdsByTitle } from '../../util/groupMemberNameCollisions';
|
2021-06-01 23:30:25 +00:00
|
|
|
import { ContactSpoofingType } from '../../util/contactSpoofing';
|
2021-07-19 19:26:06 +00:00
|
|
|
import { writeProfile } from '../../services/writeProfile';
|
2021-08-31 20:58:39 +00:00
|
|
|
import {
|
2022-05-31 19:46:56 +00:00
|
|
|
getConversationUuidsStoppingSend,
|
2022-02-16 18:36:21 +00:00
|
|
|
getConversationIdsStoppedForVerification,
|
2023-04-20 16:31:59 +00:00
|
|
|
getConversationSelector,
|
2021-08-31 20:58:39 +00:00
|
|
|
getMe,
|
2022-12-09 19:11:14 +00:00
|
|
|
getMessagesByConversation,
|
2021-08-31 20:58:39 +00:00
|
|
|
} from '../selectors/conversations';
|
2022-03-16 00:14:20 +00:00
|
|
|
import type { AvatarDataType, AvatarUpdateType } from '../../types/Avatar';
|
2021-10-26 19:15:33 +00:00
|
|
|
import { getDefaultAvatars } from '../../types/Avatar';
|
2021-08-06 00:17:05 +00:00
|
|
|
import { getAvatarData } from '../../util/getAvatarData';
|
|
|
|
import { isSameAvatarData } from '../../util/isSameAvatarData';
|
2021-09-21 22:37:10 +00:00
|
|
|
import { longRunningTaskWrapper } from '../../util/longRunningTaskWrapper';
|
2021-11-01 19:13:35 +00:00
|
|
|
import {
|
|
|
|
ComposerStep,
|
2022-02-16 18:36:21 +00:00
|
|
|
ConversationVerificationState,
|
2021-11-01 19:13:35 +00:00
|
|
|
OneTimeModalState,
|
2023-03-20 22:23:53 +00:00
|
|
|
TargetedMessageSource,
|
2021-11-01 19:13:35 +00:00
|
|
|
} from './conversationsEnums';
|
2022-10-03 23:43:44 +00:00
|
|
|
import { markViewed as messageUpdaterMarkViewed } from '../../services/MessageUpdater';
|
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';
|
2019-01-14 21:49:58 +00:00
|
|
|
|
2021-10-26 19:15:33 +00:00
|
|
|
import type { NoopActionType } from './noop';
|
2022-12-20 01:04:47 +00:00
|
|
|
import {
|
|
|
|
conversationJobQueue,
|
|
|
|
conversationQueueJobEnum,
|
|
|
|
} from '../../jobs/conversationJobQueue';
|
2022-03-11 22:31:21 +00:00
|
|
|
import type { TimelineMessageLoadingState } from '../../util/timelineUtil';
|
2022-10-03 23:43:44 +00:00
|
|
|
import {
|
|
|
|
isDirectConversation,
|
|
|
|
isGroup,
|
2022-12-05 22:56:23 +00:00
|
|
|
isGroupV2,
|
2022-10-03 23:43:44 +00:00
|
|
|
} from '../../util/whatTypeOfConversation';
|
2022-05-10 20:19:58 +00:00
|
|
|
import { missingCaseError } from '../../util/missingCaseError';
|
2022-10-03 23:43:44 +00:00
|
|
|
import { viewSyncJobQueue } from '../../jobs/viewSyncJobQueue';
|
|
|
|
import { ReadStatus } from '../../messages/MessageReadStatus';
|
2023-05-12 18:20:10 +00:00
|
|
|
import { isIncoming, processBodyRanges } from '../selectors/message';
|
2022-12-21 03:25:10 +00:00
|
|
|
import { getActiveCallState } from '../selectors/calling';
|
2022-12-05 22:56:23 +00:00
|
|
|
import { sendDeleteForEveryoneMessage } from '../../util/sendDeleteForEveryoneMessage';
|
|
|
|
import type { ShowToastActionType } from './toast';
|
2022-12-15 00:48:36 +00:00
|
|
|
import { SHOW_TOAST } from './toast';
|
|
|
|
import { ToastType } from '../../types/Toast';
|
2023-06-02 17:54:36 +00:00
|
|
|
import { isMemberRequestingToJoin } from '../../util/groupMembershipUtils';
|
2022-12-05 22:56:23 +00:00
|
|
|
import { removePendingMember } from '../../util/removePendingMember';
|
|
|
|
import { denyPendingApprovalRequest } from '../../util/denyPendingApprovalRequest';
|
2022-12-06 19:03:09 +00:00
|
|
|
import { SignalService as Proto } from '../../protobuf';
|
|
|
|
import { addReportSpamJob } from '../../jobs/helpers/addReportSpamJob';
|
|
|
|
import { reportSpamJobQueue } from '../../jobs/reportSpamJobQueue';
|
2022-12-08 06:41:37 +00:00
|
|
|
import {
|
|
|
|
modifyGroupV2,
|
2022-12-16 03:12:05 +00:00
|
|
|
buildAddMembersChange,
|
2022-12-08 06:41:37 +00:00
|
|
|
buildPromotePendingAdminApprovalMemberChange,
|
2022-12-16 03:12:05 +00:00
|
|
|
buildUpdateAttributesChange,
|
2022-12-08 06:41:37 +00:00
|
|
|
initiateMigrationToGroupV2 as doInitiateMigrationToGroupV2,
|
|
|
|
} from '../../groups';
|
2022-12-09 19:11:14 +00:00
|
|
|
import { getMessageById } from '../../messages/getMessageById';
|
2022-12-21 20:44:23 +00:00
|
|
|
import type { PanelRenderType, PanelRequestType } from '../../types/Panels';
|
2022-12-20 01:04:47 +00:00
|
|
|
import type { ConversationQueueJobData } from '../../jobs/conversationJobQueue';
|
|
|
|
import { isOlderThan } from '../../util/timestamp';
|
|
|
|
import { DAY } from '../../util/durations';
|
2022-12-16 03:12:05 +00:00
|
|
|
import { isNotNil } from '../../util/isNotNil';
|
2022-12-21 20:44:23 +00:00
|
|
|
import { PanelType } from '../../types/Panels';
|
2022-12-21 03:25:10 +00:00
|
|
|
import { startConversation } from '../../util/startConversation';
|
2023-05-16 17:37:12 +00:00
|
|
|
import { getMessageSentTimestamp } from '../../util/getMessageSentTimestamp';
|
2023-01-02 21:34:41 +00:00
|
|
|
import { UUIDKind } from '../../types/UUID';
|
2023-02-03 22:21:07 +00:00
|
|
|
import { removeLinkPreview } from '../../services/LinkPreview';
|
2023-01-02 21:34:41 +00:00
|
|
|
import type {
|
|
|
|
ReplaceAttachmentsActionType,
|
2023-03-02 20:55:40 +00:00
|
|
|
ResetComposerActionType,
|
2023-01-02 21:34:41 +00:00
|
|
|
SetFocusActionType,
|
|
|
|
SetQuotedMessageActionType,
|
|
|
|
} from './composer';
|
|
|
|
import {
|
2023-04-20 16:31:59 +00:00
|
|
|
SET_FOCUS,
|
2023-01-02 21:34:41 +00:00
|
|
|
replaceAttachments,
|
|
|
|
setComposerFocus,
|
|
|
|
setQuoteByMessageId,
|
|
|
|
resetComposer,
|
2023-03-02 20:55:40 +00:00
|
|
|
handleLeaveConversation,
|
2023-01-02 21:34:41 +00:00
|
|
|
} from './composer';
|
2023-02-06 17:24:34 +00:00
|
|
|
import { ReceiptType } from '../../types/Receipt';
|
2023-03-20 22:23:53 +00:00
|
|
|
import { sortByMessageOrder } from '../../util/maybeForwardMessages';
|
2023-05-09 15:51:11 +00:00
|
|
|
import { Sound, SoundType } from '../../util/Sound';
|
2023-05-12 00:27:19 +00:00
|
|
|
import { canEditMessage } from '../../util/canEditMessage';
|
2023-08-09 00:53:06 +00:00
|
|
|
import type { ChangeNavTabActionType } from './nav';
|
|
|
|
import { CHANGE_NAV_TAB, NavTab, actions as navActions } from './nav';
|
2021-06-17 17:15:10 +00:00
|
|
|
|
2019-01-14 21:49:58 +00:00
|
|
|
// State
|
|
|
|
|
2023-01-13 20:07:26 +00:00
|
|
|
export type DBConversationType = ReadonlyDeep<{
|
2020-02-06 19:52:05 +00:00
|
|
|
id: string;
|
|
|
|
activeAt?: number;
|
2021-04-05 22:18:19 +00:00
|
|
|
lastMessage?: string | null;
|
2020-02-06 19:52:05 +00:00
|
|
|
type: string;
|
2023-01-13 20:07:26 +00:00
|
|
|
}>;
|
2020-09-24 20:57:54 +00:00
|
|
|
|
2021-06-17 17:15:10 +00:00
|
|
|
export const InteractionModes = ['mouse', 'keyboard'] as const;
|
2023-01-13 20:07:26 +00:00
|
|
|
export type InteractionModeType = ReadonlyDeep<typeof InteractionModes[number]>;
|
2020-09-24 20:57:54 +00:00
|
|
|
|
2023-03-20 22:23:53 +00:00
|
|
|
export type MessageTimestamps = ReadonlyDeep<
|
|
|
|
Pick<MessageAttributesType, 'sent_at' | 'received_at'>
|
|
|
|
>;
|
|
|
|
|
2023-01-13 20:07:26 +00:00
|
|
|
// eslint-disable-next-line local-rules/type-alias-readonlydeep
|
2021-06-17 17:15:10 +00:00
|
|
|
export type MessageType = MessageAttributesType & {
|
|
|
|
interactionType?: InteractionModeType;
|
|
|
|
};
|
2023-01-13 20:07:26 +00:00
|
|
|
// eslint-disable-next-line local-rules/type-alias-readonlydeep
|
2021-11-11 23:45:47 +00:00
|
|
|
export type MessageWithUIFieldsType = MessageAttributesType & {
|
|
|
|
displayLimit?: number;
|
2023-05-10 00:40:19 +00:00
|
|
|
isSpoilerExpanded?: Record<number, boolean>;
|
2021-11-11 23:45:47 +00:00
|
|
|
};
|
2021-06-17 17:15:10 +00:00
|
|
|
|
|
|
|
export const ConversationTypes = ['direct', 'group'] as const;
|
2023-01-13 20:07:26 +00:00
|
|
|
export type ConversationTypeType = ReadonlyDeep<
|
|
|
|
typeof ConversationTypes[number]
|
|
|
|
>;
|
2020-09-24 20:57:54 +00:00
|
|
|
|
2023-01-13 20:07:26 +00:00
|
|
|
export type LastMessageType = ReadonlyDeep<
|
2022-12-23 00:13:23 +00:00
|
|
|
| {
|
2023-04-10 16:31:45 +00:00
|
|
|
deletedForEveryone: false;
|
|
|
|
author?: string;
|
|
|
|
bodyRanges?: HydratedBodyRangesType;
|
|
|
|
prefix?: string;
|
2022-12-23 00:13:23 +00:00
|
|
|
status?: LastMessageStatus;
|
|
|
|
text: string;
|
|
|
|
}
|
|
|
|
| { deletedForEveryone: true }
|
|
|
|
>;
|
2023-04-10 16:31:45 +00:00
|
|
|
export type DraftPreviewType = ReadonlyDeep<{
|
|
|
|
text: string;
|
|
|
|
prefix?: string;
|
|
|
|
bodyRanges?: HydratedBodyRangesType;
|
|
|
|
}>;
|
2022-12-23 00:13:23 +00:00
|
|
|
|
2023-01-13 20:07:26 +00:00
|
|
|
export type ConversationType = ReadonlyDeep<
|
|
|
|
{
|
|
|
|
id: string;
|
|
|
|
uuid?: UUIDStringType;
|
|
|
|
pni?: UUIDStringType;
|
|
|
|
e164?: string;
|
|
|
|
name?: string;
|
|
|
|
systemGivenName?: string;
|
|
|
|
systemFamilyName?: string;
|
2023-02-13 22:40:11 +00:00
|
|
|
systemNickname?: string;
|
2023-01-13 20:07:26 +00:00
|
|
|
familyName?: string;
|
|
|
|
firstName?: string;
|
|
|
|
profileName?: string;
|
|
|
|
username?: string;
|
|
|
|
about?: string;
|
|
|
|
aboutText?: string;
|
|
|
|
aboutEmoji?: string;
|
|
|
|
avatars?: ReadonlyArray<AvatarDataType>;
|
|
|
|
avatarPath?: string;
|
|
|
|
avatarHash?: string;
|
|
|
|
profileAvatarPath?: string;
|
|
|
|
unblurredAvatarPath?: string;
|
|
|
|
areWeAdmin?: boolean;
|
|
|
|
areWePending?: boolean;
|
|
|
|
areWePendingApproval?: boolean;
|
|
|
|
canChangeTimer?: boolean;
|
|
|
|
canEditGroupInfo?: boolean;
|
|
|
|
canAddNewMembers?: boolean;
|
|
|
|
color?: AvatarColorType;
|
|
|
|
conversationColor?: ConversationColorType;
|
|
|
|
customColor?: CustomColorType;
|
|
|
|
customColorId?: string;
|
|
|
|
discoveredUnregisteredAt?: number;
|
|
|
|
hideStory?: boolean;
|
2023-06-29 18:40:00 +00:00
|
|
|
hiddenFromConversationSearch?: boolean;
|
2023-01-13 20:07:26 +00:00
|
|
|
isArchived?: boolean;
|
|
|
|
isBlocked?: boolean;
|
2023-04-05 20:48:00 +00:00
|
|
|
removalStage?: 'justNotification' | 'messageRequest';
|
2023-01-13 20:07:26 +00:00
|
|
|
isGroupV1AndDisabled?: boolean;
|
|
|
|
isPinned?: boolean;
|
|
|
|
isUntrusted?: boolean;
|
|
|
|
isVerified?: boolean;
|
|
|
|
activeAt?: number;
|
|
|
|
timestamp?: number;
|
|
|
|
inboxPosition?: number;
|
|
|
|
left?: boolean;
|
|
|
|
lastMessage?: LastMessageType;
|
|
|
|
markedUnread?: boolean;
|
|
|
|
phoneNumber?: string;
|
|
|
|
membersCount?: number;
|
|
|
|
hasMessages?: boolean;
|
|
|
|
accessControlAddFromInviteLink?: number;
|
|
|
|
accessControlAttributes?: number;
|
|
|
|
accessControlMembers?: number;
|
|
|
|
announcementsOnly?: boolean;
|
|
|
|
announcementsOnlyReady?: boolean;
|
|
|
|
expireTimer?: DurationInSeconds;
|
|
|
|
memberships?: ReadonlyArray<{
|
|
|
|
uuid: UUIDStringType;
|
|
|
|
isAdmin: boolean;
|
|
|
|
}>;
|
|
|
|
pendingMemberships?: ReadonlyArray<{
|
|
|
|
uuid: UUIDStringType;
|
|
|
|
addedByUserId?: UUIDStringType;
|
|
|
|
}>;
|
|
|
|
pendingApprovalMemberships?: ReadonlyArray<{
|
|
|
|
uuid: UUIDStringType;
|
|
|
|
}>;
|
|
|
|
bannedMemberships?: ReadonlyArray<UUIDStringType>;
|
|
|
|
muteExpiresAt?: number;
|
|
|
|
dontNotifyForMentionsIfMuted?: boolean;
|
|
|
|
isMe: boolean;
|
|
|
|
lastUpdated?: number;
|
|
|
|
// This is used by the CompositionInput for @mentions
|
|
|
|
sortedGroupMembers?: ReadonlyArray<ConversationType>;
|
|
|
|
title: string;
|
|
|
|
titleNoDefault?: string;
|
|
|
|
searchableTitle?: string;
|
|
|
|
unreadCount?: number;
|
2023-05-23 21:59:07 +00:00
|
|
|
unreadMentionsCount?: number;
|
2023-01-13 20:07:26 +00:00
|
|
|
isSelected?: boolean;
|
|
|
|
isFetchingUUID?: boolean;
|
|
|
|
typingContactId?: string;
|
|
|
|
recentMediaItems?: ReadonlyArray<MediaItemType>;
|
|
|
|
profileSharing?: boolean;
|
|
|
|
|
|
|
|
shouldShowDraft?: boolean;
|
2023-04-10 16:31:45 +00:00
|
|
|
// Full information for re-hydrating composition area
|
2023-01-13 20:07:26 +00:00
|
|
|
draftText?: string;
|
2023-04-20 16:31:59 +00:00
|
|
|
draftEditMessage?: DraftEditMessageType;
|
2023-04-14 18:16:28 +00:00
|
|
|
draftBodyRanges?: DraftBodyRanges;
|
2023-04-10 16:31:45 +00:00
|
|
|
// Summary for the left pane
|
|
|
|
draftPreview?: DraftPreviewType;
|
2023-01-13 20:07:26 +00:00
|
|
|
|
|
|
|
sharedGroupNames: ReadonlyArray<string>;
|
|
|
|
groupDescription?: string;
|
|
|
|
groupVersion?: 1 | 2;
|
|
|
|
groupId?: string;
|
|
|
|
groupLink?: string;
|
|
|
|
messageRequestsEnabled?: boolean;
|
|
|
|
acceptedMessageRequest: boolean;
|
|
|
|
secretParams?: string;
|
|
|
|
publicParams?: string;
|
|
|
|
profileKey?: string;
|
|
|
|
voiceNotePlaybackRate?: number;
|
|
|
|
|
|
|
|
badges: ReadonlyArray<
|
|
|
|
| {
|
|
|
|
id: string;
|
|
|
|
}
|
|
|
|
| {
|
|
|
|
id: string;
|
|
|
|
expiresAt: number;
|
|
|
|
isVisible: boolean;
|
|
|
|
}
|
|
|
|
>;
|
|
|
|
} & (
|
2021-11-02 23:01:13 +00:00
|
|
|
| {
|
2023-01-13 20:07:26 +00:00
|
|
|
type: 'direct';
|
|
|
|
storySendMode?: undefined;
|
|
|
|
acknowledgedGroupNameCollisions?: undefined;
|
2021-11-02 23:01:13 +00:00
|
|
|
}
|
|
|
|
| {
|
2023-01-13 20:07:26 +00:00
|
|
|
type: 'group';
|
|
|
|
storySendMode: StorySendMode;
|
|
|
|
acknowledgedGroupNameCollisions: GroupNameCollisionsWithIdsByTitle;
|
2021-11-02 23:01:13 +00:00
|
|
|
}
|
2023-01-13 20:07:26 +00:00
|
|
|
)
|
|
|
|
>;
|
|
|
|
export type ProfileDataType = ReadonlyDeep<
|
|
|
|
{
|
|
|
|
firstName: string;
|
|
|
|
} & Pick<ConversationType, 'aboutEmoji' | 'aboutText' | 'familyName'>
|
|
|
|
>;
|
2021-07-19 19:26:06 +00:00
|
|
|
|
2023-01-13 20:07:26 +00:00
|
|
|
export type ConversationLookupType = ReadonlyDeep<{
|
2019-01-14 21:49:58 +00:00
|
|
|
[key: string]: ConversationType;
|
2023-01-13 20:07:26 +00:00
|
|
|
}>;
|
|
|
|
export type CustomError = ReadonlyDeep<
|
|
|
|
Error & {
|
|
|
|
identifier?: string;
|
|
|
|
number?: string;
|
|
|
|
}
|
|
|
|
>;
|
2019-05-31 22:42:01 +00:00
|
|
|
|
2023-01-13 20:07:26 +00:00
|
|
|
type MessagePointerType = ReadonlyDeep<{
|
2019-05-31 22:42:01 +00:00
|
|
|
id: string;
|
|
|
|
received_at: number;
|
2021-01-13 16:32:18 +00:00
|
|
|
sent_at?: number;
|
2023-01-13 20:07:26 +00:00
|
|
|
}>;
|
|
|
|
type MessageMetricsType = ReadonlyDeep<{
|
2019-05-31 22:42:01 +00:00
|
|
|
newest?: MessagePointerType;
|
|
|
|
oldest?: MessagePointerType;
|
2022-04-22 18:35:14 +00:00
|
|
|
oldestUnseen?: MessagePointerType;
|
|
|
|
totalUnseen: number;
|
2023-01-13 20:07:26 +00:00
|
|
|
}>;
|
2019-05-31 22:42:01 +00:00
|
|
|
|
2023-01-13 20:07:26 +00:00
|
|
|
// eslint-disable-next-line local-rules/type-alias-readonlydeep
|
2019-03-20 17:42:28 +00:00
|
|
|
export type MessageLookupType = {
|
2021-11-11 23:45:47 +00:00
|
|
|
[key: string]: MessageWithUIFieldsType;
|
2019-03-20 17:42:28 +00:00
|
|
|
};
|
2023-01-13 20:07:26 +00:00
|
|
|
export type ConversationMessageType = ReadonlyDeep<{
|
2019-05-31 22:42:01 +00:00
|
|
|
isNearBottom?: boolean;
|
2022-05-11 22:41:45 +00:00
|
|
|
messageChangeCounter: number;
|
2022-12-22 00:07:02 +00:00
|
|
|
messageIds: ReadonlyArray<string>;
|
2022-03-11 22:31:21 +00:00
|
|
|
messageLoadingState?: undefined | TimelineMessageLoadingState;
|
2019-05-31 22:42:01 +00:00
|
|
|
metrics: MessageMetricsType;
|
|
|
|
scrollToMessageId?: string;
|
|
|
|
scrollToMessageCounter: number;
|
2023-01-13 20:07:26 +00:00
|
|
|
}>;
|
2019-05-31 22:42:01 +00:00
|
|
|
|
2023-01-13 20:07:26 +00:00
|
|
|
export type MessagesByConversationType = ReadonlyDeep<{
|
2021-01-06 15:41:43 +00:00
|
|
|
[key: string]: ConversationMessageType | undefined;
|
2023-01-13 20:07:26 +00:00
|
|
|
}>;
|
2019-01-14 21:49:58 +00:00
|
|
|
|
2023-01-13 20:07:26 +00:00
|
|
|
export type PreJoinConversationType = ReadonlyDeep<{
|
2021-01-29 22:16:48 +00:00
|
|
|
avatar?: {
|
|
|
|
loading?: boolean;
|
|
|
|
url?: string;
|
|
|
|
};
|
2021-06-02 00:24:28 +00:00
|
|
|
groupDescription?: string;
|
2021-01-29 22:16:48 +00:00
|
|
|
memberCount: number;
|
|
|
|
title: string;
|
|
|
|
approvalRequired: boolean;
|
2023-01-13 20:07:26 +00:00
|
|
|
}>;
|
2021-01-29 22:16:48 +00:00
|
|
|
|
2023-01-13 20:07:26 +00:00
|
|
|
type ComposerGroupCreationState = ReadonlyDeep<{
|
2021-09-24 00:49:05 +00:00
|
|
|
groupAvatar: undefined | Uint8Array;
|
2021-03-03 20:09:58 +00:00
|
|
|
groupName: string;
|
2022-11-16 20:18:02 +00:00
|
|
|
groupExpireTimer: DurationInSeconds;
|
2021-03-03 20:09:58 +00:00
|
|
|
maximumGroupSizeModalState: OneTimeModalState;
|
|
|
|
recommendedGroupSizeModalState: OneTimeModalState;
|
2022-12-22 00:07:02 +00:00
|
|
|
selectedConversationIds: ReadonlyArray<string>;
|
|
|
|
userAvatarData: ReadonlyArray<AvatarDataType>;
|
2023-01-13 20:07:26 +00:00
|
|
|
}>;
|
2021-03-03 20:09:58 +00:00
|
|
|
|
2023-01-13 20:07:26 +00:00
|
|
|
type DistributionVerificationData = ReadonlyDeep<{
|
|
|
|
uuidsNeedingVerification: Array<UUIDStringType>;
|
|
|
|
}>;
|
2022-11-11 04:10:30 +00:00
|
|
|
|
2023-01-13 20:07:26 +00:00
|
|
|
export type ConversationVerificationData = ReadonlyDeep<
|
2022-02-16 18:36:21 +00:00
|
|
|
| {
|
|
|
|
type: ConversationVerificationState.PendingVerification;
|
2022-11-11 04:10:30 +00:00
|
|
|
uuidsNeedingVerification: ReadonlyArray<UUIDStringType>;
|
|
|
|
|
|
|
|
byDistributionId?: Record<string, DistributionVerificationData>;
|
2022-02-16 18:36:21 +00:00
|
|
|
}
|
|
|
|
| {
|
|
|
|
type: ConversationVerificationState.VerificationCancelled;
|
|
|
|
canceledAt: number;
|
2023-01-13 20:07:26 +00:00
|
|
|
}
|
|
|
|
>;
|
2022-02-16 18:36:21 +00:00
|
|
|
|
2023-01-13 20:07:26 +00:00
|
|
|
type VerificationDataByConversation = ReadonlyDeep<
|
|
|
|
Record<string, ConversationVerificationData>
|
2022-11-11 04:10:30 +00:00
|
|
|
>;
|
|
|
|
|
2023-01-13 20:07:26 +00:00
|
|
|
type ComposerStateType = ReadonlyDeep<
|
2021-03-03 20:09:58 +00:00
|
|
|
| {
|
|
|
|
step: ComposerStep.StartDirectConversation;
|
2021-04-20 23:16:49 +00:00
|
|
|
searchTerm: string;
|
2022-04-05 00:38:22 +00:00
|
|
|
uuidFetchState: UUIDFetchStateType;
|
2021-03-03 20:09:58 +00:00
|
|
|
}
|
|
|
|
| ({
|
|
|
|
step: ComposerStep.ChooseGroupMembers;
|
2021-04-20 23:16:49 +00:00
|
|
|
searchTerm: string;
|
2022-04-05 00:38:22 +00:00
|
|
|
uuidFetchState: UUIDFetchStateType;
|
2021-03-03 20:09:58 +00:00
|
|
|
} & ComposerGroupCreationState)
|
|
|
|
| ({
|
|
|
|
step: ComposerStep.SetGroupMetadata;
|
2021-08-16 14:33:27 +00:00
|
|
|
isEditingAvatar: boolean;
|
2021-03-03 20:09:58 +00:00
|
|
|
} & ComposerGroupCreationState &
|
|
|
|
(
|
|
|
|
| { isCreating: false; hasError: boolean }
|
|
|
|
| { isCreating: true; hasError: false }
|
2023-01-13 20:07:26 +00:00
|
|
|
))
|
|
|
|
>;
|
2021-03-03 20:09:58 +00:00
|
|
|
|
2023-01-13 20:07:26 +00:00
|
|
|
type ContactSpoofingReviewStateType = ReadonlyDeep<
|
2021-06-01 23:30:25 +00:00
|
|
|
| {
|
|
|
|
type: ContactSpoofingType.DirectConversationWithSameTitle;
|
|
|
|
safeConversationId: string;
|
|
|
|
}
|
|
|
|
| {
|
|
|
|
type: ContactSpoofingType.MultipleGroupMembersWithSameTitle;
|
|
|
|
groupConversationId: string;
|
2023-01-13 20:07:26 +00:00
|
|
|
}
|
|
|
|
>;
|
2021-04-21 16:31:12 +00:00
|
|
|
|
2023-01-13 20:07:26 +00:00
|
|
|
// eslint-disable-next-line local-rules/type-alias-readonlydeep -- FIXME
|
|
|
|
export type ConversationsStateType = Readonly<{
|
2021-01-29 22:16:48 +00:00
|
|
|
preJoinConversation?: PreJoinConversationType;
|
2022-12-22 00:07:02 +00:00
|
|
|
invitedUuidsForNewlyCreatedGroup?: ReadonlyArray<string>;
|
2019-01-14 21:49:58 +00:00
|
|
|
conversationLookup: ConversationLookupType;
|
2021-01-06 15:41:43 +00:00
|
|
|
conversationsByE164: ConversationLookupType;
|
|
|
|
conversationsByUuid: ConversationLookupType;
|
|
|
|
conversationsByGroupId: ConversationLookupType;
|
2021-11-12 01:17:29 +00:00
|
|
|
conversationsByUsername: ConversationLookupType;
|
2021-02-12 21:58:14 +00:00
|
|
|
selectedConversationId?: string;
|
2023-03-20 22:23:53 +00:00
|
|
|
targetedMessage: string | undefined;
|
|
|
|
targetedMessageCounter: number;
|
|
|
|
targetedMessageSource: TargetedMessageSource | undefined;
|
2023-07-26 22:23:32 +00:00
|
|
|
targetedConversationPanels: {
|
|
|
|
isAnimating: boolean;
|
|
|
|
direction: 'push' | 'pop' | undefined;
|
|
|
|
stack: ReadonlyArray<PanelRenderType>;
|
|
|
|
watermark: number;
|
|
|
|
};
|
2023-03-20 22:23:53 +00:00
|
|
|
targetedMessageForDetails?: MessageAttributesType;
|
|
|
|
|
|
|
|
lastSelectedMessage: MessageTimestamps | undefined;
|
|
|
|
selectedMessageIds: ReadonlyArray<string> | undefined;
|
2022-12-22 00:07:02 +00:00
|
|
|
|
2019-03-12 00:20:16 +00:00
|
|
|
showArchived: boolean;
|
2021-03-03 20:09:58 +00:00
|
|
|
composer?: ComposerStateType;
|
2021-04-21 16:31:12 +00:00
|
|
|
contactSpoofingReview?: ContactSpoofingReviewStateType;
|
2019-03-20 17:42:28 +00:00
|
|
|
|
2021-08-31 20:58:39 +00:00
|
|
|
/**
|
2022-02-16 18:36:21 +00:00
|
|
|
* Each key is a conversation ID. Each value is a value representing the state of
|
|
|
|
* verification: either a set of pending conversationIds to be approved, or a tombstone
|
|
|
|
* telling jobs to cancel themselves up to that timestamp.
|
2021-08-31 20:58:39 +00:00
|
|
|
*/
|
2022-11-11 04:10:30 +00:00
|
|
|
verificationDataByConversation: VerificationDataByConversation;
|
2021-08-31 20:58:39 +00:00
|
|
|
|
2019-03-20 17:42:28 +00:00
|
|
|
// Note: it's very important that both of these locations are always kept up to date
|
|
|
|
messagesLookup: MessageLookupType;
|
|
|
|
messagesByConversation: MessagesByConversationType;
|
2023-01-13 20:07:26 +00:00
|
|
|
}>;
|
2019-01-14 21:49:58 +00:00
|
|
|
|
2020-11-13 19:57:55 +00:00
|
|
|
// Helpers
|
|
|
|
|
|
|
|
export const getConversationCallMode = (
|
|
|
|
conversation: ConversationType
|
|
|
|
): CallMode => {
|
|
|
|
if (
|
|
|
|
conversation.left ||
|
|
|
|
conversation.isBlocked ||
|
|
|
|
conversation.isMe ||
|
|
|
|
!conversation.acceptedMessageRequest
|
|
|
|
) {
|
|
|
|
return CallMode.None;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (conversation.type === 'direct') {
|
|
|
|
return CallMode.Direct;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (conversation.type === 'group' && conversation.groupVersion === 2) {
|
|
|
|
return CallMode.Group;
|
|
|
|
}
|
|
|
|
|
|
|
|
return CallMode.None;
|
|
|
|
};
|
|
|
|
|
2019-01-14 21:49:58 +00:00
|
|
|
// Actions
|
|
|
|
|
2022-02-16 18:36:21 +00:00
|
|
|
const CANCEL_CONVERSATION_PENDING_VERIFICATION =
|
|
|
|
'conversations/CANCEL_CONVERSATION_PENDING_VERIFICATION';
|
|
|
|
const CLEAR_CANCELLED_VERIFICATION =
|
|
|
|
'conversations/CLEAR_CANCELLED_VERIFICATION';
|
|
|
|
const CLEAR_CONVERSATIONS_PENDING_VERIFICATION =
|
|
|
|
'conversations/CLEAR_CONVERSATIONS_PENDING_VERIFICATION';
|
2021-08-18 20:08:14 +00:00
|
|
|
export const COLORS_CHANGED = 'conversations/COLORS_CHANGED';
|
|
|
|
export const COLOR_SELECTED = 'conversations/COLOR_SELECTED';
|
2021-08-06 00:17:05 +00:00
|
|
|
const COMPOSE_TOGGLE_EDITING_AVATAR =
|
|
|
|
'conversations/compose/COMPOSE_TOGGLE_EDITING_AVATAR';
|
|
|
|
const COMPOSE_ADD_AVATAR = 'conversations/compose/ADD_AVATAR';
|
|
|
|
const COMPOSE_REMOVE_AVATAR = 'conversations/compose/REMOVE_AVATAR';
|
|
|
|
const COMPOSE_REPLACE_AVATAR = 'conversations/compose/REPLACE_AVATAR';
|
2021-05-28 16:15:17 +00:00
|
|
|
const CUSTOM_COLOR_REMOVED = 'conversations/CUSTOM_COLOR_REMOVED';
|
2022-02-16 18:36:21 +00:00
|
|
|
const CONVERSATION_STOPPED_BY_MISSING_VERIFICATION =
|
|
|
|
'conversations/CONVERSATION_STOPPED_BY_MISSING_VERIFICATION';
|
2022-03-03 20:23:10 +00:00
|
|
|
const DISCARD_MESSAGES = 'conversations/DISCARD_MESSAGES';
|
2021-08-06 00:17:05 +00:00
|
|
|
const REPLACE_AVATARS = 'conversations/REPLACE_AVATARS';
|
2023-03-20 22:23:53 +00:00
|
|
|
export const TARGETED_CONVERSATION_CHANGED =
|
|
|
|
'conversations/TARGETED_CONVERSATION_CHANGED';
|
2022-12-14 18:41:04 +00:00
|
|
|
const PUSH_PANEL = 'conversations/PUSH_PANEL';
|
|
|
|
const POP_PANEL = 'conversations/POP_PANEL';
|
2023-07-26 22:23:32 +00:00
|
|
|
const PANEL_ANIMATION_DONE = 'conversations/PANEL_ANIMATION_DONE';
|
|
|
|
const PANEL_ANIMATION_STARTED = 'conversations/PANEL_ANIMATION_STARTED';
|
2023-01-05 22:16:56 +00:00
|
|
|
export const MESSAGE_CHANGED = 'MESSAGE_CHANGED';
|
2022-12-20 17:50:23 +00:00
|
|
|
export const MESSAGE_DELETED = 'MESSAGE_DELETED';
|
2023-01-05 22:16:56 +00:00
|
|
|
export const MESSAGE_EXPIRED = 'conversations/MESSAGE_EXPIRED';
|
2022-09-15 20:10:46 +00:00
|
|
|
export const SET_VOICE_NOTE_PLAYBACK_RATE =
|
|
|
|
'conversations/SET_VOICE_NOTE_PLAYBACK_RATE';
|
2022-12-20 17:50:23 +00:00
|
|
|
export const CONVERSATION_UNLOADED = 'CONVERSATION_UNLOADED';
|
2023-04-10 16:31:45 +00:00
|
|
|
export const SHOW_SPOILER = 'conversations/SHOW_SPOILER';
|
2022-09-15 20:10:46 +00:00
|
|
|
|
2023-01-13 20:07:26 +00:00
|
|
|
export type CancelVerificationDataByConversationActionType = ReadonlyDeep<{
|
2022-02-16 18:36:21 +00:00
|
|
|
type: typeof CANCEL_CONVERSATION_PENDING_VERIFICATION;
|
|
|
|
payload: {
|
|
|
|
canceledAt: number;
|
|
|
|
};
|
2023-01-13 20:07:26 +00:00
|
|
|
}>;
|
|
|
|
type ClearGroupCreationErrorActionType = ReadonlyDeep<{
|
|
|
|
type: 'CLEAR_GROUP_CREATION_ERROR';
|
|
|
|
}>;
|
|
|
|
type ClearInvitedUuidsForNewlyCreatedGroupActionType = ReadonlyDeep<{
|
2021-10-26 22:59:08 +00:00
|
|
|
type: 'CLEAR_INVITED_UUIDS_FOR_NEWLY_CREATED_GROUP';
|
2023-01-13 20:07:26 +00:00
|
|
|
}>;
|
|
|
|
type ClearVerificationDataByConversationActionType = ReadonlyDeep<{
|
2022-02-16 18:36:21 +00:00
|
|
|
type: typeof CLEAR_CONVERSATIONS_PENDING_VERIFICATION;
|
2023-01-13 20:07:26 +00:00
|
|
|
}>;
|
|
|
|
type ClearCancelledVerificationActionType = ReadonlyDeep<{
|
2022-02-16 18:36:21 +00:00
|
|
|
type: typeof CLEAR_CANCELLED_VERIFICATION;
|
|
|
|
payload: {
|
|
|
|
conversationId: string;
|
|
|
|
};
|
2023-01-13 20:07:26 +00:00
|
|
|
}>;
|
|
|
|
type CloseContactSpoofingReviewActionType = ReadonlyDeep<{
|
2021-04-21 16:31:12 +00:00
|
|
|
type: 'CLOSE_CONTACT_SPOOFING_REVIEW';
|
2023-01-13 20:07:26 +00:00
|
|
|
}>;
|
|
|
|
type CloseMaximumGroupSizeModalActionType = ReadonlyDeep<{
|
2021-03-03 20:09:58 +00:00
|
|
|
type: 'CLOSE_MAXIMUM_GROUP_SIZE_MODAL';
|
2023-01-13 20:07:26 +00:00
|
|
|
}>;
|
|
|
|
type CloseRecommendedGroupSizeModalActionType = ReadonlyDeep<{
|
2021-03-03 20:09:58 +00:00
|
|
|
type: 'CLOSE_RECOMMENDED_GROUP_SIZE_MODAL';
|
2023-01-13 20:07:26 +00:00
|
|
|
}>;
|
|
|
|
type ColorsChangedActionType = ReadonlyDeep<{
|
2021-05-28 16:15:17 +00:00
|
|
|
type: typeof COLORS_CHANGED;
|
|
|
|
payload: {
|
|
|
|
conversationColor?: ConversationColorType;
|
|
|
|
customColorData?: {
|
|
|
|
id: string;
|
|
|
|
value: CustomColorType;
|
|
|
|
};
|
|
|
|
};
|
2023-01-13 20:07:26 +00:00
|
|
|
}>;
|
|
|
|
type ColorSelectedPayloadType = ReadonlyDeep<{
|
2021-06-03 21:34:36 +00:00
|
|
|
conversationId: string;
|
|
|
|
conversationColor?: ConversationColorType;
|
|
|
|
customColorData?: {
|
|
|
|
id: string;
|
|
|
|
value: CustomColorType;
|
|
|
|
};
|
2023-01-13 20:07:26 +00:00
|
|
|
}>;
|
|
|
|
export type ColorSelectedActionType = ReadonlyDeep<{
|
2021-06-03 21:34:36 +00:00
|
|
|
type: typeof COLOR_SELECTED;
|
|
|
|
payload: ColorSelectedPayloadType;
|
2023-01-13 20:07:26 +00:00
|
|
|
}>;
|
|
|
|
type ComposeDeleteAvatarActionType = ReadonlyDeep<{
|
2021-08-06 00:17:05 +00:00
|
|
|
type: typeof COMPOSE_REMOVE_AVATAR;
|
|
|
|
payload: AvatarDataType;
|
2023-01-13 20:07:26 +00:00
|
|
|
}>;
|
|
|
|
type ComposeReplaceAvatarsActionType = ReadonlyDeep<{
|
2021-08-06 00:17:05 +00:00
|
|
|
type: typeof COMPOSE_REPLACE_AVATAR;
|
|
|
|
payload: {
|
|
|
|
curr: AvatarDataType;
|
|
|
|
prev?: AvatarDataType;
|
|
|
|
};
|
2023-01-13 20:07:26 +00:00
|
|
|
}>;
|
|
|
|
type ComposeSaveAvatarActionType = ReadonlyDeep<{
|
2021-08-06 00:17:05 +00:00
|
|
|
type: typeof COMPOSE_ADD_AVATAR;
|
|
|
|
payload: AvatarDataType;
|
2023-01-13 20:07:26 +00:00
|
|
|
}>;
|
|
|
|
type CustomColorRemovedActionType = ReadonlyDeep<{
|
2021-05-28 16:15:17 +00:00
|
|
|
type: typeof CUSTOM_COLOR_REMOVED;
|
2021-06-02 21:05:09 +00:00
|
|
|
payload: {
|
|
|
|
colorId: string;
|
|
|
|
};
|
2023-01-13 20:07:26 +00:00
|
|
|
}>;
|
|
|
|
type DiscardMessagesActionType = ReadonlyDeep<{
|
2022-03-03 20:23:10 +00:00
|
|
|
type: typeof DISCARD_MESSAGES;
|
2022-05-10 20:19:58 +00:00
|
|
|
payload: Readonly<
|
|
|
|
| {
|
|
|
|
conversationId: string;
|
|
|
|
numberToKeepAtBottom: number;
|
|
|
|
}
|
|
|
|
| { conversationId: string; numberToKeepAtTop: number }
|
|
|
|
>;
|
2023-01-13 20:07:26 +00:00
|
|
|
}>;
|
|
|
|
type SetPreJoinConversationActionType = ReadonlyDeep<{
|
2021-01-29 22:16:48 +00:00
|
|
|
type: 'SET_PRE_JOIN_CONVERSATION';
|
|
|
|
payload: {
|
|
|
|
data: PreJoinConversationType | undefined;
|
|
|
|
};
|
2023-01-13 20:07:26 +00:00
|
|
|
}>;
|
2021-01-29 22:16:48 +00:00
|
|
|
|
2023-01-13 20:07:26 +00:00
|
|
|
type ConversationAddedActionType = ReadonlyDeep<{
|
2019-01-14 21:49:58 +00:00
|
|
|
type: 'CONVERSATION_ADDED';
|
|
|
|
payload: {
|
|
|
|
id: string;
|
|
|
|
data: ConversationType;
|
|
|
|
};
|
2023-01-13 20:07:26 +00:00
|
|
|
}>;
|
|
|
|
export type ConversationChangedActionType = ReadonlyDeep<{
|
2019-01-14 21:49:58 +00:00
|
|
|
type: 'CONVERSATION_CHANGED';
|
|
|
|
payload: {
|
|
|
|
id: string;
|
|
|
|
data: ConversationType;
|
|
|
|
};
|
2023-01-13 20:07:26 +00:00
|
|
|
}>;
|
|
|
|
export type ConversationRemovedActionType = ReadonlyDeep<{
|
2019-01-14 21:49:58 +00:00
|
|
|
type: 'CONVERSATION_REMOVED';
|
|
|
|
payload: {
|
|
|
|
id: string;
|
|
|
|
};
|
2023-01-13 20:07:26 +00:00
|
|
|
}>;
|
|
|
|
export type ConversationUnloadedActionType = ReadonlyDeep<{
|
2022-12-20 17:50:23 +00:00
|
|
|
type: typeof CONVERSATION_UNLOADED;
|
2019-05-31 22:42:01 +00:00
|
|
|
payload: {
|
2023-01-05 00:22:36 +00:00
|
|
|
conversationId: string;
|
2019-05-31 22:42:01 +00:00
|
|
|
};
|
2023-01-13 20:07:26 +00:00
|
|
|
}>;
|
|
|
|
type CreateGroupPendingActionType = ReadonlyDeep<{
|
2021-03-03 20:09:58 +00:00
|
|
|
type: 'CREATE_GROUP_PENDING';
|
2023-01-13 20:07:26 +00:00
|
|
|
}>;
|
|
|
|
type CreateGroupFulfilledActionType = ReadonlyDeep<{
|
2021-03-03 20:09:58 +00:00
|
|
|
type: 'CREATE_GROUP_FULFILLED';
|
|
|
|
payload: {
|
2022-12-22 00:07:02 +00:00
|
|
|
invitedUuids: ReadonlyArray<UUIDStringType>;
|
2021-03-03 20:09:58 +00:00
|
|
|
};
|
2023-01-13 20:07:26 +00:00
|
|
|
}>;
|
|
|
|
type CreateGroupRejectedActionType = ReadonlyDeep<{
|
2021-03-03 20:09:58 +00:00
|
|
|
type: 'CREATE_GROUP_REJECTED';
|
2023-01-13 20:07:26 +00:00
|
|
|
}>;
|
|
|
|
export type RemoveAllConversationsActionType = ReadonlyDeep<{
|
2019-01-14 21:49:58 +00:00
|
|
|
type: 'CONVERSATIONS_REMOVE_ALL';
|
|
|
|
payload: null;
|
2023-01-13 20:07:26 +00:00
|
|
|
}>;
|
2023-03-20 22:23:53 +00:00
|
|
|
export type MessageTargetedActionType = ReadonlyDeep<{
|
|
|
|
type: 'MESSAGE_TARGETED';
|
2019-11-07 21:36:16 +00:00
|
|
|
payload: {
|
|
|
|
messageId: string;
|
|
|
|
conversationId: string;
|
|
|
|
};
|
2023-01-13 20:07:26 +00:00
|
|
|
}>;
|
2023-03-20 22:23:53 +00:00
|
|
|
export type ToggleSelectMessagesActionType = ReadonlyDeep<{
|
|
|
|
type: 'TOGGLE_SELECT_MESSAGES';
|
|
|
|
payload: {
|
|
|
|
toggledMessageId: string;
|
|
|
|
messageIds: Array<string>;
|
|
|
|
selected: boolean;
|
|
|
|
};
|
|
|
|
}>;
|
|
|
|
export type ToggleSelectModeActionType = ReadonlyDeep<{
|
|
|
|
type: 'TOGGLE_SELECT_MODE';
|
|
|
|
payload: {
|
|
|
|
on: boolean;
|
|
|
|
};
|
|
|
|
}>;
|
2023-01-13 20:07:26 +00:00
|
|
|
type ConversationStoppedByMissingVerificationActionType = ReadonlyDeep<{
|
2022-02-16 18:36:21 +00:00
|
|
|
type: typeof CONVERSATION_STOPPED_BY_MISSING_VERIFICATION;
|
2021-08-31 20:58:39 +00:00
|
|
|
payload: {
|
2022-02-16 18:36:21 +00:00
|
|
|
conversationId: string;
|
2022-11-11 04:10:30 +00:00
|
|
|
distributionId?: string;
|
|
|
|
untrustedUuids: ReadonlyArray<UUIDStringType>;
|
2021-08-31 20:58:39 +00:00
|
|
|
};
|
2023-01-13 20:07:26 +00:00
|
|
|
}>;
|
|
|
|
// eslint-disable-next-line local-rules/type-alias-readonlydeep -- FIXME
|
2019-05-31 22:42:01 +00:00
|
|
|
export type MessageChangedActionType = {
|
2023-01-05 22:16:56 +00:00
|
|
|
type: typeof MESSAGE_CHANGED;
|
2019-01-14 21:49:58 +00:00
|
|
|
payload: {
|
|
|
|
id: string;
|
|
|
|
conversationId: string;
|
2021-06-17 17:15:10 +00:00
|
|
|
data: MessageAttributesType;
|
2019-05-31 22:42:01 +00:00
|
|
|
};
|
|
|
|
};
|
2023-01-13 20:07:26 +00:00
|
|
|
export type MessageDeletedActionType = ReadonlyDeep<{
|
2022-12-20 17:50:23 +00:00
|
|
|
type: typeof MESSAGE_DELETED;
|
2019-05-31 22:42:01 +00:00
|
|
|
payload: {
|
|
|
|
id: string;
|
|
|
|
conversationId: string;
|
|
|
|
};
|
2023-01-13 20:07:26 +00:00
|
|
|
}>;
|
|
|
|
export type MessageExpandedActionType = ReadonlyDeep<{
|
2021-11-11 23:45:47 +00:00
|
|
|
type: 'MESSAGE_EXPANDED';
|
|
|
|
payload: {
|
|
|
|
id: string;
|
|
|
|
displayLimit: number;
|
|
|
|
};
|
2023-01-13 20:07:26 +00:00
|
|
|
}>;
|
2023-04-10 16:31:45 +00:00
|
|
|
export type ShowSpoilerActionType = ReadonlyDeep<{
|
|
|
|
type: typeof SHOW_SPOILER;
|
|
|
|
payload: {
|
|
|
|
id: string;
|
2023-05-10 00:40:19 +00:00
|
|
|
data: Record<number, boolean>;
|
2023-04-10 16:31:45 +00:00
|
|
|
};
|
|
|
|
}>;
|
2021-11-11 23:45:47 +00:00
|
|
|
|
2023-01-13 20:07:26 +00:00
|
|
|
// eslint-disable-next-line local-rules/type-alias-readonlydeep -- FIXME
|
|
|
|
export type MessagesAddedActionType = Readonly<{
|
2019-05-31 22:42:01 +00:00
|
|
|
type: 'MESSAGES_ADDED';
|
|
|
|
payload: {
|
|
|
|
conversationId: string;
|
2021-11-23 13:09:07 +00:00
|
|
|
isActive: boolean;
|
2021-11-30 11:25:24 +00:00
|
|
|
isJustSent: boolean;
|
|
|
|
isNewMessage: boolean;
|
2022-12-22 00:07:02 +00:00
|
|
|
messages: ReadonlyArray<MessageAttributesType>;
|
2019-05-31 22:42:01 +00:00
|
|
|
};
|
2023-01-13 20:07:26 +00:00
|
|
|
}>;
|
2020-12-04 20:41:40 +00:00
|
|
|
|
2023-01-13 20:07:26 +00:00
|
|
|
export type MessageExpiredActionType = ReadonlyDeep<{
|
2022-12-20 17:50:23 +00:00
|
|
|
type: typeof MESSAGE_EXPIRED;
|
|
|
|
payload: {
|
|
|
|
id: string;
|
|
|
|
};
|
2023-01-13 20:07:26 +00:00
|
|
|
}>;
|
2022-12-20 17:50:23 +00:00
|
|
|
|
2023-01-13 20:07:26 +00:00
|
|
|
export type RepairNewestMessageActionType = ReadonlyDeep<{
|
2020-12-04 20:41:40 +00:00
|
|
|
type: 'REPAIR_NEWEST_MESSAGE';
|
|
|
|
payload: {
|
|
|
|
conversationId: string;
|
|
|
|
};
|
2023-01-13 20:07:26 +00:00
|
|
|
}>;
|
|
|
|
export type RepairOldestMessageActionType = ReadonlyDeep<{
|
2020-12-04 20:41:40 +00:00
|
|
|
type: 'REPAIR_OLDEST_MESSAGE';
|
|
|
|
payload: {
|
|
|
|
conversationId: string;
|
|
|
|
};
|
2023-01-13 20:07:26 +00:00
|
|
|
}>;
|
|
|
|
// eslint-disable-next-line local-rules/type-alias-readonlydeep
|
2019-05-31 22:42:01 +00:00
|
|
|
export type MessagesResetActionType = {
|
|
|
|
type: 'MESSAGES_RESET';
|
|
|
|
payload: {
|
|
|
|
conversationId: string;
|
2022-12-22 00:07:02 +00:00
|
|
|
messages: ReadonlyArray<MessageAttributesType>;
|
2019-05-31 22:42:01 +00:00
|
|
|
metrics: MessageMetricsType;
|
|
|
|
scrollToMessageId?: string;
|
2020-07-06 17:06:44 +00:00
|
|
|
// The set of provided messages should be trusted, even if it conflicts with metrics,
|
|
|
|
// because we weren't looking for a specific time window of messages with our query.
|
|
|
|
unboundedFetch: boolean;
|
2019-05-31 22:42:01 +00:00
|
|
|
};
|
|
|
|
};
|
2023-01-13 20:07:26 +00:00
|
|
|
export type SetMessageLoadingStateActionType = ReadonlyDeep<{
|
2022-03-11 22:31:21 +00:00
|
|
|
type: 'SET_MESSAGE_LOADING_STATE';
|
2019-05-31 22:42:01 +00:00
|
|
|
payload: {
|
|
|
|
conversationId: string;
|
2022-03-11 22:31:21 +00:00
|
|
|
messageLoadingState: undefined | TimelineMessageLoadingState;
|
2019-05-31 22:42:01 +00:00
|
|
|
};
|
2023-01-13 20:07:26 +00:00
|
|
|
}>;
|
|
|
|
export type SetIsNearBottomActionType = ReadonlyDeep<{
|
2019-05-31 22:42:01 +00:00
|
|
|
type: 'SET_NEAR_BOTTOM';
|
|
|
|
payload: {
|
|
|
|
conversationId: string;
|
|
|
|
isNearBottom: boolean;
|
|
|
|
};
|
2023-01-13 20:07:26 +00:00
|
|
|
}>;
|
|
|
|
export type ScrollToMessageActionType = ReadonlyDeep<{
|
2019-05-31 22:42:01 +00:00
|
|
|
type: 'SCROLL_TO_MESSAGE';
|
|
|
|
payload: {
|
|
|
|
conversationId: string;
|
|
|
|
messageId: string;
|
|
|
|
};
|
2023-01-13 20:07:26 +00:00
|
|
|
}>;
|
2023-03-20 22:23:53 +00:00
|
|
|
export type ClearTargetedMessageActionType = ReadonlyDeep<{
|
|
|
|
type: 'CLEAR_TARGETED_MESSAGE';
|
2019-05-31 22:42:01 +00:00
|
|
|
payload: null;
|
2023-01-13 20:07:26 +00:00
|
|
|
}>;
|
|
|
|
export type ClearUnreadMetricsActionType = ReadonlyDeep<{
|
2019-05-31 22:42:01 +00:00
|
|
|
type: 'CLEAR_UNREAD_METRICS';
|
|
|
|
payload: {
|
|
|
|
conversationId: string;
|
2019-01-14 21:49:58 +00:00
|
|
|
};
|
2023-01-13 20:07:26 +00:00
|
|
|
}>;
|
2023-03-20 22:23:53 +00:00
|
|
|
export type TargetedConversationChangedActionType = ReadonlyDeep<{
|
|
|
|
type: typeof TARGETED_CONVERSATION_CHANGED;
|
2019-01-14 21:49:58 +00:00
|
|
|
payload: {
|
2023-01-05 00:22:36 +00:00
|
|
|
conversationId?: string;
|
2019-01-14 21:49:58 +00:00
|
|
|
messageId?: string;
|
2022-06-16 19:12:50 +00:00
|
|
|
switchToAssociatedView?: boolean;
|
2019-01-14 21:49:58 +00:00
|
|
|
};
|
2023-01-13 20:07:26 +00:00
|
|
|
}>;
|
|
|
|
type ReviewGroupMemberNameCollisionActionType = ReadonlyDeep<{
|
2021-06-01 23:30:25 +00:00
|
|
|
type: 'REVIEW_GROUP_MEMBER_NAME_COLLISION';
|
|
|
|
payload: {
|
|
|
|
groupConversationId: string;
|
|
|
|
};
|
2023-01-13 20:07:26 +00:00
|
|
|
}>;
|
|
|
|
type ReviewMessageRequestNameCollisionActionType = ReadonlyDeep<{
|
2021-04-21 16:31:12 +00:00
|
|
|
type: 'REVIEW_MESSAGE_REQUEST_NAME_COLLISION';
|
|
|
|
payload: {
|
|
|
|
safeConversationId: string;
|
|
|
|
};
|
2023-01-13 20:07:26 +00:00
|
|
|
}>;
|
|
|
|
type ShowInboxActionType = ReadonlyDeep<{
|
2019-03-12 00:20:16 +00:00
|
|
|
type: 'SHOW_INBOX';
|
|
|
|
payload: null;
|
2023-01-13 20:07:26 +00:00
|
|
|
}>;
|
|
|
|
export type ShowArchivedConversationsActionType = ReadonlyDeep<{
|
2019-03-12 00:20:16 +00:00
|
|
|
type: 'SHOW_ARCHIVED_CONVERSATIONS';
|
|
|
|
payload: null;
|
2023-01-13 20:07:26 +00:00
|
|
|
}>;
|
|
|
|
type SetComposeGroupAvatarActionType = ReadonlyDeep<{
|
2021-03-03 20:09:58 +00:00
|
|
|
type: 'SET_COMPOSE_GROUP_AVATAR';
|
2021-09-24 00:49:05 +00:00
|
|
|
payload: { groupAvatar: undefined | Uint8Array };
|
2023-01-13 20:07:26 +00:00
|
|
|
}>;
|
|
|
|
type SetComposeGroupNameActionType = ReadonlyDeep<{
|
2021-03-03 20:09:58 +00:00
|
|
|
type: 'SET_COMPOSE_GROUP_NAME';
|
|
|
|
payload: { groupName: string };
|
2023-01-13 20:07:26 +00:00
|
|
|
}>;
|
|
|
|
type SetComposeGroupExpireTimerActionType = ReadonlyDeep<{
|
2021-06-25 23:52:56 +00:00
|
|
|
type: 'SET_COMPOSE_GROUP_EXPIRE_TIMER';
|
2022-11-16 20:18:02 +00:00
|
|
|
payload: { groupExpireTimer: DurationInSeconds };
|
2023-01-13 20:07:26 +00:00
|
|
|
}>;
|
|
|
|
type SetComposeSearchTermActionType = ReadonlyDeep<{
|
2021-02-23 20:34:28 +00:00
|
|
|
type: 'SET_COMPOSE_SEARCH_TERM';
|
2021-04-20 23:16:49 +00:00
|
|
|
payload: { searchTerm: string };
|
2023-01-13 20:07:26 +00:00
|
|
|
}>;
|
|
|
|
type SetIsFetchingUUIDActionType = ReadonlyDeep<{
|
2022-04-05 00:38:22 +00:00
|
|
|
type: 'SET_IS_FETCHING_UUID';
|
2021-11-12 01:17:29 +00:00
|
|
|
payload: {
|
2022-04-05 00:38:22 +00:00
|
|
|
identifier: UUIDFetchStateKeyType;
|
|
|
|
isFetching: boolean;
|
2021-11-12 01:17:29 +00:00
|
|
|
};
|
2023-01-13 20:07:26 +00:00
|
|
|
}>;
|
|
|
|
type SetRecentMediaItemsActionType = ReadonlyDeep<{
|
2021-01-29 21:19:24 +00:00
|
|
|
type: 'SET_RECENT_MEDIA_ITEMS';
|
|
|
|
payload: {
|
|
|
|
id: string;
|
2022-12-22 00:07:02 +00:00
|
|
|
recentMediaItems: ReadonlyArray<MediaItemType>;
|
2021-01-29 21:19:24 +00:00
|
|
|
};
|
2023-01-13 20:07:26 +00:00
|
|
|
}>;
|
|
|
|
type ToggleComposeEditingAvatarActionType = ReadonlyDeep<{
|
2021-08-06 00:17:05 +00:00
|
|
|
type: typeof COMPOSE_TOGGLE_EDITING_AVATAR;
|
2023-01-13 20:07:26 +00:00
|
|
|
}>;
|
|
|
|
type StartComposingActionType = ReadonlyDeep<{
|
2021-02-23 20:34:28 +00:00
|
|
|
type: 'START_COMPOSING';
|
2023-01-13 20:07:26 +00:00
|
|
|
}>;
|
|
|
|
type ShowChooseGroupMembersActionType = ReadonlyDeep<{
|
2021-03-03 20:09:58 +00:00
|
|
|
type: 'SHOW_CHOOSE_GROUP_MEMBERS';
|
2023-01-13 20:07:26 +00:00
|
|
|
}>;
|
|
|
|
type StartSettingGroupMetadataActionType = ReadonlyDeep<{
|
2021-03-03 20:09:58 +00:00
|
|
|
type: 'START_SETTING_GROUP_METADATA';
|
2023-01-13 20:07:26 +00:00
|
|
|
}>;
|
|
|
|
export type ToggleConversationInChooseMembersActionType = ReadonlyDeep<{
|
2021-03-03 20:09:58 +00:00
|
|
|
type: 'TOGGLE_CONVERSATION_IN_CHOOSE_MEMBERS';
|
|
|
|
payload: {
|
|
|
|
conversationId: string;
|
|
|
|
maxRecommendedGroupSize: number;
|
|
|
|
maxGroupSize: number;
|
|
|
|
};
|
2023-01-13 20:07:26 +00:00
|
|
|
}>;
|
|
|
|
|
|
|
|
// eslint-disable-next-line local-rules/type-alias-readonlydeep -- FIXME
|
|
|
|
type PushPanelActionType = Readonly<{
|
2022-12-14 18:41:04 +00:00
|
|
|
type: typeof PUSH_PANEL;
|
|
|
|
payload: PanelRenderType;
|
2023-01-13 20:07:26 +00:00
|
|
|
}>;
|
|
|
|
type PopPanelActionType = ReadonlyDeep<{
|
2022-12-14 18:41:04 +00:00
|
|
|
type: typeof POP_PANEL;
|
|
|
|
payload: null;
|
2023-01-13 20:07:26 +00:00
|
|
|
}>;
|
2023-07-26 22:23:32 +00:00
|
|
|
type PanelAnimationDoneActionType = ReadonlyDeep<{
|
|
|
|
type: typeof PANEL_ANIMATION_DONE;
|
|
|
|
payload: null;
|
|
|
|
}>;
|
|
|
|
type PanelAnimationStartedActionType = ReadonlyDeep<{
|
|
|
|
type: typeof PANEL_ANIMATION_STARTED;
|
|
|
|
payload: null;
|
|
|
|
}>;
|
2021-08-06 00:17:05 +00:00
|
|
|
|
2023-01-13 20:07:26 +00:00
|
|
|
type ReplaceAvatarsActionType = ReadonlyDeep<{
|
2021-08-06 00:17:05 +00:00
|
|
|
type: typeof REPLACE_AVATARS;
|
|
|
|
payload: {
|
|
|
|
conversationId: string;
|
2022-12-22 00:07:02 +00:00
|
|
|
avatars: ReadonlyArray<AvatarDataType>;
|
2021-08-06 00:17:05 +00:00
|
|
|
};
|
2023-01-13 20:07:26 +00:00
|
|
|
}>;
|
2022-10-18 17:12:02 +00:00
|
|
|
|
2023-01-13 20:07:26 +00:00
|
|
|
// eslint-disable-next-line local-rules/type-alias-readonlydeep -- FIXME
|
2019-01-14 21:49:58 +00:00
|
|
|
export type ConversationActionType =
|
2022-02-16 18:36:21 +00:00
|
|
|
| CancelVerificationDataByConversationActionType
|
|
|
|
| ClearCancelledVerificationActionType
|
2021-03-03 20:09:58 +00:00
|
|
|
| ClearGroupCreationErrorActionType
|
2021-10-26 22:59:08 +00:00
|
|
|
| ClearInvitedUuidsForNewlyCreatedGroupActionType
|
2023-03-20 22:23:53 +00:00
|
|
|
| ClearTargetedMessageActionType
|
2021-01-29 22:16:48 +00:00
|
|
|
| ClearUnreadMetricsActionType
|
2022-12-21 20:44:23 +00:00
|
|
|
| ClearVerificationDataByConversationActionType
|
2021-04-21 16:31:12 +00:00
|
|
|
| CloseContactSpoofingReviewActionType
|
2021-03-03 20:09:58 +00:00
|
|
|
| CloseMaximumGroupSizeModalActionType
|
|
|
|
| CloseRecommendedGroupSizeModalActionType
|
2021-08-06 00:17:05 +00:00
|
|
|
| ColorSelectedActionType
|
|
|
|
| ColorsChangedActionType
|
|
|
|
| ComposeDeleteAvatarActionType
|
|
|
|
| ComposeReplaceAvatarsActionType
|
|
|
|
| ComposeSaveAvatarActionType
|
2019-01-14 21:49:58 +00:00
|
|
|
| ConversationAddedActionType
|
|
|
|
| ConversationChangedActionType
|
|
|
|
| ConversationRemovedActionType
|
2022-02-16 18:36:21 +00:00
|
|
|
| ConversationStoppedByMissingVerificationActionType
|
2019-05-31 22:42:01 +00:00
|
|
|
| ConversationUnloadedActionType
|
2021-03-03 20:09:58 +00:00
|
|
|
| CreateGroupFulfilledActionType
|
|
|
|
| CreateGroupPendingActionType
|
|
|
|
| CreateGroupRejectedActionType
|
2021-08-06 00:17:05 +00:00
|
|
|
| CustomColorRemovedActionType
|
2022-03-03 20:23:10 +00:00
|
|
|
| DiscardMessagesActionType
|
2019-05-31 22:42:01 +00:00
|
|
|
| MessageChangedActionType
|
|
|
|
| MessageDeletedActionType
|
2021-11-11 23:45:47 +00:00
|
|
|
| MessageExpandedActionType
|
2022-12-21 20:44:23 +00:00
|
|
|
| MessageExpiredActionType
|
2023-03-20 22:23:53 +00:00
|
|
|
| MessageTargetedActionType
|
2021-08-06 00:17:05 +00:00
|
|
|
| MessagesAddedActionType
|
2021-01-29 22:16:48 +00:00
|
|
|
| MessagesResetActionType
|
2023-07-26 22:23:32 +00:00
|
|
|
| PanelAnimationStartedActionType
|
|
|
|
| PanelAnimationDoneActionType
|
2022-12-14 18:41:04 +00:00
|
|
|
| PopPanelActionType
|
|
|
|
| PushPanelActionType
|
2021-01-29 22:16:48 +00:00
|
|
|
| RemoveAllConversationsActionType
|
2020-12-04 20:41:40 +00:00
|
|
|
| RepairNewestMessageActionType
|
|
|
|
| RepairOldestMessageActionType
|
2021-08-06 00:17:05 +00:00
|
|
|
| ReplaceAvatarsActionType
|
2021-06-01 23:30:25 +00:00
|
|
|
| ReviewGroupMemberNameCollisionActionType
|
2021-04-21 16:31:12 +00:00
|
|
|
| ReviewMessageRequestNameCollisionActionType
|
2019-05-31 22:42:01 +00:00
|
|
|
| ScrollToMessageActionType
|
2023-03-20 22:23:53 +00:00
|
|
|
| TargetedConversationChangedActionType
|
2021-03-03 20:09:58 +00:00
|
|
|
| SetComposeGroupAvatarActionType
|
2021-06-25 23:52:56 +00:00
|
|
|
| SetComposeGroupExpireTimerActionType
|
2021-08-06 00:17:05 +00:00
|
|
|
| SetComposeGroupNameActionType
|
2021-02-23 20:34:28 +00:00
|
|
|
| SetComposeSearchTermActionType
|
2022-04-05 00:38:22 +00:00
|
|
|
| SetIsFetchingUUIDActionType
|
2021-01-29 22:16:48 +00:00
|
|
|
| SetIsNearBottomActionType
|
2022-03-11 22:31:21 +00:00
|
|
|
| SetMessageLoadingStateActionType
|
2021-01-29 22:16:48 +00:00
|
|
|
| SetPreJoinConversationActionType
|
2021-01-29 21:19:24 +00:00
|
|
|
| SetRecentMediaItemsActionType
|
2021-01-29 22:16:48 +00:00
|
|
|
| ShowArchivedConversationsActionType
|
2021-08-06 00:17:05 +00:00
|
|
|
| ShowChooseGroupMembersActionType
|
2021-02-23 20:34:28 +00:00
|
|
|
| ShowInboxActionType
|
2022-11-11 04:10:30 +00:00
|
|
|
| ShowSendAnywayDialogActionType
|
2023-04-10 16:31:45 +00:00
|
|
|
| ShowSpoilerActionType
|
2021-02-23 20:34:28 +00:00
|
|
|
| StartComposingActionType
|
2021-03-03 20:09:58 +00:00
|
|
|
| StartSettingGroupMetadataActionType
|
2022-12-21 20:44:23 +00:00
|
|
|
| ToggleComposeEditingAvatarActionType
|
2023-03-20 22:23:53 +00:00
|
|
|
| ToggleConversationInChooseMembersActionType
|
|
|
|
| ToggleSelectMessagesActionType
|
|
|
|
| ToggleSelectModeActionType;
|
2019-01-14 21:49:58 +00:00
|
|
|
|
|
|
|
// Action Creators
|
|
|
|
|
|
|
|
export const actions = {
|
2023-01-02 21:34:41 +00:00
|
|
|
onConversationOpened,
|
|
|
|
onConversationClosed,
|
2022-12-06 19:03:09 +00:00
|
|
|
acceptConversation,
|
2022-12-21 03:25:10 +00:00
|
|
|
acknowledgeGroupMemberNameCollisions,
|
2022-12-16 03:12:05 +00:00
|
|
|
addMembersToGroup,
|
2022-12-05 22:56:23 +00:00
|
|
|
approvePendingMembershipFromGroupV2,
|
2022-12-06 19:03:09 +00:00
|
|
|
blockAndReportSpam,
|
|
|
|
blockConversation,
|
2022-12-21 03:25:10 +00:00
|
|
|
blockGroupLinkRequests,
|
2022-02-16 18:36:21 +00:00
|
|
|
cancelConversationVerification,
|
2022-06-13 18:42:19 +00:00
|
|
|
changeHasGroupLink,
|
2022-02-16 18:36:21 +00:00
|
|
|
clearCancelledConversationVerification,
|
2021-03-03 20:09:58 +00:00
|
|
|
clearGroupCreationError,
|
2021-10-26 22:59:08 +00:00
|
|
|
clearInvitedUuidsForNewlyCreatedGroup,
|
2023-03-20 22:23:53 +00:00
|
|
|
clearTargetedMessage,
|
2021-01-29 21:19:24 +00:00
|
|
|
clearUnreadMetrics,
|
2021-04-21 16:31:12 +00:00
|
|
|
closeContactSpoofingReview,
|
2021-03-03 20:09:58 +00:00
|
|
|
closeMaximumGroupSizeModal,
|
2021-08-06 00:17:05 +00:00
|
|
|
closeRecommendedGroupSizeModal,
|
|
|
|
colorSelected,
|
|
|
|
composeDeleteAvatarFromDisk,
|
|
|
|
composeReplaceAvatar,
|
|
|
|
composeSaveAvatarToDisk,
|
2019-01-14 21:49:58 +00:00
|
|
|
conversationAdded,
|
|
|
|
conversationChanged,
|
|
|
|
conversationRemoved,
|
2022-02-16 18:36:21 +00:00
|
|
|
conversationStoppedByMissingVerification,
|
2021-03-03 20:09:58 +00:00
|
|
|
createGroup,
|
2021-08-06 00:17:05 +00:00
|
|
|
deleteAvatarFromDisk,
|
2022-12-06 19:03:09 +00:00
|
|
|
deleteConversation,
|
2023-03-20 22:23:53 +00:00
|
|
|
deleteMessages,
|
2023-04-10 21:38:34 +00:00
|
|
|
deleteMessagesForEveryone,
|
2022-12-05 22:56:23 +00:00
|
|
|
destroyMessages,
|
2023-04-20 16:31:59 +00:00
|
|
|
discardEditMessage,
|
2022-03-03 20:23:10 +00:00
|
|
|
discardMessages,
|
2021-06-17 17:15:10 +00:00
|
|
|
doubleCheckMissingQuoteReference,
|
2022-06-13 18:42:19 +00:00
|
|
|
generateNewGroupLink,
|
2022-12-16 03:12:05 +00:00
|
|
|
getProfilesForConversation,
|
2022-12-08 06:41:37 +00:00
|
|
|
initiateMigrationToGroupV2,
|
2022-12-20 01:04:47 +00:00
|
|
|
kickOffAttachmentDownload,
|
2022-12-16 03:12:05 +00:00
|
|
|
leaveGroup,
|
2022-12-21 03:25:10 +00:00
|
|
|
loadNewerMessages,
|
|
|
|
loadNewestMessages,
|
|
|
|
loadOlderMessages,
|
2022-12-14 18:41:04 +00:00
|
|
|
loadRecentMediaItems,
|
2022-12-20 01:04:47 +00:00
|
|
|
markAttachmentAsCorrupted,
|
2022-12-21 03:25:10 +00:00
|
|
|
markMessageRead,
|
2019-05-31 22:42:01 +00:00
|
|
|
messageChanged,
|
2021-01-29 21:19:24 +00:00
|
|
|
messageDeleted,
|
2021-11-11 23:45:47 +00:00
|
|
|
messageExpanded,
|
2022-12-20 17:50:23 +00:00
|
|
|
messageExpired,
|
2021-08-06 00:17:05 +00:00
|
|
|
messagesAdded,
|
2019-05-31 22:42:01 +00:00
|
|
|
messagesReset,
|
2021-07-19 19:26:06 +00:00
|
|
|
myProfileChanged,
|
2022-12-21 03:25:10 +00:00
|
|
|
onArchive,
|
|
|
|
onMarkUnread,
|
|
|
|
onMoveToInbox,
|
|
|
|
onUndoArchive,
|
2022-12-20 01:04:47 +00:00
|
|
|
openGiftBadge,
|
2022-12-14 18:41:04 +00:00
|
|
|
popPanelForConversation,
|
|
|
|
pushPanelForConversation,
|
2023-07-26 22:23:32 +00:00
|
|
|
panelAnimationDone,
|
|
|
|
panelAnimationStarted,
|
2021-01-29 21:19:24 +00:00
|
|
|
removeAllConversations,
|
2023-04-05 20:48:00 +00:00
|
|
|
removeConversation,
|
2021-05-28 16:15:17 +00:00
|
|
|
removeCustomColorOnConversations,
|
2022-12-21 03:25:10 +00:00
|
|
|
removeMember,
|
2021-09-21 22:37:10 +00:00
|
|
|
removeMemberFromGroup,
|
2020-12-04 20:41:40 +00:00
|
|
|
repairNewestMessage,
|
|
|
|
repairOldestMessage,
|
2021-08-06 00:17:05 +00:00
|
|
|
replaceAvatar,
|
2021-05-28 16:15:17 +00:00
|
|
|
resetAllChatColors,
|
2023-04-22 01:52:25 +00:00
|
|
|
copyMessageText,
|
2022-12-20 01:04:47 +00:00
|
|
|
retryDeleteForEveryone,
|
|
|
|
retryMessageSend,
|
2021-06-01 23:30:25 +00:00
|
|
|
reviewGroupMemberNameCollision,
|
2021-04-21 16:31:12 +00:00
|
|
|
reviewMessageRequestNameCollision,
|
2022-12-05 22:56:23 +00:00
|
|
|
revokePendingMembershipsFromGroupV2,
|
2022-12-14 18:12:04 +00:00
|
|
|
saveAttachment,
|
|
|
|
saveAttachmentFromMessage,
|
2021-08-06 00:17:05 +00:00
|
|
|
saveAvatarToDisk,
|
2021-01-29 21:19:24 +00:00
|
|
|
scrollToMessage,
|
2023-05-23 21:59:07 +00:00
|
|
|
scrollToOldestUnreadMention,
|
2023-04-10 16:31:45 +00:00
|
|
|
showSpoiler,
|
2023-03-20 22:23:53 +00:00
|
|
|
targetMessage,
|
2022-06-13 18:42:19 +00:00
|
|
|
setAccessControlAddFromInviteLinkSetting,
|
2022-12-05 22:56:23 +00:00
|
|
|
setAccessControlAttributesSetting,
|
|
|
|
setAccessControlMembersSetting,
|
|
|
|
setAnnouncementsOnly,
|
2021-03-03 20:09:58 +00:00
|
|
|
setComposeGroupAvatar,
|
2021-06-25 23:52:56 +00:00
|
|
|
setComposeGroupExpireTimer,
|
2021-08-06 00:17:05 +00:00
|
|
|
setComposeGroupName,
|
2021-02-23 20:34:28 +00:00
|
|
|
setComposeSearchTerm,
|
2022-12-05 22:56:23 +00:00
|
|
|
setDisappearingMessages,
|
2022-12-06 17:31:44 +00:00
|
|
|
setDontNotifyForMentionsIfMuted,
|
2022-04-05 00:38:22 +00:00
|
|
|
setIsFetchingUUID,
|
2021-01-29 21:19:24 +00:00
|
|
|
setIsNearBottom,
|
2022-03-11 22:31:21 +00:00
|
|
|
setMessageLoadingState,
|
2023-04-20 16:31:59 +00:00
|
|
|
setMessageToEdit,
|
2022-12-06 17:31:44 +00:00
|
|
|
setMuteExpiration,
|
2022-12-07 01:00:02 +00:00
|
|
|
setPinned,
|
2021-01-29 22:16:48 +00:00
|
|
|
setPreJoinConversation,
|
2022-09-15 20:10:46 +00:00
|
|
|
setVoiceNotePlaybackRate,
|
2021-01-29 21:19:24 +00:00
|
|
|
showArchivedConversations,
|
2021-08-06 00:17:05 +00:00
|
|
|
showChooseGroupMembers,
|
2022-04-05 00:38:22 +00:00
|
|
|
showConversation,
|
2022-12-20 01:04:47 +00:00
|
|
|
showExpiredIncomingTapToViewToast,
|
|
|
|
showExpiredOutgoingTapToViewToast,
|
2022-12-05 22:56:23 +00:00
|
|
|
showInbox,
|
2021-02-23 20:34:28 +00:00
|
|
|
startComposing,
|
2022-12-21 03:25:10 +00:00
|
|
|
startConversation,
|
2021-03-03 20:09:58 +00:00
|
|
|
startSettingGroupMetadata,
|
2021-09-21 22:37:10 +00:00
|
|
|
toggleAdmin,
|
2021-08-06 00:17:05 +00:00
|
|
|
toggleComposeEditingAvatar,
|
2022-12-05 22:56:23 +00:00
|
|
|
toggleConversationInChooseMembers,
|
2022-08-30 19:13:32 +00:00
|
|
|
toggleGroupsForStorySend,
|
2022-03-04 21:14:52 +00:00
|
|
|
toggleHideStories,
|
2023-03-20 22:23:53 +00:00
|
|
|
toggleSelectMessage,
|
|
|
|
toggleSelectMode,
|
2022-12-21 03:25:10 +00:00
|
|
|
unblurAvatar,
|
2021-09-21 22:37:10 +00:00
|
|
|
updateConversationModelSharedGroups,
|
2022-12-16 03:12:05 +00:00
|
|
|
updateGroupAttributes,
|
2022-12-21 03:25:10 +00:00
|
|
|
updateSharedGroups,
|
2022-02-16 18:36:21 +00:00
|
|
|
verifyConversationsStoppingSend,
|
2019-01-14 21:49:58 +00:00
|
|
|
};
|
|
|
|
|
2022-12-09 17:35:34 +00:00
|
|
|
export const useConversationsActions = (): BoundActionCreatorsMapObject<
|
|
|
|
typeof actions
|
|
|
|
> => useBoundActions(actions);
|
2022-03-04 21:14:52 +00:00
|
|
|
|
2023-01-02 21:34:41 +00:00
|
|
|
function onArchive(
|
|
|
|
conversationId: string
|
|
|
|
): ThunkAction<
|
|
|
|
void,
|
|
|
|
RootStateType,
|
|
|
|
unknown,
|
|
|
|
ConversationUnloadedActionType | ShowToastActionType
|
|
|
|
> {
|
|
|
|
return (dispatch, getState) => {
|
|
|
|
const conversation = window.ConversationController.get(conversationId);
|
|
|
|
if (!conversation) {
|
|
|
|
throw new Error('onArchive: Conversation not found!');
|
|
|
|
}
|
2022-12-21 03:25:10 +00:00
|
|
|
|
2023-01-02 21:34:41 +00:00
|
|
|
conversation.setArchived(true);
|
2022-12-21 03:25:10 +00:00
|
|
|
|
2023-01-02 21:34:41 +00:00
|
|
|
onConversationClosed(conversationId, 'archive')(
|
|
|
|
dispatch,
|
|
|
|
getState,
|
|
|
|
undefined
|
|
|
|
);
|
|
|
|
|
|
|
|
dispatch({
|
|
|
|
type: SHOW_TOAST,
|
|
|
|
payload: {
|
|
|
|
toastType: ToastType.ConversationArchived,
|
|
|
|
parameters: {
|
|
|
|
conversationId,
|
|
|
|
},
|
2022-12-21 03:25:10 +00:00
|
|
|
},
|
2023-01-02 21:34:41 +00:00
|
|
|
});
|
2022-12-21 03:25:10 +00:00
|
|
|
};
|
|
|
|
}
|
|
|
|
function onUndoArchive(
|
|
|
|
conversationId: string
|
2023-01-05 23:34:47 +00:00
|
|
|
): ThunkAction<
|
|
|
|
void,
|
|
|
|
RootStateType,
|
|
|
|
unknown,
|
2023-03-20 22:23:53 +00:00
|
|
|
TargetedConversationChangedActionType
|
2023-01-05 23:34:47 +00:00
|
|
|
> {
|
|
|
|
return (dispatch, getState) => {
|
|
|
|
const conversation = window.ConversationController.get(conversationId);
|
|
|
|
if (!conversation) {
|
|
|
|
throw new Error('onUndoArchive: Conversation not found!');
|
|
|
|
}
|
2022-12-21 03:25:10 +00:00
|
|
|
|
2023-01-05 23:34:47 +00:00
|
|
|
conversation.setArchived(false);
|
|
|
|
showConversation({
|
|
|
|
conversationId,
|
|
|
|
})(dispatch, getState, null);
|
|
|
|
};
|
2022-12-21 03:25:10 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
function onMarkUnread(conversationId: string): ShowToastActionType {
|
|
|
|
const conversation = window.ConversationController.get(conversationId);
|
|
|
|
if (!conversation) {
|
|
|
|
throw new Error('onMarkUnread: Conversation not found!');
|
|
|
|
}
|
|
|
|
|
|
|
|
conversation.setMarkedUnread(true);
|
|
|
|
|
|
|
|
return {
|
|
|
|
type: SHOW_TOAST,
|
|
|
|
payload: {
|
|
|
|
toastType: ToastType.ConversationMarkedUnread,
|
|
|
|
},
|
|
|
|
};
|
|
|
|
}
|
|
|
|
function onMoveToInbox(conversationId: string): ShowToastActionType {
|
|
|
|
const conversation = window.ConversationController.get(conversationId);
|
|
|
|
if (!conversation) {
|
|
|
|
throw new Error('onMoveToInbox: Conversation not found!');
|
|
|
|
}
|
|
|
|
|
|
|
|
conversation.setArchived(false);
|
|
|
|
|
|
|
|
return {
|
|
|
|
type: SHOW_TOAST,
|
|
|
|
payload: {
|
|
|
|
toastType: ToastType.ConversationUnarchived,
|
|
|
|
},
|
|
|
|
};
|
|
|
|
}
|
|
|
|
|
|
|
|
function acknowledgeGroupMemberNameCollisions(
|
|
|
|
conversationId: string,
|
2023-01-13 20:07:26 +00:00
|
|
|
groupNameCollisions: ReadonlyDeep<GroupNameCollisionsWithIdsByTitle>
|
2022-12-21 03:25:10 +00:00
|
|
|
): NoopActionType {
|
|
|
|
const conversation = window.ConversationController.get(conversationId);
|
|
|
|
if (!conversation) {
|
|
|
|
throw new Error(
|
|
|
|
'acknowledgeGroupMemberNameCollisions: Conversation not found!'
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
|
|
|
conversation.acknowledgeGroupMemberNameCollisions(groupNameCollisions);
|
|
|
|
|
|
|
|
return {
|
|
|
|
type: 'NOOP',
|
|
|
|
payload: null,
|
|
|
|
};
|
|
|
|
}
|
|
|
|
function blockGroupLinkRequests(
|
|
|
|
conversationId: string,
|
|
|
|
uuid: UUIDStringType
|
|
|
|
): NoopActionType {
|
|
|
|
const conversation = window.ConversationController.get(conversationId);
|
|
|
|
if (!conversation) {
|
|
|
|
throw new Error('blockGroupLinkRequests: Conversation not found!');
|
|
|
|
}
|
|
|
|
|
2022-12-21 18:41:48 +00:00
|
|
|
void conversation.blockGroupLinkRequests(uuid);
|
2022-12-21 03:25:10 +00:00
|
|
|
|
|
|
|
return {
|
|
|
|
type: 'NOOP',
|
|
|
|
payload: null,
|
|
|
|
};
|
|
|
|
}
|
|
|
|
function loadNewerMessages(
|
|
|
|
conversationId: string,
|
|
|
|
newestMessageId: string
|
|
|
|
): NoopActionType {
|
|
|
|
const conversation = window.ConversationController.get(conversationId);
|
|
|
|
if (!conversation) {
|
|
|
|
throw new Error('loadNewerMessages: Conversation not found!');
|
|
|
|
}
|
|
|
|
|
2022-12-21 18:41:48 +00:00
|
|
|
void conversation.loadNewerMessages(newestMessageId);
|
2022-12-21 03:25:10 +00:00
|
|
|
|
|
|
|
return {
|
|
|
|
type: 'NOOP',
|
|
|
|
payload: null,
|
|
|
|
};
|
|
|
|
}
|
|
|
|
function loadNewestMessages(
|
|
|
|
conversationId: string,
|
|
|
|
newestMessageId: string | undefined,
|
|
|
|
setFocus: boolean | undefined
|
|
|
|
): NoopActionType {
|
|
|
|
const conversation = window.ConversationController.get(conversationId);
|
|
|
|
if (!conversation) {
|
|
|
|
throw new Error('loadNewestMessages: Conversation not found!');
|
|
|
|
}
|
|
|
|
|
2022-12-21 18:41:48 +00:00
|
|
|
void conversation.loadNewestMessages(newestMessageId, setFocus);
|
2022-12-21 03:25:10 +00:00
|
|
|
|
|
|
|
return {
|
|
|
|
type: 'NOOP',
|
|
|
|
payload: null,
|
|
|
|
};
|
|
|
|
}
|
2023-05-23 21:59:07 +00:00
|
|
|
|
2022-12-21 03:25:10 +00:00
|
|
|
function loadOlderMessages(
|
|
|
|
conversationId: string,
|
|
|
|
oldestMessageId: string
|
|
|
|
): NoopActionType {
|
|
|
|
const conversation = window.ConversationController.get(conversationId);
|
|
|
|
if (!conversation) {
|
|
|
|
throw new Error('loadOlderMessages: Conversation not found!');
|
|
|
|
}
|
|
|
|
|
2022-12-21 18:41:48 +00:00
|
|
|
void conversation.loadOlderMessages(oldestMessageId);
|
2022-12-21 03:25:10 +00:00
|
|
|
return {
|
|
|
|
type: 'NOOP',
|
|
|
|
payload: null,
|
|
|
|
};
|
|
|
|
}
|
|
|
|
|
|
|
|
function markMessageRead(
|
|
|
|
conversationId: string,
|
|
|
|
messageId: string
|
|
|
|
): ThunkAction<void, RootStateType, unknown, NoopActionType> {
|
|
|
|
return async (_dispatch, getState) => {
|
|
|
|
const conversation = window.ConversationController.get(conversationId);
|
|
|
|
if (!conversation) {
|
|
|
|
throw new Error('markMessageRead: Conversation not found!');
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!window.SignalContext.activeWindowService.isActive()) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
const activeCall = getActiveCallState(getState());
|
|
|
|
if (activeCall && !activeCall.pip) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
const message = await getMessageById(messageId);
|
|
|
|
if (!message) {
|
|
|
|
throw new Error(`markMessageRead: failed to load message ${messageId}`);
|
|
|
|
}
|
|
|
|
|
|
|
|
await conversation.markRead(message.get('received_at'), {
|
|
|
|
newestSentAt: message.get('sent_at'),
|
|
|
|
sendReadReceipts: true,
|
|
|
|
});
|
|
|
|
};
|
|
|
|
}
|
2023-05-23 21:59:07 +00:00
|
|
|
|
2022-12-21 03:25:10 +00:00
|
|
|
function removeMember(
|
|
|
|
conversationId: string,
|
|
|
|
memberConversationId: string
|
|
|
|
): NoopActionType {
|
|
|
|
const conversation = window.ConversationController.get(conversationId);
|
|
|
|
if (!conversation) {
|
|
|
|
throw new Error('removeMember: Conversation not found!');
|
|
|
|
}
|
|
|
|
|
2022-12-21 18:41:48 +00:00
|
|
|
void longRunningTaskWrapper({
|
2022-12-21 03:25:10 +00:00
|
|
|
idForLogging: conversation.idForLogging(),
|
|
|
|
name: 'removeMember',
|
|
|
|
task: () => conversation.removeFromGroupV2(memberConversationId),
|
|
|
|
});
|
|
|
|
|
|
|
|
return {
|
|
|
|
type: 'NOOP',
|
|
|
|
payload: null,
|
|
|
|
};
|
|
|
|
}
|
|
|
|
function unblurAvatar(conversationId: string): NoopActionType {
|
|
|
|
const conversation = window.ConversationController.get(conversationId);
|
|
|
|
if (!conversation) {
|
|
|
|
throw new Error('unblurAvatar: Conversation not found!');
|
|
|
|
}
|
|
|
|
|
|
|
|
conversation.unblurAvatar();
|
|
|
|
|
|
|
|
return {
|
|
|
|
type: 'NOOP',
|
|
|
|
payload: null,
|
|
|
|
};
|
|
|
|
}
|
|
|
|
function updateSharedGroups(conversationId: string): NoopActionType {
|
|
|
|
const conversation = window.ConversationController.get(conversationId);
|
|
|
|
if (!conversation) {
|
|
|
|
throw new Error('updateSharedGroups: Conversation not found!');
|
|
|
|
}
|
|
|
|
|
2022-12-21 18:41:48 +00:00
|
|
|
void conversation.throttledUpdateSharedGroups?.();
|
2022-12-21 03:25:10 +00:00
|
|
|
|
|
|
|
return {
|
|
|
|
type: 'NOOP',
|
|
|
|
payload: null,
|
|
|
|
};
|
|
|
|
}
|
|
|
|
|
2021-08-06 00:17:05 +00:00
|
|
|
function filterAvatarData(
|
|
|
|
avatars: ReadonlyArray<AvatarDataType>,
|
|
|
|
data: AvatarDataType
|
|
|
|
): Array<AvatarDataType> {
|
|
|
|
return avatars.filter(avatarData => !isSameAvatarData(data, avatarData));
|
|
|
|
}
|
|
|
|
|
2022-12-22 00:07:02 +00:00
|
|
|
function getNextAvatarId(avatars: ReadonlyArray<AvatarDataType>): number {
|
2021-08-06 00:17:05 +00:00
|
|
|
return Math.max(...avatars.map(x => Number(x.id))) + 1;
|
|
|
|
}
|
|
|
|
|
|
|
|
async function getAvatarsAndUpdateConversation(
|
|
|
|
conversations: ConversationsStateType,
|
|
|
|
conversationId: string,
|
|
|
|
getNextAvatarsData: (
|
2022-12-22 00:07:02 +00:00
|
|
|
avatars: ReadonlyArray<AvatarDataType>,
|
2021-08-06 00:17:05 +00:00
|
|
|
nextId: number
|
2022-12-22 00:07:02 +00:00
|
|
|
) => ReadonlyArray<AvatarDataType>
|
|
|
|
): Promise<ReadonlyArray<AvatarDataType>> {
|
2021-08-06 00:17:05 +00:00
|
|
|
const conversation = window.ConversationController.get(conversationId);
|
|
|
|
if (!conversation) {
|
2022-12-06 17:31:44 +00:00
|
|
|
throw new Error('getAvatarsAndUpdateConversation: No conversation found');
|
2021-08-06 00:17:05 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
const { conversationLookup } = conversations;
|
|
|
|
const conversationAttrs = conversationLookup[conversationId];
|
|
|
|
const avatars =
|
|
|
|
conversationAttrs.avatars || getAvatarData(conversation.attributes);
|
|
|
|
|
|
|
|
const nextAvatarId = getNextAvatarId(avatars);
|
|
|
|
const nextAvatars = getNextAvatarsData(avatars, nextAvatarId);
|
|
|
|
// We don't save buffers to the db, but we definitely want it in-memory so
|
|
|
|
// we don't have to re-generate them.
|
|
|
|
//
|
|
|
|
// Mutating here because we don't want to trigger a model change
|
|
|
|
// because we're updating redux here manually ourselves. Au revoir Backbone!
|
|
|
|
conversation.attributes.avatars = nextAvatars.map(avatarData =>
|
|
|
|
omit(avatarData, ['buffer'])
|
|
|
|
);
|
2022-11-08 20:01:59 +00:00
|
|
|
window.Signal.Data.updateConversation(conversation.attributes);
|
2021-08-06 00:17:05 +00:00
|
|
|
|
|
|
|
return nextAvatars;
|
|
|
|
}
|
|
|
|
|
|
|
|
function deleteAvatarFromDisk(
|
|
|
|
avatarData: AvatarDataType,
|
|
|
|
conversationId?: string
|
|
|
|
): ThunkAction<void, RootStateType, unknown, ReplaceAvatarsActionType> {
|
|
|
|
return async (dispatch, getState) => {
|
|
|
|
if (avatarData.imagePath) {
|
|
|
|
await window.Signal.Migrations.deleteAvatar(avatarData.imagePath);
|
|
|
|
} else {
|
2021-09-17 18:27:53 +00:00
|
|
|
log.info(
|
2021-08-06 00:17:05 +00:00
|
|
|
'No imagePath for avatarData. Removing from userAvatarData, but not disk'
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
|
|
|
strictAssert(conversationId, 'conversationId not provided');
|
|
|
|
|
|
|
|
const avatars = await getAvatarsAndUpdateConversation(
|
|
|
|
getState().conversations,
|
|
|
|
conversationId,
|
|
|
|
prevAvatarsData => filterAvatarData(prevAvatarsData, avatarData)
|
|
|
|
);
|
|
|
|
|
|
|
|
dispatch({
|
|
|
|
type: REPLACE_AVATARS,
|
|
|
|
payload: {
|
|
|
|
conversationId,
|
|
|
|
avatars,
|
|
|
|
},
|
|
|
|
});
|
|
|
|
};
|
|
|
|
}
|
|
|
|
|
2022-06-13 18:42:19 +00:00
|
|
|
function changeHasGroupLink(
|
|
|
|
conversationId: string,
|
|
|
|
value: boolean
|
|
|
|
): ThunkAction<void, RootStateType, unknown, NoopActionType> {
|
|
|
|
return async dispatch => {
|
|
|
|
const conversation = window.ConversationController.get(conversationId);
|
|
|
|
if (!conversation) {
|
2022-12-06 17:31:44 +00:00
|
|
|
throw new Error('changeHasGroupLink: No conversation found');
|
2022-06-13 18:42:19 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
await longRunningTaskWrapper({
|
|
|
|
name: 'toggleGroupLink',
|
|
|
|
idForLogging: conversation.idForLogging(),
|
|
|
|
task: async () => conversation.toggleGroupLink(value),
|
|
|
|
});
|
|
|
|
dispatch({
|
|
|
|
type: 'NOOP',
|
|
|
|
payload: null,
|
|
|
|
});
|
|
|
|
};
|
|
|
|
}
|
|
|
|
|
2022-12-05 22:56:23 +00:00
|
|
|
function setAnnouncementsOnly(
|
|
|
|
conversationId: string,
|
|
|
|
value: boolean
|
|
|
|
): ThunkAction<void, RootStateType, unknown, NoopActionType> {
|
|
|
|
return async dispatch => {
|
|
|
|
const conversation = window.ConversationController.get(conversationId);
|
|
|
|
if (!conversation) {
|
2022-12-06 17:31:44 +00:00
|
|
|
throw new Error('setAnnouncementsOnly: No conversation found');
|
2022-12-05 22:56:23 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
await longRunningTaskWrapper({
|
|
|
|
name: 'updateAnnouncementsOnly',
|
|
|
|
idForLogging: conversation.idForLogging(),
|
|
|
|
task: async () => conversation.updateAnnouncementsOnly(value),
|
|
|
|
});
|
|
|
|
dispatch({
|
|
|
|
type: 'NOOP',
|
|
|
|
payload: null,
|
|
|
|
});
|
|
|
|
};
|
|
|
|
}
|
|
|
|
|
|
|
|
function setAccessControlMembersSetting(
|
|
|
|
conversationId: string,
|
|
|
|
value: number
|
|
|
|
): ThunkAction<void, RootStateType, unknown, NoopActionType> {
|
|
|
|
return async dispatch => {
|
|
|
|
const conversation = window.ConversationController.get(conversationId);
|
|
|
|
if (!conversation) {
|
2022-12-06 17:31:44 +00:00
|
|
|
throw new Error('setAccessControlMembersSetting: No conversation found');
|
2022-12-05 22:56:23 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
await longRunningTaskWrapper({
|
|
|
|
name: 'updateAccessControlMembers',
|
|
|
|
idForLogging: conversation.idForLogging(),
|
|
|
|
task: async () => conversation.updateAccessControlMembers(value),
|
|
|
|
});
|
|
|
|
dispatch({
|
|
|
|
type: 'NOOP',
|
|
|
|
payload: null,
|
|
|
|
});
|
|
|
|
};
|
|
|
|
}
|
|
|
|
|
|
|
|
function setAccessControlAttributesSetting(
|
|
|
|
conversationId: string,
|
|
|
|
value: number
|
|
|
|
): ThunkAction<void, RootStateType, unknown, NoopActionType> {
|
|
|
|
return async dispatch => {
|
|
|
|
const conversation = window.ConversationController.get(conversationId);
|
|
|
|
if (!conversation) {
|
2022-12-06 17:31:44 +00:00
|
|
|
throw new Error(
|
|
|
|
'setAccessControlAttributesSetting: No conversation found'
|
|
|
|
);
|
2022-12-05 22:56:23 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
await longRunningTaskWrapper({
|
|
|
|
name: 'updateAccessControlAttributes',
|
|
|
|
idForLogging: conversation.idForLogging(),
|
|
|
|
task: async () => conversation.updateAccessControlAttributes(value),
|
|
|
|
});
|
|
|
|
dispatch({
|
|
|
|
type: 'NOOP',
|
|
|
|
payload: null,
|
|
|
|
});
|
|
|
|
};
|
|
|
|
}
|
|
|
|
|
|
|
|
function setDisappearingMessages(
|
|
|
|
conversationId: string,
|
|
|
|
seconds: DurationInSeconds
|
|
|
|
): ThunkAction<void, RootStateType, unknown, NoopActionType> {
|
|
|
|
return async dispatch => {
|
|
|
|
const conversation = window.ConversationController.get(conversationId);
|
|
|
|
if (!conversation) {
|
2022-12-06 17:31:44 +00:00
|
|
|
throw new Error('setDisappearingMessages: No conversation found');
|
2022-12-05 22:56:23 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
const valueToSet = seconds > 0 ? seconds : undefined;
|
|
|
|
|
|
|
|
await longRunningTaskWrapper({
|
|
|
|
name: 'updateExpirationTimer',
|
|
|
|
idForLogging: conversation.idForLogging(),
|
|
|
|
task: async () =>
|
|
|
|
conversation.updateExpirationTimer(valueToSet, {
|
|
|
|
reason: 'setDisappearingMessages',
|
|
|
|
}),
|
|
|
|
});
|
|
|
|
dispatch({
|
|
|
|
type: 'NOOP',
|
|
|
|
payload: null,
|
|
|
|
});
|
|
|
|
};
|
|
|
|
}
|
|
|
|
|
2022-12-06 17:31:44 +00:00
|
|
|
function setDontNotifyForMentionsIfMuted(
|
|
|
|
conversationId: string,
|
|
|
|
newValue: boolean
|
|
|
|
): NoopActionType {
|
|
|
|
const conversation = window.ConversationController.get(conversationId);
|
|
|
|
if (!conversation) {
|
|
|
|
throw new Error('setDontNotifyForMentionsIfMuted: No conversation found');
|
|
|
|
}
|
|
|
|
|
|
|
|
conversation.setDontNotifyForMentionsIfMuted(newValue);
|
|
|
|
|
|
|
|
return {
|
|
|
|
type: 'NOOP',
|
|
|
|
payload: null,
|
|
|
|
};
|
|
|
|
}
|
|
|
|
|
|
|
|
function setMuteExpiration(
|
|
|
|
conversationId: string,
|
|
|
|
muteExpiresAt = 0
|
|
|
|
): NoopActionType {
|
|
|
|
const conversation = window.ConversationController.get(conversationId);
|
|
|
|
if (!conversation) {
|
|
|
|
throw new Error('setMuteExpiration: No conversation found');
|
|
|
|
}
|
|
|
|
|
|
|
|
conversation.setMuteExpiration(
|
|
|
|
muteExpiresAt >= Number.MAX_SAFE_INTEGER
|
|
|
|
? muteExpiresAt
|
|
|
|
: Date.now() + muteExpiresAt
|
|
|
|
);
|
|
|
|
|
|
|
|
return {
|
|
|
|
type: 'NOOP',
|
|
|
|
payload: null,
|
|
|
|
};
|
|
|
|
}
|
|
|
|
|
2022-12-07 01:00:02 +00:00
|
|
|
function setPinned(
|
|
|
|
conversationId: string,
|
|
|
|
value: boolean
|
|
|
|
): NoopActionType | ShowToastActionType {
|
|
|
|
const conversation = window.ConversationController.get(conversationId);
|
|
|
|
if (!conversation) {
|
|
|
|
throw new Error('setPinned: No conversation found');
|
|
|
|
}
|
|
|
|
|
|
|
|
if (value) {
|
|
|
|
const pinnedConversationIds = window.storage.get(
|
|
|
|
'pinnedConversationIds',
|
|
|
|
new Array<string>()
|
|
|
|
);
|
|
|
|
|
|
|
|
if (pinnedConversationIds.length >= 4) {
|
|
|
|
return {
|
|
|
|
type: SHOW_TOAST,
|
|
|
|
payload: {
|
|
|
|
toastType: ToastType.PinnedConversationsFull,
|
|
|
|
},
|
|
|
|
};
|
|
|
|
}
|
|
|
|
conversation.pin();
|
|
|
|
} else {
|
|
|
|
conversation.unpin();
|
|
|
|
}
|
|
|
|
|
|
|
|
return {
|
|
|
|
type: 'NOOP',
|
|
|
|
payload: null,
|
|
|
|
};
|
|
|
|
}
|
|
|
|
|
2023-03-20 22:23:53 +00:00
|
|
|
function deleteMessages({
|
2022-12-14 22:45:39 +00:00
|
|
|
conversationId,
|
2023-03-20 22:23:53 +00:00
|
|
|
messageIds,
|
|
|
|
lastSelectedMessage,
|
2022-12-14 22:45:39 +00:00
|
|
|
}: {
|
|
|
|
conversationId: string;
|
2023-03-20 22:23:53 +00:00
|
|
|
messageIds: ReadonlyArray<string>;
|
|
|
|
lastSelectedMessage?: MessageTimestamps;
|
2022-12-14 22:45:39 +00:00
|
|
|
}): ThunkAction<void, RootStateType, unknown, NoopActionType> {
|
|
|
|
return async (dispatch, getState) => {
|
2023-03-20 22:23:53 +00:00
|
|
|
if (!messageIds || messageIds.length === 0) {
|
|
|
|
log.warn('deleteMessages: No message ids provided');
|
|
|
|
return;
|
2022-12-14 22:45:39 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
const conversation = window.ConversationController.get(conversationId);
|
|
|
|
if (!conversation) {
|
|
|
|
throw new Error('deleteMessage: No conversation found');
|
|
|
|
}
|
|
|
|
|
2023-03-20 22:23:53 +00:00
|
|
|
await Promise.all(
|
|
|
|
messageIds.map(async messageId => {
|
|
|
|
const message = await getMessageById(messageId);
|
|
|
|
if (!message) {
|
|
|
|
throw new Error(`deleteMessages: Message ${messageId} missing!`);
|
|
|
|
}
|
|
|
|
|
|
|
|
const messageConversationId = message.get('conversationId');
|
|
|
|
if (conversationId !== messageConversationId) {
|
|
|
|
throw new Error(
|
|
|
|
`deleteMessages: message conversation ${messageConversationId} doesn't match provided conversation ${conversationId}`
|
|
|
|
);
|
|
|
|
}
|
|
|
|
})
|
|
|
|
);
|
|
|
|
|
|
|
|
let nearbyMessageId: string | null = null;
|
|
|
|
|
|
|
|
if (nearbyMessageId == null && lastSelectedMessage != null) {
|
|
|
|
const foundMessageId =
|
|
|
|
await window.Signal.Data.getNearbyMessageFromDeletedSet({
|
|
|
|
conversationId,
|
|
|
|
lastSelectedMessage,
|
|
|
|
deletedMessageIds: messageIds,
|
|
|
|
includeStoryReplies: false,
|
|
|
|
storyId: undefined,
|
|
|
|
});
|
|
|
|
|
|
|
|
if (foundMessageId != null) {
|
|
|
|
nearbyMessageId = foundMessageId;
|
|
|
|
}
|
2022-12-14 22:45:39 +00:00
|
|
|
}
|
|
|
|
|
2023-03-20 22:23:53 +00:00
|
|
|
await window.Signal.Data.removeMessages(messageIds);
|
|
|
|
|
2022-12-21 20:44:23 +00:00
|
|
|
popPanelForConversation()(dispatch, getState, undefined);
|
2022-12-14 22:45:39 +00:00
|
|
|
|
2023-03-20 22:23:53 +00:00
|
|
|
if (nearbyMessageId != null) {
|
|
|
|
dispatch(scrollToMessage(conversationId, nearbyMessageId));
|
|
|
|
}
|
2022-12-14 22:45:39 +00:00
|
|
|
};
|
|
|
|
}
|
|
|
|
|
2022-12-05 22:56:23 +00:00
|
|
|
function destroyMessages(
|
|
|
|
conversationId: string
|
2023-01-02 21:34:41 +00:00
|
|
|
): ThunkAction<
|
|
|
|
void,
|
|
|
|
RootStateType,
|
|
|
|
unknown,
|
|
|
|
ConversationUnloadedActionType | NoopActionType
|
|
|
|
> {
|
|
|
|
return async (dispatch, getState) => {
|
2022-12-05 22:56:23 +00:00
|
|
|
const conversation = window.ConversationController.get(conversationId);
|
|
|
|
if (!conversation) {
|
2022-12-06 17:31:44 +00:00
|
|
|
throw new Error('destroyMessages: No conversation found');
|
2022-12-05 22:56:23 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
await longRunningTaskWrapper({
|
|
|
|
name: 'destroymessages',
|
|
|
|
idForLogging: conversation.idForLogging(),
|
|
|
|
task: async () => {
|
2023-01-02 21:34:41 +00:00
|
|
|
onConversationClosed(conversationId, 'delete messages')(
|
|
|
|
dispatch,
|
|
|
|
getState,
|
|
|
|
undefined
|
|
|
|
);
|
|
|
|
|
2022-12-05 22:56:23 +00:00
|
|
|
await conversation.destroyMessages();
|
2023-01-02 21:34:41 +00:00
|
|
|
drop(conversation.updateLastMessage());
|
2022-12-05 22:56:23 +00:00
|
|
|
},
|
|
|
|
});
|
|
|
|
|
|
|
|
dispatch({
|
|
|
|
type: 'NOOP',
|
|
|
|
payload: null,
|
|
|
|
});
|
|
|
|
};
|
|
|
|
}
|
|
|
|
|
2023-04-20 16:31:59 +00:00
|
|
|
function discardEditMessage(
|
|
|
|
conversationId: string
|
|
|
|
): ThunkAction<void, RootStateType, unknown, never> {
|
|
|
|
return () => {
|
|
|
|
window.ConversationController.get(conversationId)?.set(
|
|
|
|
{
|
|
|
|
draftEditMessage: undefined,
|
|
|
|
draftBodyRanges: undefined,
|
|
|
|
draft: undefined,
|
|
|
|
quotedMessageId: undefined,
|
|
|
|
},
|
|
|
|
{ unset: true }
|
|
|
|
);
|
|
|
|
};
|
|
|
|
}
|
|
|
|
|
|
|
|
function setMessageToEdit(
|
|
|
|
conversationId: string,
|
|
|
|
messageId: string
|
|
|
|
): ThunkAction<void, RootStateType, unknown, SetFocusActionType> {
|
|
|
|
return async (dispatch, getState) => {
|
|
|
|
const conversation = window.ConversationController.get(conversationId);
|
|
|
|
|
|
|
|
if (!conversation) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
const message = (await getMessageById(messageId))?.attributes;
|
|
|
|
if (!message) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2023-05-12 00:27:19 +00:00
|
|
|
if (!canEditMessage(message) || !message.body) {
|
2023-04-20 16:31:59 +00:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2023-06-13 16:46:06 +00:00
|
|
|
setQuoteByMessageId(conversationId, undefined)(
|
|
|
|
dispatch,
|
|
|
|
getState,
|
|
|
|
undefined
|
|
|
|
);
|
|
|
|
|
2023-04-20 16:31:59 +00:00
|
|
|
let attachmentThumbnail: string | undefined;
|
|
|
|
if (message.attachments) {
|
|
|
|
const thumbnailPath = message.attachments[0]?.thumbnail?.path;
|
|
|
|
attachmentThumbnail = thumbnailPath
|
|
|
|
? window.Signal.Migrations.getAbsoluteAttachmentPath(thumbnailPath)
|
|
|
|
: undefined;
|
|
|
|
}
|
|
|
|
|
|
|
|
conversation.set({
|
|
|
|
draftEditMessage: {
|
|
|
|
body: message.body,
|
|
|
|
editHistoryLength: message.editHistory?.length ?? 0,
|
|
|
|
attachmentThumbnail,
|
|
|
|
preview: message.preview ? message.preview[0] : undefined,
|
|
|
|
targetMessageId: messageId,
|
|
|
|
quote: message.quote,
|
|
|
|
},
|
|
|
|
draftBodyRanges: processBodyRanges(message, {
|
|
|
|
conversationSelector: getConversationSelector(getState()),
|
|
|
|
}),
|
|
|
|
});
|
|
|
|
|
|
|
|
dispatch({
|
|
|
|
type: SET_FOCUS,
|
|
|
|
payload: {
|
|
|
|
conversationId,
|
|
|
|
},
|
|
|
|
});
|
|
|
|
};
|
|
|
|
}
|
|
|
|
|
2022-06-13 18:42:19 +00:00
|
|
|
function generateNewGroupLink(
|
|
|
|
conversationId: string
|
|
|
|
): ThunkAction<void, RootStateType, unknown, NoopActionType> {
|
|
|
|
return async dispatch => {
|
|
|
|
const conversation = window.ConversationController.get(conversationId);
|
|
|
|
if (!conversation) {
|
2022-12-06 17:31:44 +00:00
|
|
|
throw new Error('generateNewGroupLink: No conversation found');
|
2022-06-13 18:42:19 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
await longRunningTaskWrapper({
|
|
|
|
name: 'refreshGroupLink',
|
|
|
|
idForLogging: conversation.idForLogging(),
|
|
|
|
task: async () => conversation.refreshGroupLink(),
|
|
|
|
});
|
|
|
|
|
|
|
|
dispatch({
|
|
|
|
type: 'NOOP',
|
|
|
|
payload: null,
|
|
|
|
});
|
|
|
|
};
|
|
|
|
}
|
|
|
|
|
2022-10-03 23:43:44 +00:00
|
|
|
/**
|
|
|
|
* Not an actual redux action creator, so it doesn't produce an action (or dispatch
|
|
|
|
* itself) because updates are managed through the backbone model, which will trigger
|
|
|
|
* necessary updates and refresh conversation_view.
|
|
|
|
*
|
|
|
|
* In practice, it's similar to an already-connected thunk action. Later on we will
|
|
|
|
* replace it with an actual action that fits in with the redux approach.
|
|
|
|
*/
|
|
|
|
export const markViewed = (messageId: string): void => {
|
|
|
|
const message = window.MessageController.getById(messageId);
|
|
|
|
if (!message) {
|
|
|
|
throw new Error(`markViewed: Message ${messageId} missing!`);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (message.get('readStatus') === ReadStatus.Viewed) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
const senderE164 = message.get('source');
|
|
|
|
const senderUuid = message.get('sourceUuid');
|
2023-05-16 17:37:12 +00:00
|
|
|
const timestamp = getMessageSentTimestamp(message.attributes, { log });
|
2022-10-03 23:43:44 +00:00
|
|
|
|
|
|
|
message.set(messageUpdaterMarkViewed(message.attributes, Date.now()));
|
|
|
|
|
|
|
|
if (isIncoming(message.attributes)) {
|
2023-01-05 21:58:13 +00:00
|
|
|
const convoAttributes = message.getConversation()?.attributes;
|
2023-02-06 17:24:34 +00:00
|
|
|
const conversationId = message.get('conversationId');
|
2022-12-21 18:41:48 +00:00
|
|
|
drop(
|
2023-02-06 17:24:34 +00:00
|
|
|
conversationJobQueue.add({
|
|
|
|
type: conversationQueueJobEnum.enum.Receipts,
|
|
|
|
conversationId,
|
|
|
|
receiptsType: ReceiptType.Viewed,
|
|
|
|
receipts: [
|
|
|
|
{
|
|
|
|
messageId,
|
|
|
|
conversationId,
|
|
|
|
senderE164,
|
|
|
|
senderUuid,
|
|
|
|
timestamp,
|
|
|
|
isDirectConversation: convoAttributes
|
|
|
|
? isDirectConversation(convoAttributes)
|
|
|
|
: true,
|
|
|
|
},
|
|
|
|
],
|
2022-12-21 18:41:48 +00:00
|
|
|
})
|
|
|
|
);
|
2022-10-03 23:43:44 +00:00
|
|
|
}
|
|
|
|
|
2022-12-21 18:41:48 +00:00
|
|
|
drop(
|
|
|
|
viewSyncJobQueue.add({
|
|
|
|
viewSyncs: [
|
|
|
|
{
|
|
|
|
messageId,
|
|
|
|
senderE164,
|
|
|
|
senderUuid,
|
|
|
|
timestamp,
|
|
|
|
},
|
|
|
|
],
|
|
|
|
})
|
|
|
|
);
|
2022-10-03 23:43:44 +00:00
|
|
|
};
|
|
|
|
|
2022-06-13 18:42:19 +00:00
|
|
|
function setAccessControlAddFromInviteLinkSetting(
|
|
|
|
conversationId: string,
|
|
|
|
value: boolean
|
|
|
|
): ThunkAction<void, RootStateType, unknown, NoopActionType> {
|
|
|
|
return async dispatch => {
|
|
|
|
const conversation = window.ConversationController.get(conversationId);
|
|
|
|
if (!conversation) {
|
2022-12-06 17:31:44 +00:00
|
|
|
throw new Error(
|
|
|
|
'setAccessControlAddFromInviteLinkSetting: No conversation found'
|
|
|
|
);
|
2022-06-13 18:42:19 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
await longRunningTaskWrapper({
|
|
|
|
idForLogging: conversation.idForLogging(),
|
|
|
|
name: 'updateAccessControlAddFromInviteLink',
|
|
|
|
task: async () =>
|
|
|
|
conversation.updateAccessControlAddFromInviteLink(value),
|
|
|
|
});
|
|
|
|
|
|
|
|
dispatch({
|
|
|
|
type: 'NOOP',
|
|
|
|
payload: null,
|
|
|
|
});
|
|
|
|
};
|
|
|
|
}
|
|
|
|
|
2022-03-03 20:23:10 +00:00
|
|
|
function discardMessages(
|
|
|
|
payload: Readonly<DiscardMessagesActionType['payload']>
|
|
|
|
): DiscardMessagesActionType {
|
|
|
|
return { type: DISCARD_MESSAGES, payload };
|
|
|
|
}
|
|
|
|
|
2021-08-06 00:17:05 +00:00
|
|
|
function replaceAvatar(
|
|
|
|
curr: AvatarDataType,
|
|
|
|
prev?: AvatarDataType,
|
|
|
|
conversationId?: string
|
|
|
|
): ThunkAction<void, RootStateType, unknown, ReplaceAvatarsActionType> {
|
|
|
|
return async (dispatch, getState) => {
|
|
|
|
strictAssert(conversationId, 'conversationId not provided');
|
|
|
|
|
|
|
|
const avatars = await getAvatarsAndUpdateConversation(
|
|
|
|
getState().conversations,
|
|
|
|
conversationId,
|
|
|
|
(prevAvatarsData, nextId) => {
|
|
|
|
const newAvatarData = {
|
|
|
|
...curr,
|
|
|
|
id: prev?.id ?? nextId,
|
|
|
|
};
|
|
|
|
const existingAvatarsData = prev
|
|
|
|
? filterAvatarData(prevAvatarsData, prev)
|
|
|
|
: prevAvatarsData;
|
|
|
|
|
|
|
|
return [newAvatarData, ...existingAvatarsData];
|
|
|
|
}
|
|
|
|
);
|
|
|
|
|
|
|
|
dispatch({
|
|
|
|
type: REPLACE_AVATARS,
|
|
|
|
payload: {
|
|
|
|
conversationId,
|
|
|
|
avatars,
|
|
|
|
},
|
|
|
|
});
|
|
|
|
};
|
|
|
|
}
|
|
|
|
|
|
|
|
function saveAvatarToDisk(
|
|
|
|
avatarData: AvatarDataType,
|
|
|
|
conversationId?: string
|
|
|
|
): ThunkAction<void, RootStateType, unknown, ReplaceAvatarsActionType> {
|
|
|
|
return async (dispatch, getState) => {
|
|
|
|
if (!avatarData.buffer) {
|
2022-12-06 17:31:44 +00:00
|
|
|
throw new Error('saveAvatarToDisk: No avatar Uint8Array provided');
|
2021-08-06 00:17:05 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
strictAssert(conversationId, 'conversationId not provided');
|
|
|
|
|
|
|
|
const imagePath = await window.Signal.Migrations.writeNewAvatarData(
|
|
|
|
avatarData.buffer
|
|
|
|
);
|
|
|
|
|
|
|
|
const avatars = await getAvatarsAndUpdateConversation(
|
|
|
|
getState().conversations,
|
|
|
|
conversationId,
|
|
|
|
(prevAvatarsData, id) => {
|
|
|
|
const newAvatarData = {
|
|
|
|
...avatarData,
|
|
|
|
imagePath,
|
|
|
|
id,
|
|
|
|
};
|
|
|
|
|
|
|
|
return [newAvatarData, ...prevAvatarsData];
|
|
|
|
}
|
|
|
|
);
|
|
|
|
|
|
|
|
dispatch({
|
|
|
|
type: REPLACE_AVATARS,
|
|
|
|
payload: {
|
|
|
|
conversationId,
|
|
|
|
avatars,
|
|
|
|
},
|
|
|
|
});
|
|
|
|
};
|
|
|
|
}
|
|
|
|
|
2021-07-19 19:26:06 +00:00
|
|
|
function myProfileChanged(
|
|
|
|
profileData: ProfileDataType,
|
2022-03-16 00:14:20 +00:00
|
|
|
avatar: AvatarUpdateType
|
2021-07-19 19:26:06 +00:00
|
|
|
): ThunkAction<
|
|
|
|
void,
|
|
|
|
RootStateType,
|
|
|
|
unknown,
|
|
|
|
NoopActionType | ToggleProfileEditorErrorActionType
|
|
|
|
> {
|
|
|
|
return async (dispatch, getState) => {
|
|
|
|
const conversation = getMe(getState());
|
|
|
|
|
|
|
|
try {
|
|
|
|
await writeProfile(
|
|
|
|
{
|
|
|
|
...conversation,
|
|
|
|
...profileData,
|
|
|
|
},
|
2022-03-16 00:14:20 +00:00
|
|
|
avatar
|
2021-07-19 19:26:06 +00:00
|
|
|
);
|
|
|
|
|
|
|
|
// writeProfile above updates the backbone model which in turn updates
|
|
|
|
// redux through it's on:change event listener. Once we lose Backbone
|
|
|
|
// we'll need to manually sync these new changes.
|
|
|
|
dispatch({
|
|
|
|
type: 'NOOP',
|
|
|
|
payload: null,
|
|
|
|
});
|
|
|
|
} catch (err) {
|
2022-11-22 18:43:43 +00:00
|
|
|
log.error('myProfileChanged', Errors.toLogFormat(err));
|
2021-07-19 19:26:06 +00:00
|
|
|
dispatch({ type: TOGGLE_PROFILE_EDITOR_ERROR });
|
|
|
|
}
|
|
|
|
};
|
|
|
|
}
|
|
|
|
|
2021-05-28 16:15:17 +00:00
|
|
|
function removeCustomColorOnConversations(
|
|
|
|
colorId: string
|
|
|
|
): ThunkAction<void, RootStateType, unknown, CustomColorRemovedActionType> {
|
|
|
|
return async dispatch => {
|
|
|
|
const conversationsToUpdate: Array<ConversationAttributesType> = [];
|
|
|
|
// We don't want to trigger a model change because we're updating redux
|
|
|
|
// here manually ourselves. Au revoir Backbone!
|
|
|
|
window.getConversations().forEach(conversation => {
|
|
|
|
if (conversation.get('customColorId') === colorId) {
|
|
|
|
// eslint-disable-next-line no-param-reassign
|
|
|
|
delete conversation.attributes.conversationColor;
|
|
|
|
// eslint-disable-next-line no-param-reassign
|
|
|
|
delete conversation.attributes.customColor;
|
|
|
|
// eslint-disable-next-line no-param-reassign
|
|
|
|
delete conversation.attributes.customColorId;
|
|
|
|
|
|
|
|
conversationsToUpdate.push(conversation.attributes);
|
|
|
|
}
|
|
|
|
});
|
|
|
|
|
|
|
|
if (conversationsToUpdate.length) {
|
|
|
|
await window.Signal.Data.updateConversations(conversationsToUpdate);
|
|
|
|
}
|
|
|
|
|
|
|
|
dispatch({
|
|
|
|
type: CUSTOM_COLOR_REMOVED,
|
2021-06-02 21:05:09 +00:00
|
|
|
payload: {
|
|
|
|
colorId,
|
|
|
|
},
|
2021-05-28 16:15:17 +00:00
|
|
|
});
|
|
|
|
};
|
|
|
|
}
|
|
|
|
|
|
|
|
function resetAllChatColors(): ThunkAction<
|
|
|
|
void,
|
|
|
|
RootStateType,
|
|
|
|
unknown,
|
|
|
|
ColorsChangedActionType
|
|
|
|
> {
|
|
|
|
return async dispatch => {
|
|
|
|
// Calling this with no args unsets all the colors in the db
|
|
|
|
await window.Signal.Data.updateAllConversationColors();
|
|
|
|
|
|
|
|
// We don't want to trigger a model change because we're updating redux
|
|
|
|
// here manually ourselves. Au revoir Backbone!
|
|
|
|
window.getConversations().forEach(conversation => {
|
|
|
|
// eslint-disable-next-line no-param-reassign
|
|
|
|
delete conversation.attributes.conversationColor;
|
|
|
|
// eslint-disable-next-line no-param-reassign
|
|
|
|
delete conversation.attributes.customColor;
|
|
|
|
// eslint-disable-next-line no-param-reassign
|
|
|
|
delete conversation.attributes.customColorId;
|
|
|
|
});
|
|
|
|
|
|
|
|
dispatch({
|
|
|
|
type: COLORS_CHANGED,
|
|
|
|
payload: {
|
2021-08-25 00:15:12 +00:00
|
|
|
conversationColor: undefined,
|
|
|
|
customColorData: undefined,
|
2021-05-28 16:15:17 +00:00
|
|
|
},
|
|
|
|
});
|
|
|
|
};
|
|
|
|
}
|
|
|
|
|
2022-12-20 01:04:47 +00:00
|
|
|
function kickOffAttachmentDownload(
|
|
|
|
options: Readonly<{ messageId: string }>
|
|
|
|
): ThunkAction<void, RootStateType, unknown, NoopActionType> {
|
|
|
|
return async dispatch => {
|
|
|
|
const message = await getMessageById(options.messageId);
|
|
|
|
if (!message) {
|
|
|
|
throw new Error(
|
|
|
|
`kickOffAttachmentDownload: Message ${options.messageId} missing!`
|
|
|
|
);
|
|
|
|
}
|
2023-03-27 23:48:57 +00:00
|
|
|
const didUpdateValues = await message.queueAttachmentDownloads();
|
|
|
|
|
|
|
|
if (didUpdateValues) {
|
|
|
|
drop(
|
|
|
|
window.Signal.Data.saveMessage(message.attributes, {
|
|
|
|
ourUuid: window.textsecure.storage.user.getCheckedUuid().toString(),
|
|
|
|
})
|
|
|
|
);
|
|
|
|
}
|
2022-12-20 01:04:47 +00:00
|
|
|
|
|
|
|
dispatch({
|
|
|
|
type: 'NOOP',
|
|
|
|
payload: null,
|
|
|
|
});
|
|
|
|
};
|
|
|
|
}
|
|
|
|
|
2023-01-13 20:07:26 +00:00
|
|
|
type AttachmentOptions = ReadonlyDeep<{
|
2022-12-20 01:04:47 +00:00
|
|
|
messageId: string;
|
|
|
|
attachment: AttachmentType;
|
2023-01-13 20:07:26 +00:00
|
|
|
}>;
|
2022-12-20 01:04:47 +00:00
|
|
|
|
|
|
|
function markAttachmentAsCorrupted(
|
|
|
|
options: AttachmentOptions
|
|
|
|
): ThunkAction<void, RootStateType, unknown, NoopActionType> {
|
|
|
|
return async dispatch => {
|
|
|
|
const message = await getMessageById(options.messageId);
|
|
|
|
if (!message) {
|
|
|
|
throw new Error(
|
|
|
|
`markAttachmentAsCorrupted: Message ${options.messageId} missing!`
|
|
|
|
);
|
|
|
|
}
|
|
|
|
message.markAttachmentAsCorrupted(options.attachment);
|
|
|
|
|
|
|
|
dispatch({
|
|
|
|
type: 'NOOP',
|
|
|
|
payload: null,
|
|
|
|
});
|
|
|
|
};
|
|
|
|
}
|
|
|
|
|
|
|
|
function openGiftBadge(
|
|
|
|
messageId: string
|
|
|
|
): ThunkAction<void, RootStateType, unknown, ShowToastActionType> {
|
|
|
|
return async dispatch => {
|
|
|
|
const message = await getMessageById(messageId);
|
|
|
|
if (!message) {
|
|
|
|
throw new Error(`openGiftBadge: Message ${messageId} missing!`);
|
|
|
|
}
|
|
|
|
|
|
|
|
dispatch({
|
|
|
|
type: SHOW_TOAST,
|
|
|
|
payload: {
|
|
|
|
toastType: isIncoming(message.attributes)
|
|
|
|
? ToastType.CannotOpenGiftBadgeIncoming
|
|
|
|
: ToastType.CannotOpenGiftBadgeOutgoing,
|
|
|
|
},
|
|
|
|
});
|
|
|
|
};
|
|
|
|
}
|
|
|
|
|
|
|
|
function retryMessageSend(
|
|
|
|
messageId: string
|
|
|
|
): ThunkAction<void, RootStateType, unknown, NoopActionType> {
|
|
|
|
return async dispatch => {
|
|
|
|
const message = await getMessageById(messageId);
|
|
|
|
if (!message) {
|
|
|
|
throw new Error(`retryMessageSend: Message ${messageId} missing!`);
|
|
|
|
}
|
|
|
|
await message.retrySend();
|
|
|
|
|
|
|
|
dispatch({
|
|
|
|
type: 'NOOP',
|
|
|
|
payload: null,
|
|
|
|
});
|
|
|
|
};
|
|
|
|
}
|
2023-04-22 01:52:25 +00:00
|
|
|
|
|
|
|
export function copyMessageText(
|
|
|
|
messageId: string
|
|
|
|
): ThunkAction<void, RootStateType, unknown, NoopActionType> {
|
|
|
|
return async dispatch => {
|
|
|
|
const message = await getMessageById(messageId);
|
|
|
|
if (!message) {
|
|
|
|
throw new Error(`copy: Message ${messageId} missing!`);
|
|
|
|
}
|
|
|
|
|
|
|
|
const body = message.getNotificationText();
|
|
|
|
clipboard.writeText(body);
|
|
|
|
|
|
|
|
dispatch({
|
|
|
|
type: 'NOOP',
|
|
|
|
payload: null,
|
|
|
|
});
|
|
|
|
};
|
|
|
|
}
|
2022-12-20 01:04:47 +00:00
|
|
|
|
|
|
|
export function retryDeleteForEveryone(
|
|
|
|
messageId: string
|
|
|
|
): ThunkAction<void, RootStateType, unknown, NoopActionType> {
|
|
|
|
return async dispatch => {
|
|
|
|
const message = await getMessageById(messageId);
|
|
|
|
if (!message) {
|
|
|
|
throw new Error(`retryDeleteForEveryone: Message ${messageId} missing!`);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (isOlderThan(message.get('sent_at'), DAY)) {
|
|
|
|
throw new Error(
|
|
|
|
'retryDeleteForEveryone: Message too old to retry delete for everyone!'
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
|
|
|
try {
|
|
|
|
const conversation = message.getConversation();
|
|
|
|
if (!conversation) {
|
|
|
|
throw new Error(
|
|
|
|
`retryDeleteForEveryone: Conversation for ${messageId} missing!`
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
|
|
|
const jobData: ConversationQueueJobData = {
|
|
|
|
type: conversationQueueJobEnum.enum.DeleteForEveryone,
|
|
|
|
conversationId: conversation.id,
|
|
|
|
messageId,
|
|
|
|
recipients: conversation.getRecipients(),
|
|
|
|
revision: conversation.get('revision'),
|
|
|
|
targetTimestamp: message.get('sent_at'),
|
|
|
|
};
|
|
|
|
|
|
|
|
log.info(
|
|
|
|
`retryDeleteForEveryone: Adding job for message ${message.idForLogging()}!`
|
|
|
|
);
|
|
|
|
await conversationJobQueue.add(jobData);
|
|
|
|
|
|
|
|
dispatch({
|
|
|
|
type: 'NOOP',
|
|
|
|
payload: null,
|
|
|
|
});
|
|
|
|
} catch (error) {
|
|
|
|
log.error(
|
|
|
|
'retryDeleteForEveryone: Failed to queue delete for everyone',
|
|
|
|
Errors.toLogFormat(error)
|
|
|
|
);
|
|
|
|
}
|
|
|
|
};
|
|
|
|
}
|
|
|
|
|
2022-09-15 20:10:46 +00:00
|
|
|
// update the conversation voice note playback rate preference for the conversation
|
|
|
|
export function setVoiceNotePlaybackRate({
|
|
|
|
conversationId,
|
|
|
|
rate,
|
|
|
|
}: {
|
|
|
|
conversationId: string;
|
|
|
|
rate: number;
|
|
|
|
}): ThunkAction<void, RootStateType, unknown, ConversationChangedActionType> {
|
|
|
|
return async dispatch => {
|
|
|
|
const conversationModel = window.ConversationController.get(conversationId);
|
|
|
|
if (conversationModel) {
|
|
|
|
if (rate === 1) {
|
|
|
|
delete conversationModel.attributes.voiceNotePlaybackRate;
|
|
|
|
} else {
|
|
|
|
conversationModel.attributes.voiceNotePlaybackRate = rate;
|
|
|
|
}
|
2022-11-08 20:01:59 +00:00
|
|
|
window.Signal.Data.updateConversation(conversationModel.attributes);
|
2022-09-15 20:10:46 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
const conversation = conversationModel?.format();
|
|
|
|
|
|
|
|
if (conversation) {
|
|
|
|
dispatch({
|
|
|
|
type: 'CONVERSATION_CHANGED',
|
|
|
|
payload: {
|
|
|
|
id: conversationId,
|
|
|
|
data: {
|
|
|
|
...conversation,
|
|
|
|
voiceNotePlaybackRate: rate,
|
|
|
|
},
|
|
|
|
},
|
|
|
|
});
|
|
|
|
}
|
|
|
|
};
|
|
|
|
}
|
|
|
|
|
2021-06-03 21:34:36 +00:00
|
|
|
function colorSelected({
|
|
|
|
conversationId,
|
|
|
|
conversationColor,
|
|
|
|
customColorData,
|
|
|
|
}: ColorSelectedPayloadType): ThunkAction<
|
|
|
|
void,
|
|
|
|
RootStateType,
|
|
|
|
unknown,
|
|
|
|
ColorSelectedActionType
|
|
|
|
> {
|
|
|
|
return async dispatch => {
|
|
|
|
// We don't want to trigger a model change because we're updating redux
|
|
|
|
// here manually ourselves. Au revoir Backbone!
|
|
|
|
const conversation = window.ConversationController.get(conversationId);
|
|
|
|
if (conversation) {
|
|
|
|
if (conversationColor) {
|
|
|
|
conversation.attributes.conversationColor = conversationColor;
|
|
|
|
if (customColorData) {
|
|
|
|
conversation.attributes.customColor = customColorData.value;
|
|
|
|
conversation.attributes.customColorId = customColorData.id;
|
|
|
|
} else {
|
|
|
|
delete conversation.attributes.customColor;
|
|
|
|
delete conversation.attributes.customColorId;
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
delete conversation.attributes.conversationColor;
|
|
|
|
delete conversation.attributes.customColor;
|
|
|
|
delete conversation.attributes.customColorId;
|
|
|
|
}
|
|
|
|
|
2022-11-08 20:01:59 +00:00
|
|
|
window.Signal.Data.updateConversation(conversation.attributes);
|
2021-06-03 21:34:36 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
dispatch({
|
|
|
|
type: COLOR_SELECTED,
|
|
|
|
payload: {
|
|
|
|
conversationId,
|
|
|
|
conversationColor,
|
|
|
|
customColorData,
|
|
|
|
},
|
|
|
|
});
|
|
|
|
};
|
|
|
|
}
|
|
|
|
|
2021-08-06 00:17:05 +00:00
|
|
|
function toggleComposeEditingAvatar(): ToggleComposeEditingAvatarActionType {
|
|
|
|
return {
|
|
|
|
type: COMPOSE_TOGGLE_EDITING_AVATAR,
|
|
|
|
};
|
|
|
|
}
|
|
|
|
|
2022-02-16 18:36:21 +00:00
|
|
|
export function cancelConversationVerification(
|
|
|
|
canceledAt?: number
|
|
|
|
): ThunkAction<
|
2021-08-31 20:58:39 +00:00
|
|
|
void,
|
|
|
|
RootStateType,
|
|
|
|
unknown,
|
2022-02-16 18:36:21 +00:00
|
|
|
CancelVerificationDataByConversationActionType
|
2021-08-31 20:58:39 +00:00
|
|
|
> {
|
2022-02-16 18:36:21 +00:00
|
|
|
return (dispatch, getState) => {
|
|
|
|
const state = getState();
|
|
|
|
const conversationIdsBlocked =
|
|
|
|
getConversationIdsStoppedForVerification(state);
|
2022-01-25 01:39:18 +00:00
|
|
|
|
2022-02-16 18:36:21 +00:00
|
|
|
dispatch({
|
|
|
|
type: CANCEL_CONVERSATION_PENDING_VERIFICATION,
|
|
|
|
payload: {
|
|
|
|
canceledAt: canceledAt ?? Date.now(),
|
|
|
|
},
|
|
|
|
});
|
2022-01-25 01:39:18 +00:00
|
|
|
|
2022-02-16 18:36:21 +00:00
|
|
|
// Start the blocked conversation queues up again
|
|
|
|
conversationIdsBlocked.forEach(conversationId => {
|
|
|
|
conversationJobQueue.resolveVerificationWaiter(conversationId);
|
|
|
|
});
|
|
|
|
};
|
|
|
|
}
|
2021-08-31 20:58:39 +00:00
|
|
|
|
2022-02-16 18:36:21 +00:00
|
|
|
function verifyConversationsStoppingSend(): ThunkAction<
|
|
|
|
void,
|
|
|
|
RootStateType,
|
|
|
|
unknown,
|
|
|
|
ClearVerificationDataByConversationActionType
|
|
|
|
> {
|
|
|
|
return async (dispatch, getState) => {
|
|
|
|
const state = getState();
|
2022-05-31 19:46:56 +00:00
|
|
|
const uuidsStoppingSend = getConversationUuidsStoppingSend(state);
|
2022-02-16 18:36:21 +00:00
|
|
|
const conversationIdsBlocked =
|
|
|
|
getConversationIdsStoppedForVerification(state);
|
2022-04-14 22:27:16 +00:00
|
|
|
log.info(
|
|
|
|
`verifyConversationsStoppingSend: Starting with ${conversationIdsBlocked.length} blocked ` +
|
2022-05-31 19:46:56 +00:00
|
|
|
`conversations and ${uuidsStoppingSend.length} conversations to verify.`
|
2022-04-14 22:27:16 +00:00
|
|
|
);
|
2022-01-25 01:39:18 +00:00
|
|
|
|
2022-02-16 18:36:21 +00:00
|
|
|
// Mark conversations as approved/verified as appropriate
|
|
|
|
const promises: Array<Promise<unknown>> = [];
|
2022-05-31 19:46:56 +00:00
|
|
|
uuidsStoppingSend.forEach(async uuid => {
|
|
|
|
const conversation = window.ConversationController.get(uuid);
|
2022-02-16 18:36:21 +00:00
|
|
|
if (!conversation) {
|
2022-05-31 19:46:56 +00:00
|
|
|
log.warn(
|
|
|
|
`verifyConversationsStoppingSend: Cannot verify missing converastion for uuid ${uuid}`
|
|
|
|
);
|
2022-02-16 18:36:21 +00:00
|
|
|
return;
|
|
|
|
}
|
2022-04-14 22:27:16 +00:00
|
|
|
|
|
|
|
log.info(
|
|
|
|
`verifyConversationsStoppingSend: Verifying conversation ${conversation.idForLogging()}`
|
|
|
|
);
|
2022-02-16 18:36:21 +00:00
|
|
|
if (conversation.isUnverified()) {
|
|
|
|
promises.push(conversation.setVerifiedDefault());
|
|
|
|
}
|
|
|
|
promises.push(conversation.setApproved());
|
|
|
|
});
|
2022-01-25 01:39:18 +00:00
|
|
|
|
|
|
|
dispatch({
|
2022-02-16 18:36:21 +00:00
|
|
|
type: CLEAR_CONVERSATIONS_PENDING_VERIFICATION,
|
2022-01-25 01:39:18 +00:00
|
|
|
});
|
|
|
|
|
|
|
|
await Promise.all(promises);
|
2022-02-16 18:36:21 +00:00
|
|
|
|
|
|
|
// Start the blocked conversation queues up again
|
|
|
|
conversationIdsBlocked.forEach(conversationId => {
|
|
|
|
conversationJobQueue.resolveVerificationWaiter(conversationId);
|
|
|
|
});
|
|
|
|
};
|
|
|
|
}
|
|
|
|
|
|
|
|
export function clearCancelledConversationVerification(
|
|
|
|
conversationId: string
|
|
|
|
): ClearCancelledVerificationActionType {
|
|
|
|
return {
|
|
|
|
type: CLEAR_CANCELLED_VERIFICATION,
|
|
|
|
payload: {
|
|
|
|
conversationId,
|
|
|
|
},
|
2021-08-31 20:58:39 +00:00
|
|
|
};
|
|
|
|
}
|
|
|
|
|
2021-08-06 00:17:05 +00:00
|
|
|
function composeSaveAvatarToDisk(
|
|
|
|
avatarData: AvatarDataType
|
|
|
|
): ThunkAction<void, RootStateType, unknown, ComposeSaveAvatarActionType> {
|
|
|
|
return async dispatch => {
|
|
|
|
if (!avatarData.buffer) {
|
2021-09-24 00:49:05 +00:00
|
|
|
throw new Error('No avatar Uint8Array provided');
|
2021-08-06 00:17:05 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
const imagePath = await window.Signal.Migrations.writeNewAvatarData(
|
|
|
|
avatarData.buffer
|
|
|
|
);
|
|
|
|
|
|
|
|
dispatch({
|
|
|
|
type: COMPOSE_ADD_AVATAR,
|
|
|
|
payload: {
|
|
|
|
...avatarData,
|
|
|
|
imagePath,
|
|
|
|
},
|
|
|
|
});
|
|
|
|
};
|
|
|
|
}
|
|
|
|
|
|
|
|
function composeDeleteAvatarFromDisk(
|
|
|
|
avatarData: AvatarDataType
|
|
|
|
): ThunkAction<void, RootStateType, unknown, ComposeDeleteAvatarActionType> {
|
|
|
|
return async dispatch => {
|
|
|
|
if (avatarData.imagePath) {
|
|
|
|
await window.Signal.Migrations.deleteAvatar(avatarData.imagePath);
|
|
|
|
} else {
|
2021-09-17 18:27:53 +00:00
|
|
|
log.info(
|
2021-08-06 00:17:05 +00:00
|
|
|
'No imagePath for avatarData. Removing from userAvatarData, but not disk'
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
|
|
|
dispatch({
|
|
|
|
type: COMPOSE_REMOVE_AVATAR,
|
|
|
|
payload: avatarData,
|
|
|
|
});
|
|
|
|
};
|
|
|
|
}
|
|
|
|
|
|
|
|
function composeReplaceAvatar(
|
|
|
|
curr: AvatarDataType,
|
|
|
|
prev?: AvatarDataType
|
|
|
|
): ComposeReplaceAvatarsActionType {
|
|
|
|
return {
|
|
|
|
type: COMPOSE_REPLACE_AVATAR,
|
|
|
|
payload: {
|
|
|
|
curr,
|
|
|
|
prev,
|
|
|
|
},
|
|
|
|
};
|
|
|
|
}
|
|
|
|
|
2021-01-29 22:16:48 +00:00
|
|
|
function setPreJoinConversation(
|
|
|
|
data: PreJoinConversationType | undefined
|
|
|
|
): SetPreJoinConversationActionType {
|
|
|
|
return {
|
|
|
|
type: 'SET_PRE_JOIN_CONVERSATION',
|
|
|
|
payload: {
|
|
|
|
data,
|
|
|
|
},
|
|
|
|
};
|
|
|
|
}
|
2019-01-14 21:49:58 +00:00
|
|
|
function conversationAdded(
|
|
|
|
id: string,
|
|
|
|
data: ConversationType
|
|
|
|
): ConversationAddedActionType {
|
|
|
|
return {
|
|
|
|
type: 'CONVERSATION_ADDED',
|
|
|
|
payload: {
|
|
|
|
id,
|
|
|
|
data,
|
|
|
|
},
|
|
|
|
};
|
|
|
|
}
|
|
|
|
function conversationChanged(
|
|
|
|
id: string,
|
|
|
|
data: ConversationType
|
2020-12-09 23:21:34 +00:00
|
|
|
): ThunkAction<void, RootStateType, unknown, ConversationChangedActionType> {
|
2022-02-16 18:36:21 +00:00
|
|
|
return dispatch => {
|
2020-12-09 23:21:34 +00:00
|
|
|
calling.groupMembersChanged(id);
|
|
|
|
|
|
|
|
dispatch({
|
|
|
|
type: 'CONVERSATION_CHANGED',
|
|
|
|
payload: {
|
|
|
|
id,
|
|
|
|
data,
|
|
|
|
},
|
|
|
|
});
|
2019-01-14 21:49:58 +00:00
|
|
|
};
|
|
|
|
}
|
|
|
|
function conversationRemoved(id: string): ConversationRemovedActionType {
|
|
|
|
return {
|
|
|
|
type: 'CONVERSATION_REMOVED',
|
|
|
|
payload: {
|
|
|
|
id,
|
|
|
|
},
|
|
|
|
};
|
|
|
|
}
|
2021-03-03 20:09:58 +00:00
|
|
|
|
2022-02-11 21:38:52 +00:00
|
|
|
function createGroup(
|
|
|
|
createGroupV2 = groups.createGroupV2
|
|
|
|
): ThunkAction<
|
2021-03-03 20:09:58 +00:00
|
|
|
void,
|
|
|
|
RootStateType,
|
|
|
|
unknown,
|
|
|
|
| CreateGroupPendingActionType
|
|
|
|
| CreateGroupFulfilledActionType
|
|
|
|
| CreateGroupRejectedActionType
|
2023-03-20 22:23:53 +00:00
|
|
|
| TargetedConversationChangedActionType
|
2021-03-03 20:09:58 +00:00
|
|
|
> {
|
2022-06-16 19:12:50 +00:00
|
|
|
return async (dispatch, getState) => {
|
2021-03-03 20:09:58 +00:00
|
|
|
const { composer } = getState().conversations;
|
|
|
|
if (
|
|
|
|
composer?.step !== ComposerStep.SetGroupMetadata ||
|
|
|
|
composer.isCreating
|
|
|
|
) {
|
2022-09-15 19:17:15 +00:00
|
|
|
assertDev(false, 'Cannot create group in this stage; doing nothing');
|
2021-03-03 20:09:58 +00:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
dispatch({ type: 'CREATE_GROUP_PENDING' });
|
|
|
|
|
|
|
|
try {
|
2022-02-11 21:38:52 +00:00
|
|
|
const conversation = await createGroupV2({
|
2021-03-11 01:54:13 +00:00
|
|
|
name: composer.groupName.trim(),
|
2021-03-03 20:09:58 +00:00
|
|
|
avatar: composer.groupAvatar,
|
2021-08-06 00:17:05 +00:00
|
|
|
avatars: composer.userAvatarData.map(avatarData =>
|
|
|
|
omit(avatarData, ['buffer'])
|
|
|
|
),
|
2021-06-25 23:52:56 +00:00
|
|
|
expireTimer: composer.groupExpireTimer,
|
2021-03-03 20:09:58 +00:00
|
|
|
conversationIds: composer.selectedConversationIds,
|
|
|
|
});
|
|
|
|
dispatch({
|
|
|
|
type: 'CREATE_GROUP_FULFILLED',
|
|
|
|
payload: {
|
2021-10-26 22:59:08 +00:00
|
|
|
invitedUuids: (conversation.get('pendingMembersV2') || []).map(
|
|
|
|
member => member.uuid
|
|
|
|
),
|
2021-03-03 20:09:58 +00:00
|
|
|
},
|
|
|
|
});
|
2023-01-05 23:34:47 +00:00
|
|
|
showConversation({
|
|
|
|
conversationId: conversation.id,
|
|
|
|
switchToAssociatedView: true,
|
|
|
|
})(dispatch, getState, null);
|
2021-03-03 20:09:58 +00:00
|
|
|
} catch (err) {
|
2022-11-22 18:43:43 +00:00
|
|
|
log.error('Failed to create group', Errors.toLogFormat(err));
|
2021-03-03 20:09:58 +00:00
|
|
|
dispatch({ type: 'CREATE_GROUP_REJECTED' });
|
|
|
|
}
|
|
|
|
};
|
|
|
|
}
|
|
|
|
|
2019-01-14 21:49:58 +00:00
|
|
|
function removeAllConversations(): RemoveAllConversationsActionType {
|
|
|
|
return {
|
|
|
|
type: 'CONVERSATIONS_REMOVE_ALL',
|
|
|
|
payload: null,
|
|
|
|
};
|
|
|
|
}
|
2019-03-12 00:20:16 +00:00
|
|
|
|
2023-03-20 22:23:53 +00:00
|
|
|
function targetMessage(
|
2020-09-14 21:56:35 +00:00
|
|
|
messageId: string,
|
|
|
|
conversationId: string
|
2023-03-20 22:23:53 +00:00
|
|
|
): MessageTargetedActionType {
|
2019-11-07 21:36:16 +00:00
|
|
|
return {
|
2023-03-20 22:23:53 +00:00
|
|
|
type: 'MESSAGE_TARGETED',
|
2019-11-07 21:36:16 +00:00
|
|
|
payload: {
|
|
|
|
messageId,
|
|
|
|
conversationId,
|
|
|
|
},
|
|
|
|
};
|
|
|
|
}
|
|
|
|
|
2023-03-20 22:23:53 +00:00
|
|
|
function toggleSelectMessage(
|
|
|
|
conversationId: string,
|
|
|
|
messageId: string,
|
|
|
|
shift: boolean,
|
|
|
|
selected: boolean
|
|
|
|
): ThunkAction<void, RootStateType, unknown, ToggleSelectMessagesActionType> {
|
|
|
|
return async (dispatch, getState) => {
|
|
|
|
const state = getState();
|
|
|
|
const { conversations } = state;
|
|
|
|
|
|
|
|
let toggledMessageIds: ReadonlyArray<string>;
|
|
|
|
if (shift && conversations.lastSelectedMessage != null) {
|
|
|
|
if (conversationId !== conversations.selectedConversationId) {
|
|
|
|
throw new Error("toggleSelectMessage: conversationId doesn't match");
|
|
|
|
}
|
|
|
|
|
|
|
|
const conversation = window.ConversationController.get(conversationId);
|
|
|
|
|
|
|
|
if (conversation == null) {
|
|
|
|
throw new Error('toggleSelectMessage: conversation not found');
|
|
|
|
}
|
|
|
|
|
|
|
|
const toggledMessage = getOwn(conversations.messagesLookup, messageId);
|
|
|
|
|
|
|
|
strictAssert(
|
|
|
|
toggledMessage != null,
|
|
|
|
'toggleSelectMessage: toggled message not found'
|
|
|
|
);
|
|
|
|
|
|
|
|
// Sort the messages by their order in the conversation
|
|
|
|
const [after, before] = sortByMessageOrder(
|
|
|
|
[toggledMessage, conversations.lastSelectedMessage],
|
|
|
|
message => message
|
|
|
|
);
|
|
|
|
|
|
|
|
const betweenIds = await window.Signal.Data.getMessagesBetween(
|
|
|
|
conversationId,
|
|
|
|
{
|
|
|
|
after: {
|
|
|
|
sent_at: after.sent_at,
|
|
|
|
received_at: after.received_at,
|
|
|
|
},
|
|
|
|
before: {
|
|
|
|
sent_at: before.sent_at,
|
|
|
|
received_at: before.received_at,
|
|
|
|
},
|
|
|
|
includeStoryReplies: !isGroup(conversation.attributes),
|
|
|
|
}
|
|
|
|
);
|
|
|
|
|
|
|
|
toggledMessageIds = [messageId, ...betweenIds];
|
|
|
|
} else {
|
|
|
|
toggledMessageIds = [messageId];
|
|
|
|
}
|
|
|
|
|
|
|
|
dispatch({
|
|
|
|
type: 'TOGGLE_SELECT_MESSAGES',
|
|
|
|
payload: {
|
|
|
|
toggledMessageId: messageId,
|
|
|
|
messageIds: toggledMessageIds,
|
|
|
|
selected,
|
|
|
|
},
|
|
|
|
});
|
|
|
|
};
|
|
|
|
}
|
|
|
|
|
|
|
|
function toggleSelectMode(on: boolean): ToggleSelectModeActionType {
|
|
|
|
return {
|
|
|
|
type: 'TOGGLE_SELECT_MODE',
|
|
|
|
payload: { on },
|
|
|
|
};
|
|
|
|
}
|
|
|
|
|
2022-12-16 03:12:05 +00:00
|
|
|
function getProfilesForConversation(conversationId: string): NoopActionType {
|
|
|
|
const conversation = window.ConversationController.get(conversationId);
|
|
|
|
if (!conversation) {
|
|
|
|
throw new Error('getProfilesForConversation: no conversation found');
|
|
|
|
}
|
|
|
|
|
2022-12-21 18:41:48 +00:00
|
|
|
void conversation.getProfiles();
|
2022-12-16 03:12:05 +00:00
|
|
|
|
|
|
|
return {
|
|
|
|
type: 'NOOP',
|
|
|
|
payload: null,
|
|
|
|
};
|
|
|
|
}
|
|
|
|
|
2022-02-16 18:36:21 +00:00
|
|
|
function conversationStoppedByMissingVerification(payload: {
|
|
|
|
conversationId: string;
|
2022-11-11 04:10:30 +00:00
|
|
|
distributionId?: string;
|
|
|
|
untrustedUuids: ReadonlyArray<UUIDStringType>;
|
2022-02-16 18:36:21 +00:00
|
|
|
}): ConversationStoppedByMissingVerificationActionType {
|
2022-04-14 22:27:16 +00:00
|
|
|
// Fetching profiles to ensure that we have their latest identity key in storage
|
2022-05-31 19:46:56 +00:00
|
|
|
payload.untrustedUuids.forEach(uuid => {
|
|
|
|
const conversation = window.ConversationController.get(uuid);
|
2022-04-14 22:27:16 +00:00
|
|
|
if (!conversation) {
|
|
|
|
log.error(
|
2022-05-31 19:46:56 +00:00
|
|
|
`conversationStoppedByMissingVerification: uuid ${uuid} not found!`
|
2022-04-14 22:27:16 +00:00
|
|
|
);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2022-07-14 00:46:46 +00:00
|
|
|
// Intentionally not awaiting here
|
2022-12-21 18:41:48 +00:00
|
|
|
void conversation.getProfiles();
|
2022-04-14 22:27:16 +00:00
|
|
|
});
|
|
|
|
|
2021-08-31 20:58:39 +00:00
|
|
|
return {
|
2022-02-16 18:36:21 +00:00
|
|
|
type: CONVERSATION_STOPPED_BY_MISSING_VERIFICATION,
|
|
|
|
payload,
|
2021-08-31 20:58:39 +00:00
|
|
|
};
|
|
|
|
}
|
|
|
|
|
2019-05-31 22:42:01 +00:00
|
|
|
function messageChanged(
|
|
|
|
id: string,
|
|
|
|
conversationId: string,
|
2021-06-17 17:15:10 +00:00
|
|
|
data: MessageAttributesType
|
2019-05-31 22:42:01 +00:00
|
|
|
): MessageChangedActionType {
|
|
|
|
return {
|
2023-01-05 22:16:56 +00:00
|
|
|
type: MESSAGE_CHANGED,
|
2019-05-31 22:42:01 +00:00
|
|
|
payload: {
|
|
|
|
id,
|
|
|
|
conversationId,
|
|
|
|
data,
|
|
|
|
},
|
|
|
|
};
|
|
|
|
}
|
2023-02-24 23:18:57 +00:00
|
|
|
|
2019-05-31 22:42:01 +00:00
|
|
|
function messageDeleted(
|
2019-01-14 21:49:58 +00:00
|
|
|
id: string,
|
|
|
|
conversationId: string
|
2019-05-31 22:42:01 +00:00
|
|
|
): MessageDeletedActionType {
|
2019-01-14 21:49:58 +00:00
|
|
|
return {
|
2022-12-20 17:50:23 +00:00
|
|
|
type: MESSAGE_DELETED,
|
2019-01-14 21:49:58 +00:00
|
|
|
payload: {
|
|
|
|
id,
|
|
|
|
conversationId,
|
|
|
|
},
|
|
|
|
};
|
|
|
|
}
|
2023-02-24 23:18:57 +00:00
|
|
|
|
2021-11-11 23:45:47 +00:00
|
|
|
function messageExpanded(
|
|
|
|
id: string,
|
|
|
|
displayLimit: number
|
|
|
|
): MessageExpandedActionType {
|
|
|
|
return {
|
|
|
|
type: 'MESSAGE_EXPANDED',
|
|
|
|
payload: {
|
|
|
|
id,
|
|
|
|
displayLimit,
|
|
|
|
},
|
|
|
|
};
|
|
|
|
}
|
2023-05-10 00:40:19 +00:00
|
|
|
function showSpoiler(
|
|
|
|
id: string,
|
|
|
|
data: Record<number, boolean>
|
|
|
|
): ShowSpoilerActionType {
|
2023-04-10 16:31:45 +00:00
|
|
|
return {
|
|
|
|
type: SHOW_SPOILER,
|
|
|
|
payload: {
|
|
|
|
id,
|
2023-05-10 00:40:19 +00:00
|
|
|
data,
|
2023-04-10 16:31:45 +00:00
|
|
|
},
|
|
|
|
};
|
|
|
|
}
|
|
|
|
|
2022-12-20 17:50:23 +00:00
|
|
|
function messageExpired(id: string): MessageExpiredActionType {
|
|
|
|
return {
|
|
|
|
type: MESSAGE_EXPIRED,
|
|
|
|
payload: {
|
|
|
|
id,
|
|
|
|
},
|
|
|
|
};
|
|
|
|
}
|
2023-02-24 23:18:57 +00:00
|
|
|
|
2021-11-30 11:25:24 +00:00
|
|
|
function messagesAdded({
|
|
|
|
conversationId,
|
|
|
|
isActive,
|
|
|
|
isJustSent,
|
|
|
|
isNewMessage,
|
|
|
|
messages,
|
|
|
|
}: {
|
|
|
|
conversationId: string;
|
|
|
|
isActive: boolean;
|
|
|
|
isJustSent: boolean;
|
|
|
|
isNewMessage: boolean;
|
2022-12-22 00:07:02 +00:00
|
|
|
messages: ReadonlyArray<MessageAttributesType>;
|
2023-05-09 15:51:11 +00:00
|
|
|
}): ThunkAction<void, RootStateType, unknown, MessagesAddedActionType> {
|
|
|
|
return (dispatch, getState) => {
|
|
|
|
const state = getState();
|
|
|
|
if (
|
|
|
|
isNewMessage &&
|
|
|
|
state.items.audioMessage &&
|
|
|
|
conversationId === state.conversations.selectedConversationId &&
|
|
|
|
isActive &&
|
|
|
|
!isJustSent &&
|
|
|
|
messages.some(isIncoming)
|
|
|
|
) {
|
|
|
|
drop(new Sound({ soundType: SoundType.Pop }).play());
|
|
|
|
}
|
|
|
|
|
|
|
|
dispatch({
|
|
|
|
type: 'MESSAGES_ADDED',
|
|
|
|
payload: {
|
|
|
|
conversationId,
|
|
|
|
isActive,
|
|
|
|
isJustSent,
|
|
|
|
isNewMessage,
|
|
|
|
messages,
|
|
|
|
},
|
|
|
|
});
|
2019-05-31 22:42:01 +00:00
|
|
|
};
|
|
|
|
}
|
2020-12-04 20:41:40 +00:00
|
|
|
|
|
|
|
function repairNewestMessage(
|
|
|
|
conversationId: string
|
|
|
|
): RepairNewestMessageActionType {
|
|
|
|
return {
|
|
|
|
type: 'REPAIR_NEWEST_MESSAGE',
|
|
|
|
payload: {
|
|
|
|
conversationId,
|
|
|
|
},
|
|
|
|
};
|
|
|
|
}
|
|
|
|
function repairOldestMessage(
|
|
|
|
conversationId: string
|
|
|
|
): RepairOldestMessageActionType {
|
|
|
|
return {
|
|
|
|
type: 'REPAIR_OLDEST_MESSAGE',
|
|
|
|
payload: {
|
|
|
|
conversationId,
|
|
|
|
},
|
|
|
|
};
|
|
|
|
}
|
|
|
|
|
2021-06-01 23:30:25 +00:00
|
|
|
function reviewGroupMemberNameCollision(
|
|
|
|
groupConversationId: string
|
|
|
|
): ReviewGroupMemberNameCollisionActionType {
|
|
|
|
return {
|
|
|
|
type: 'REVIEW_GROUP_MEMBER_NAME_COLLISION',
|
|
|
|
payload: { groupConversationId },
|
|
|
|
};
|
|
|
|
}
|
|
|
|
|
2021-04-21 16:31:12 +00:00
|
|
|
function reviewMessageRequestNameCollision(
|
|
|
|
payload: Readonly<{
|
|
|
|
safeConversationId: string;
|
|
|
|
}>
|
|
|
|
): ReviewMessageRequestNameCollisionActionType {
|
|
|
|
return { type: 'REVIEW_MESSAGE_REQUEST_NAME_COLLISION', payload };
|
|
|
|
}
|
|
|
|
|
2023-01-13 20:07:26 +00:00
|
|
|
// eslint-disable-next-line local-rules/type-alias-readonlydeep
|
|
|
|
export type MessageResetOptionsType = {
|
2022-01-20 00:40:29 +00:00
|
|
|
conversationId: string;
|
2022-12-22 00:07:02 +00:00
|
|
|
messages: ReadonlyArray<MessageAttributesType>;
|
2022-01-20 00:40:29 +00:00
|
|
|
metrics: MessageMetricsType;
|
|
|
|
scrollToMessageId?: string;
|
|
|
|
unboundedFetch?: boolean;
|
2023-01-13 20:07:26 +00:00
|
|
|
};
|
2022-01-20 00:40:29 +00:00
|
|
|
|
|
|
|
function messagesReset({
|
|
|
|
conversationId,
|
|
|
|
messages,
|
|
|
|
metrics,
|
|
|
|
scrollToMessageId,
|
|
|
|
unboundedFetch,
|
|
|
|
}: MessageResetOptionsType): MessagesResetActionType {
|
2022-06-23 16:12:17 +00:00
|
|
|
for (const message of messages) {
|
|
|
|
strictAssert(
|
|
|
|
message.conversationId === conversationId,
|
|
|
|
`messagesReset(${conversationId}): invalid message conversationId ` +
|
|
|
|
`${message.conversationId}`
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
2019-05-31 22:42:01 +00:00
|
|
|
return {
|
|
|
|
type: 'MESSAGES_RESET',
|
|
|
|
payload: {
|
2020-07-06 17:06:44 +00:00
|
|
|
unboundedFetch: Boolean(unboundedFetch),
|
2019-05-31 22:42:01 +00:00
|
|
|
conversationId,
|
|
|
|
messages,
|
|
|
|
metrics,
|
|
|
|
scrollToMessageId,
|
|
|
|
},
|
|
|
|
};
|
|
|
|
}
|
2022-03-11 22:31:21 +00:00
|
|
|
function setMessageLoadingState(
|
2019-05-31 22:42:01 +00:00
|
|
|
conversationId: string,
|
2022-03-11 22:31:21 +00:00
|
|
|
messageLoadingState: undefined | TimelineMessageLoadingState
|
|
|
|
): SetMessageLoadingStateActionType {
|
2019-05-31 22:42:01 +00:00
|
|
|
return {
|
2022-03-11 22:31:21 +00:00
|
|
|
type: 'SET_MESSAGE_LOADING_STATE',
|
2019-05-31 22:42:01 +00:00
|
|
|
payload: {
|
|
|
|
conversationId,
|
2022-03-11 22:31:21 +00:00
|
|
|
messageLoadingState,
|
2019-05-31 22:42:01 +00:00
|
|
|
},
|
|
|
|
};
|
|
|
|
}
|
|
|
|
function setIsNearBottom(
|
|
|
|
conversationId: string,
|
|
|
|
isNearBottom: boolean
|
|
|
|
): SetIsNearBottomActionType {
|
|
|
|
return {
|
|
|
|
type: 'SET_NEAR_BOTTOM',
|
|
|
|
payload: {
|
|
|
|
conversationId,
|
|
|
|
isNearBottom,
|
|
|
|
},
|
|
|
|
};
|
|
|
|
}
|
2022-04-05 00:38:22 +00:00
|
|
|
function setIsFetchingUUID(
|
|
|
|
identifier: UUIDFetchStateKeyType,
|
|
|
|
isFetching: boolean
|
|
|
|
): SetIsFetchingUUIDActionType {
|
|
|
|
return {
|
|
|
|
type: 'SET_IS_FETCHING_UUID',
|
|
|
|
payload: {
|
|
|
|
identifier,
|
|
|
|
isFetching,
|
|
|
|
},
|
|
|
|
};
|
|
|
|
}
|
2022-12-14 18:41:04 +00:00
|
|
|
|
2023-01-13 20:07:26 +00:00
|
|
|
export type PushPanelForConversationActionType = ReadonlyDeep<
|
|
|
|
(panel: PanelRequestType) => unknown
|
|
|
|
>;
|
2022-12-14 18:41:04 +00:00
|
|
|
|
|
|
|
function pushPanelForConversation(
|
2022-12-21 20:44:23 +00:00
|
|
|
panel: PanelRequestType
|
|
|
|
): ThunkAction<void, RootStateType, unknown, PushPanelActionType> {
|
2023-04-10 16:31:45 +00:00
|
|
|
return async (dispatch, getState) => {
|
2022-12-21 20:44:23 +00:00
|
|
|
if (panel.type === PanelType.MessageDetails) {
|
|
|
|
const { messageId } = panel.args;
|
2023-04-10 16:31:45 +00:00
|
|
|
const state = getState();
|
2022-12-14 18:41:04 +00:00
|
|
|
|
2023-04-10 16:31:45 +00:00
|
|
|
const message =
|
|
|
|
state.conversations.messagesLookup[messageId] ||
|
|
|
|
(await getMessageById(messageId))?.attributes;
|
2022-12-21 20:44:23 +00:00
|
|
|
if (!message) {
|
|
|
|
throw new Error(
|
|
|
|
'pushPanelForConversation: could not find message for MessageDetails'
|
|
|
|
);
|
|
|
|
}
|
|
|
|
dispatch({
|
|
|
|
type: PUSH_PANEL,
|
|
|
|
payload: {
|
|
|
|
type: PanelType.MessageDetails,
|
|
|
|
args: {
|
2023-04-10 16:31:45 +00:00
|
|
|
message,
|
2022-12-21 20:44:23 +00:00
|
|
|
},
|
|
|
|
},
|
|
|
|
});
|
|
|
|
return;
|
|
|
|
}
|
2022-12-14 18:41:04 +00:00
|
|
|
|
2022-12-21 20:44:23 +00:00
|
|
|
dispatch({
|
|
|
|
type: PUSH_PANEL,
|
|
|
|
payload: panel,
|
|
|
|
});
|
2021-01-29 21:19:24 +00:00
|
|
|
};
|
|
|
|
}
|
2022-12-14 18:41:04 +00:00
|
|
|
|
2023-01-13 20:07:26 +00:00
|
|
|
export type PopPanelForConversationActionType = ReadonlyDeep<() => unknown>;
|
2022-12-21 03:25:10 +00:00
|
|
|
|
2022-12-21 20:44:23 +00:00
|
|
|
function popPanelForConversation(): ThunkAction<
|
|
|
|
void,
|
|
|
|
RootStateType,
|
|
|
|
unknown,
|
|
|
|
PopPanelActionType
|
|
|
|
> {
|
2022-12-14 18:41:04 +00:00
|
|
|
return (dispatch, getState) => {
|
|
|
|
const { conversations } = getState();
|
2023-07-26 22:23:32 +00:00
|
|
|
const { targetedConversationPanels } = conversations;
|
2022-12-14 18:41:04 +00:00
|
|
|
|
2023-07-26 22:23:32 +00:00
|
|
|
if (!targetedConversationPanels.stack.length) {
|
2022-12-14 18:41:04 +00:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
dispatch({
|
|
|
|
type: POP_PANEL,
|
|
|
|
payload: null,
|
|
|
|
});
|
2020-10-30 17:52:21 +00:00
|
|
|
};
|
|
|
|
}
|
2022-12-05 22:56:23 +00:00
|
|
|
|
2023-07-26 22:23:32 +00:00
|
|
|
function panelAnimationStarted(): PanelAnimationStartedActionType {
|
|
|
|
return {
|
|
|
|
type: PANEL_ANIMATION_STARTED,
|
|
|
|
payload: null,
|
|
|
|
};
|
|
|
|
}
|
|
|
|
|
|
|
|
function panelAnimationDone(): PanelAnimationDoneActionType {
|
|
|
|
return {
|
|
|
|
type: PANEL_ANIMATION_DONE,
|
|
|
|
payload: null,
|
|
|
|
};
|
|
|
|
}
|
|
|
|
|
2023-04-10 21:38:34 +00:00
|
|
|
function deleteMessagesForEveryone(
|
|
|
|
messageIds: ReadonlyArray<string>
|
2022-12-05 22:56:23 +00:00
|
|
|
): ThunkAction<
|
|
|
|
void,
|
|
|
|
RootStateType,
|
|
|
|
unknown,
|
|
|
|
NoopActionType | ShowToastActionType
|
|
|
|
> {
|
|
|
|
return async dispatch => {
|
2023-04-10 21:38:34 +00:00
|
|
|
let hasError = false;
|
2022-12-05 22:56:23 +00:00
|
|
|
|
2023-04-10 21:38:34 +00:00
|
|
|
await Promise.all(
|
|
|
|
messageIds.map(async messageId => {
|
|
|
|
try {
|
|
|
|
const message = window.MessageController.getById(messageId);
|
|
|
|
if (!message) {
|
|
|
|
throw new Error(
|
|
|
|
`deleteMessageForEveryone: Message ${messageId} missing!`
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
|
|
|
const conversation = message.getConversation();
|
|
|
|
if (!conversation) {
|
|
|
|
throw new Error('deleteMessageForEveryone: no conversation');
|
|
|
|
}
|
|
|
|
|
|
|
|
await sendDeleteForEveryoneMessage(conversation.attributes, {
|
|
|
|
id: message.id,
|
2023-05-16 17:37:12 +00:00
|
|
|
timestamp: getMessageSentTimestamp(message.attributes, { log }),
|
2023-04-10 21:38:34 +00:00
|
|
|
});
|
|
|
|
} catch (error) {
|
|
|
|
hasError = true;
|
|
|
|
log.error(
|
|
|
|
'Error queuing delete-for-everyone job',
|
|
|
|
Errors.toLogFormat(error),
|
|
|
|
messageId
|
|
|
|
);
|
|
|
|
}
|
|
|
|
})
|
|
|
|
);
|
2022-12-05 22:56:23 +00:00
|
|
|
|
2023-04-10 21:38:34 +00:00
|
|
|
if (hasError) {
|
2022-12-05 22:56:23 +00:00
|
|
|
dispatch({
|
|
|
|
type: SHOW_TOAST,
|
|
|
|
payload: {
|
|
|
|
toastType: ToastType.DeleteForEveryoneFailed,
|
|
|
|
},
|
|
|
|
});
|
2023-04-10 21:38:34 +00:00
|
|
|
} else {
|
|
|
|
dispatch({
|
|
|
|
type: 'NOOP',
|
|
|
|
payload: null,
|
|
|
|
});
|
2022-12-05 22:56:23 +00:00
|
|
|
}
|
|
|
|
};
|
|
|
|
}
|
|
|
|
|
|
|
|
function approvePendingMembershipFromGroupV2(
|
|
|
|
conversationId: string,
|
|
|
|
memberId: string
|
|
|
|
): ThunkAction<void, RootStateType, unknown, NoopActionType> {
|
|
|
|
return async dispatch => {
|
|
|
|
const conversation = window.ConversationController.get(conversationId);
|
|
|
|
if (!conversation) {
|
|
|
|
throw new Error(
|
|
|
|
`approvePendingMembershipFromGroupV2: No conversation found for conversation ${conversationId}`
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
|
|
|
const logId = conversation.idForLogging();
|
|
|
|
|
|
|
|
const pendingMember = window.ConversationController.get(memberId);
|
|
|
|
if (!pendingMember) {
|
|
|
|
throw new Error(
|
|
|
|
`approvePendingMembershipFromGroupV2/${logId}: No member found for conversation ${conversationId}`
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
|
|
|
const uuid = pendingMember.getCheckedUuid(
|
|
|
|
`approvePendingMembershipFromGroupV2/${logId}`
|
|
|
|
);
|
|
|
|
|
|
|
|
if (
|
|
|
|
isGroupV2(conversation.attributes) &&
|
|
|
|
isMemberRequestingToJoin(conversation.attributes, uuid)
|
|
|
|
) {
|
2022-12-08 06:41:37 +00:00
|
|
|
await modifyGroupV2({
|
2022-12-05 22:56:23 +00:00
|
|
|
conversation,
|
|
|
|
usingCredentialsFrom: [pendingMember],
|
|
|
|
createGroupChange: async () => {
|
|
|
|
// This user's pending state may have changed in the time between the user's
|
|
|
|
// button press and when we get here. It's especially important to check here
|
|
|
|
// in conflict/retry cases.
|
|
|
|
if (!isMemberRequestingToJoin(conversation.attributes, uuid)) {
|
|
|
|
log.warn(
|
|
|
|
`approvePendingMembershipFromGroupV2/${logId}: ${uuid} is not requesting ` +
|
|
|
|
'to join the group. Returning early.'
|
|
|
|
);
|
|
|
|
return undefined;
|
|
|
|
}
|
|
|
|
|
2022-12-08 06:41:37 +00:00
|
|
|
return buildPromotePendingAdminApprovalMemberChange({
|
|
|
|
group: conversation.attributes,
|
|
|
|
uuid,
|
|
|
|
});
|
2022-12-05 22:56:23 +00:00
|
|
|
},
|
|
|
|
name: 'approvePendingMembershipFromGroupV2',
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
dispatch({
|
|
|
|
type: 'NOOP',
|
|
|
|
payload: null,
|
|
|
|
});
|
2021-01-29 21:19:24 +00:00
|
|
|
};
|
|
|
|
}
|
2022-12-05 22:56:23 +00:00
|
|
|
|
|
|
|
function revokePendingMembershipsFromGroupV2(
|
|
|
|
conversationId: string,
|
2022-12-22 00:07:02 +00:00
|
|
|
memberIds: ReadonlyArray<string>
|
2022-12-05 22:56:23 +00:00
|
|
|
): ThunkAction<void, RootStateType, unknown, NoopActionType> {
|
|
|
|
return async dispatch => {
|
|
|
|
const conversation = window.ConversationController.get(conversationId);
|
|
|
|
if (!conversation) {
|
|
|
|
throw new Error(
|
|
|
|
`approvePendingMembershipFromGroupV2: No conversation found for conversation ${conversationId}`
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!isGroupV2(conversation.attributes)) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Only pending memberships can be revoked for multiple members at once
|
|
|
|
if (memberIds.length > 1) {
|
|
|
|
const uuids = memberIds.map(id => {
|
|
|
|
const uuid = window.ConversationController.get(id)?.getUuid();
|
|
|
|
strictAssert(uuid, `UUID does not exist for ${id}`);
|
|
|
|
return uuid;
|
|
|
|
});
|
|
|
|
await conversation.modifyGroupV2({
|
|
|
|
name: 'removePendingMember',
|
|
|
|
usingCredentialsFrom: [],
|
|
|
|
createGroupChange: () =>
|
|
|
|
removePendingMember(conversation.attributes, uuids),
|
|
|
|
extraConversationsForSend: memberIds,
|
|
|
|
});
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
const [memberId] = memberIds;
|
|
|
|
|
|
|
|
const pendingMember = window.ConversationController.get(memberId);
|
|
|
|
if (!pendingMember) {
|
|
|
|
const logId = conversation.idForLogging();
|
|
|
|
throw new Error(
|
|
|
|
`revokePendingMembershipsFromGroupV2/${logId}: No conversation found for conversation ${memberId}`
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
|
|
|
const uuid = pendingMember.getCheckedUuid(
|
|
|
|
'revokePendingMembershipsFromGroupV2'
|
|
|
|
);
|
|
|
|
|
|
|
|
if (isMemberRequestingToJoin(conversation.attributes, uuid)) {
|
|
|
|
await conversation.modifyGroupV2({
|
|
|
|
name: 'denyPendingApprovalRequest',
|
|
|
|
usingCredentialsFrom: [],
|
|
|
|
createGroupChange: () =>
|
|
|
|
denyPendingApprovalRequest(conversation.attributes, uuid),
|
|
|
|
extraConversationsForSend: [memberId],
|
|
|
|
});
|
|
|
|
} else if (conversation.isMemberPending(uuid)) {
|
|
|
|
await conversation.modifyGroupV2({
|
|
|
|
name: 'removePendingMember',
|
|
|
|
usingCredentialsFrom: [],
|
|
|
|
createGroupChange: () =>
|
|
|
|
removePendingMember(conversation.attributes, [uuid]),
|
|
|
|
extraConversationsForSend: [memberId],
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
dispatch({
|
|
|
|
type: 'NOOP',
|
|
|
|
payload: null,
|
|
|
|
});
|
|
|
|
};
|
|
|
|
}
|
|
|
|
|
2022-12-06 19:03:09 +00:00
|
|
|
function blockAndReportSpam(
|
|
|
|
conversationId: string
|
|
|
|
): ThunkAction<void, RootStateType, unknown, ShowToastActionType> {
|
|
|
|
return async dispatch => {
|
|
|
|
const conversation = window.ConversationController.get(conversationId);
|
|
|
|
if (!conversation) {
|
|
|
|
log.error(
|
|
|
|
`blockAndReportSpam: Expected a conversation to be found for ${conversationId}. Doing nothing.`
|
|
|
|
);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
const messageRequestEnum = Proto.SyncMessage.MessageRequestResponse.Type;
|
|
|
|
const idForLogging = conversation.idForLogging();
|
|
|
|
|
2022-12-21 18:41:48 +00:00
|
|
|
void longRunningTaskWrapper({
|
2022-12-06 19:03:09 +00:00
|
|
|
name: 'blockAndReportSpam',
|
|
|
|
idForLogging,
|
|
|
|
task: async () => {
|
|
|
|
await Promise.all([
|
|
|
|
conversation.syncMessageRequestResponse(messageRequestEnum.BLOCK),
|
|
|
|
addReportSpamJob({
|
2023-02-08 00:55:12 +00:00
|
|
|
conversation: conversation.attributes,
|
2022-12-06 19:03:09 +00:00
|
|
|
getMessageServerGuidsForSpam:
|
|
|
|
window.Signal.Data.getMessageServerGuidsForSpam,
|
|
|
|
jobQueue: reportSpamJobQueue,
|
|
|
|
}),
|
|
|
|
]);
|
|
|
|
|
|
|
|
dispatch({
|
|
|
|
type: SHOW_TOAST,
|
|
|
|
payload: {
|
|
|
|
toastType: ToastType.ReportedSpamAndBlocked,
|
|
|
|
},
|
|
|
|
});
|
|
|
|
},
|
|
|
|
});
|
|
|
|
};
|
|
|
|
}
|
|
|
|
|
|
|
|
function acceptConversation(conversationId: string): NoopActionType {
|
|
|
|
const conversation = window.ConversationController.get(conversationId);
|
|
|
|
if (!conversation) {
|
|
|
|
throw new Error(
|
|
|
|
'acceptConversation: Expected a conversation to be found. Doing nothing'
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
|
|
|
const messageRequestEnum = Proto.SyncMessage.MessageRequestResponse.Type;
|
|
|
|
|
2022-12-21 18:41:48 +00:00
|
|
|
void longRunningTaskWrapper({
|
2022-12-06 19:03:09 +00:00
|
|
|
name: 'acceptConversation',
|
|
|
|
idForLogging: conversation.idForLogging(),
|
|
|
|
task: conversation.syncMessageRequestResponse.bind(
|
|
|
|
conversation,
|
|
|
|
messageRequestEnum.ACCEPT
|
|
|
|
),
|
|
|
|
});
|
|
|
|
|
|
|
|
return {
|
|
|
|
type: 'NOOP',
|
|
|
|
payload: null,
|
|
|
|
};
|
|
|
|
}
|
|
|
|
|
2023-04-05 20:48:00 +00:00
|
|
|
function removeConversation(conversationId: string): ShowToastActionType {
|
|
|
|
const conversation = window.ConversationController.get(conversationId);
|
|
|
|
if (!conversation) {
|
|
|
|
throw new Error(
|
|
|
|
'acceptConversation: Expected a conversation to be found. Doing nothing'
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
|
|
|
drop(conversation.removeContact());
|
|
|
|
|
|
|
|
return {
|
|
|
|
type: SHOW_TOAST,
|
|
|
|
payload: {
|
|
|
|
toastType: ToastType.ConversationRemoved,
|
|
|
|
parameters: {
|
|
|
|
title: conversation.getTitle(),
|
|
|
|
},
|
|
|
|
},
|
|
|
|
};
|
|
|
|
}
|
|
|
|
|
2022-12-06 19:03:09 +00:00
|
|
|
function blockConversation(conversationId: string): NoopActionType {
|
|
|
|
const conversation = window.ConversationController.get(conversationId);
|
|
|
|
if (!conversation) {
|
|
|
|
throw new Error(
|
|
|
|
'blockConversation: Expected a conversation to be found. Doing nothing'
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
|
|
|
const messageRequestEnum = Proto.SyncMessage.MessageRequestResponse.Type;
|
|
|
|
|
2022-12-21 18:41:48 +00:00
|
|
|
void longRunningTaskWrapper({
|
2022-12-06 19:03:09 +00:00
|
|
|
name: 'blockConversation',
|
|
|
|
idForLogging: conversation.idForLogging(),
|
|
|
|
task: conversation.syncMessageRequestResponse.bind(
|
|
|
|
conversation,
|
|
|
|
messageRequestEnum.BLOCK
|
|
|
|
),
|
|
|
|
});
|
|
|
|
|
|
|
|
return {
|
|
|
|
type: 'NOOP',
|
|
|
|
payload: null,
|
|
|
|
};
|
|
|
|
}
|
|
|
|
|
|
|
|
function deleteConversation(conversationId: string): NoopActionType {
|
|
|
|
const conversation = window.ConversationController.get(conversationId);
|
|
|
|
if (!conversation) {
|
|
|
|
throw new Error(
|
|
|
|
'deleteConversation: Expected a conversation to be found. Doing nothing'
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
|
|
|
const messageRequestEnum = Proto.SyncMessage.MessageRequestResponse.Type;
|
|
|
|
|
2022-12-21 18:41:48 +00:00
|
|
|
void longRunningTaskWrapper({
|
2022-12-06 19:03:09 +00:00
|
|
|
name: 'deleteConversation',
|
|
|
|
idForLogging: conversation.idForLogging(),
|
|
|
|
task: conversation.syncMessageRequestResponse.bind(
|
|
|
|
conversation,
|
|
|
|
messageRequestEnum.DELETE
|
|
|
|
),
|
|
|
|
});
|
|
|
|
|
|
|
|
return {
|
|
|
|
type: 'NOOP',
|
|
|
|
payload: null,
|
|
|
|
};
|
|
|
|
}
|
|
|
|
|
2022-12-08 06:41:37 +00:00
|
|
|
function initiateMigrationToGroupV2(conversationId: string): NoopActionType {
|
|
|
|
const conversation = window.ConversationController.get(conversationId);
|
|
|
|
if (!conversation) {
|
|
|
|
throw new Error(
|
|
|
|
'deleteConversation: Expected a conversation to be found. Doing nothing'
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
2022-12-21 18:41:48 +00:00
|
|
|
void longRunningTaskWrapper({
|
2022-12-08 06:41:37 +00:00
|
|
|
idForLogging: conversation.idForLogging(),
|
|
|
|
name: 'initiateMigrationToGroupV2',
|
|
|
|
task: () => doInitiateMigrationToGroupV2(conversation),
|
|
|
|
});
|
|
|
|
|
|
|
|
return {
|
|
|
|
type: 'NOOP',
|
|
|
|
payload: null,
|
|
|
|
};
|
|
|
|
}
|
|
|
|
|
2022-12-05 22:56:23 +00:00
|
|
|
function loadRecentMediaItems(
|
|
|
|
conversationId: string,
|
|
|
|
limit: number
|
|
|
|
): ThunkAction<void, RootStateType, unknown, SetRecentMediaItemsActionType> {
|
|
|
|
return async dispatch => {
|
|
|
|
const { getAbsoluteAttachmentPath } = window.Signal.Migrations;
|
|
|
|
|
|
|
|
const messages: Array<MessageAttributesType> =
|
|
|
|
await window.Signal.Data.getMessagesWithVisualMediaAttachments(
|
|
|
|
conversationId,
|
|
|
|
{
|
|
|
|
limit,
|
|
|
|
}
|
|
|
|
);
|
|
|
|
|
|
|
|
// Cache these messages in memory to ensure Lightbox can find them
|
|
|
|
messages.forEach(message => {
|
|
|
|
window.MessageController.register(message.id, message);
|
|
|
|
});
|
|
|
|
|
|
|
|
const recentMediaItems = messages
|
|
|
|
.filter(message => message.attachments !== undefined)
|
|
|
|
.reduce(
|
|
|
|
(acc, message) => [
|
|
|
|
...acc,
|
|
|
|
...(message.attachments || []).map(
|
|
|
|
(attachment: AttachmentType, index: number): MediaItemType => {
|
|
|
|
const { thumbnail } = attachment;
|
|
|
|
|
|
|
|
return {
|
|
|
|
objectURL: getAbsoluteAttachmentPath(attachment.path || ''),
|
|
|
|
thumbnailObjectUrl: thumbnail?.path
|
|
|
|
? getAbsoluteAttachmentPath(thumbnail.path)
|
|
|
|
: '',
|
|
|
|
contentType: attachment.contentType,
|
|
|
|
index,
|
|
|
|
attachment,
|
|
|
|
message: {
|
|
|
|
attachments: message.attachments || [],
|
|
|
|
conversationId:
|
|
|
|
window.ConversationController.get(message.sourceUuid)?.id ||
|
|
|
|
message.conversationId,
|
|
|
|
id: message.id,
|
|
|
|
received_at: message.received_at,
|
|
|
|
received_at_ms: Number(message.received_at_ms),
|
|
|
|
sent_at: message.sent_at,
|
|
|
|
},
|
|
|
|
};
|
|
|
|
}
|
|
|
|
),
|
|
|
|
],
|
|
|
|
[] as Array<MediaItemType>
|
|
|
|
);
|
|
|
|
|
|
|
|
dispatch({
|
|
|
|
type: 'SET_RECENT_MEDIA_ITEMS',
|
|
|
|
payload: { id: conversationId, recentMediaItems },
|
|
|
|
});
|
|
|
|
};
|
|
|
|
}
|
|
|
|
|
2023-01-13 20:07:26 +00:00
|
|
|
export type SaveAttachmentActionCreatorType = ReadonlyDeep<
|
|
|
|
(attachment: AttachmentType, timestamp?: number, index?: number) => unknown
|
|
|
|
>;
|
2022-12-14 18:12:04 +00:00
|
|
|
|
|
|
|
function saveAttachment(
|
|
|
|
attachment: AttachmentType,
|
|
|
|
timestamp = Date.now(),
|
|
|
|
index = 0
|
|
|
|
): ThunkAction<void, RootStateType, unknown, ShowToastActionType> {
|
|
|
|
return async dispatch => {
|
|
|
|
const { fileName = '' } = attachment;
|
|
|
|
|
|
|
|
const isDangerous = isFileDangerous(fileName);
|
|
|
|
|
|
|
|
if (isDangerous) {
|
|
|
|
dispatch({
|
|
|
|
type: SHOW_TOAST,
|
|
|
|
payload: {
|
|
|
|
toastType: ToastType.DangerousFileType,
|
|
|
|
},
|
|
|
|
});
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
const { readAttachmentData, saveAttachmentToDisk } =
|
|
|
|
window.Signal.Migrations;
|
|
|
|
|
|
|
|
const fullPath = await Attachment.save({
|
|
|
|
attachment,
|
|
|
|
index: index + 1,
|
|
|
|
readAttachmentData,
|
|
|
|
saveAttachmentToDisk,
|
|
|
|
timestamp,
|
|
|
|
});
|
|
|
|
|
|
|
|
if (fullPath) {
|
|
|
|
dispatch({
|
|
|
|
type: SHOW_TOAST,
|
|
|
|
payload: {
|
|
|
|
toastType: ToastType.FileSaved,
|
|
|
|
parameters: {
|
|
|
|
fullPath,
|
|
|
|
},
|
|
|
|
},
|
|
|
|
});
|
|
|
|
}
|
|
|
|
};
|
|
|
|
}
|
|
|
|
|
|
|
|
export function saveAttachmentFromMessage(
|
|
|
|
messageId: string,
|
|
|
|
providedAttachment?: AttachmentType
|
|
|
|
): ThunkAction<void, RootStateType, unknown, ShowToastActionType> {
|
|
|
|
return async (dispatch, getState) => {
|
|
|
|
const message = await getMessageById(messageId);
|
|
|
|
if (!message) {
|
|
|
|
throw new Error(
|
|
|
|
`saveAttachmentFromMessage: Message ${messageId} missing!`
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
|
|
|
const { attachments, sent_at: timestamp } = message.attributes;
|
|
|
|
if (!attachments || attachments.length < 1) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
const attachment =
|
|
|
|
providedAttachment && attachments.includes(providedAttachment)
|
|
|
|
? providedAttachment
|
|
|
|
: attachments[0];
|
|
|
|
|
|
|
|
saveAttachment(attachment, timestamp)(dispatch, getState, null);
|
|
|
|
};
|
|
|
|
}
|
|
|
|
|
2021-10-26 22:59:08 +00:00
|
|
|
function clearInvitedUuidsForNewlyCreatedGroup(): ClearInvitedUuidsForNewlyCreatedGroupActionType {
|
|
|
|
return { type: 'CLEAR_INVITED_UUIDS_FOR_NEWLY_CREATED_GROUP' };
|
2021-03-03 20:09:58 +00:00
|
|
|
}
|
|
|
|
function clearGroupCreationError(): ClearGroupCreationErrorActionType {
|
|
|
|
return { type: 'CLEAR_GROUP_CREATION_ERROR' };
|
|
|
|
}
|
2023-03-20 22:23:53 +00:00
|
|
|
function clearTargetedMessage(): ClearTargetedMessageActionType {
|
2019-05-31 22:42:01 +00:00
|
|
|
return {
|
2023-03-20 22:23:53 +00:00
|
|
|
type: 'CLEAR_TARGETED_MESSAGE',
|
2019-05-31 22:42:01 +00:00
|
|
|
payload: null,
|
|
|
|
};
|
|
|
|
}
|
|
|
|
function clearUnreadMetrics(
|
|
|
|
conversationId: string
|
|
|
|
): ClearUnreadMetricsActionType {
|
|
|
|
return {
|
|
|
|
type: 'CLEAR_UNREAD_METRICS',
|
|
|
|
payload: {
|
|
|
|
conversationId,
|
|
|
|
},
|
|
|
|
};
|
|
|
|
}
|
2021-04-21 16:31:12 +00:00
|
|
|
function closeContactSpoofingReview(): CloseContactSpoofingReviewActionType {
|
|
|
|
return { type: 'CLOSE_CONTACT_SPOOFING_REVIEW' };
|
|
|
|
}
|
2021-03-03 20:09:58 +00:00
|
|
|
function closeMaximumGroupSizeModal(): CloseMaximumGroupSizeModalActionType {
|
|
|
|
return { type: 'CLOSE_MAXIMUM_GROUP_SIZE_MODAL' };
|
|
|
|
}
|
|
|
|
function closeRecommendedGroupSizeModal(): CloseRecommendedGroupSizeModalActionType {
|
|
|
|
return { type: 'CLOSE_RECOMMENDED_GROUP_SIZE_MODAL' };
|
|
|
|
}
|
2022-12-09 19:11:14 +00:00
|
|
|
|
2023-05-23 21:59:07 +00:00
|
|
|
export function scrollToOldestUnreadMention(
|
|
|
|
conversationId: string
|
|
|
|
): ThunkAction<void, RootStateType, unknown, NoopActionType> {
|
|
|
|
return async (dispatch, getState) => {
|
|
|
|
const conversation = getOwn(
|
|
|
|
getState().conversations.conversationLookup,
|
|
|
|
conversationId
|
|
|
|
);
|
|
|
|
if (!conversation) {
|
|
|
|
log.warn(`No conversation found: [${conversationId}]`);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
const oldestUnreadMention =
|
|
|
|
await window.Signal.Data.getOldestUnreadMentionOfMeForConversation(
|
|
|
|
conversationId,
|
|
|
|
{
|
|
|
|
includeStoryReplies: !isGroup(conversation),
|
|
|
|
}
|
|
|
|
);
|
|
|
|
|
|
|
|
if (!oldestUnreadMention) {
|
|
|
|
log.warn(`No unread mention found for conversation: [${conversationId}]`);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
dispatch(scrollToMessage(conversationId, oldestUnreadMention.id));
|
|
|
|
};
|
|
|
|
}
|
|
|
|
|
2022-12-21 03:25:10 +00:00
|
|
|
export function scrollToMessage(
|
2019-05-31 22:42:01 +00:00
|
|
|
conversationId: string,
|
|
|
|
messageId: string
|
2022-12-09 19:11:14 +00:00
|
|
|
): ThunkAction<void, RootStateType, unknown, ScrollToMessageActionType> {
|
|
|
|
return async (dispatch, getState) => {
|
|
|
|
const conversation = window.ConversationController.get(conversationId);
|
|
|
|
if (!conversation) {
|
|
|
|
throw new Error('scrollToMessage: No conversation found');
|
|
|
|
}
|
|
|
|
|
|
|
|
const message = await getMessageById(messageId);
|
|
|
|
if (!message) {
|
|
|
|
throw new Error(`scrollToMessage: failed to load message ${messageId}`);
|
|
|
|
}
|
|
|
|
if (message.get('conversationId') !== conversationId) {
|
|
|
|
throw new Error(
|
|
|
|
`scrollToMessage: ${messageId} didn't have conversationId ${conversationId}`
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
|
|
|
const state = getState();
|
|
|
|
|
|
|
|
let isInMemory = true;
|
|
|
|
|
|
|
|
if (!window.MessageController.getById(messageId)) {
|
|
|
|
isInMemory = false;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Message might be in memory, but not in the redux anymore because
|
|
|
|
// we call `messageReset()` in `loadAndScroll()`.
|
|
|
|
const messagesByConversation =
|
|
|
|
getMessagesByConversation(state)[conversationId];
|
|
|
|
if (!messagesByConversation?.messageIds.includes(messageId)) {
|
|
|
|
isInMemory = false;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (isInMemory) {
|
|
|
|
dispatch({
|
|
|
|
type: 'SCROLL_TO_MESSAGE',
|
|
|
|
payload: {
|
|
|
|
conversationId,
|
|
|
|
messageId,
|
|
|
|
},
|
|
|
|
});
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2023-01-02 21:34:41 +00:00
|
|
|
drop(conversation.loadAndScroll(messageId));
|
2019-05-31 22:42:01 +00:00
|
|
|
};
|
|
|
|
}
|
2019-01-14 21:49:58 +00:00
|
|
|
|
2021-03-03 20:09:58 +00:00
|
|
|
function setComposeGroupAvatar(
|
2021-09-24 00:49:05 +00:00
|
|
|
groupAvatar: undefined | Uint8Array
|
2021-03-03 20:09:58 +00:00
|
|
|
): SetComposeGroupAvatarActionType {
|
|
|
|
return {
|
|
|
|
type: 'SET_COMPOSE_GROUP_AVATAR',
|
|
|
|
payload: { groupAvatar },
|
|
|
|
};
|
|
|
|
}
|
|
|
|
|
|
|
|
function setComposeGroupName(groupName: string): SetComposeGroupNameActionType {
|
|
|
|
return {
|
|
|
|
type: 'SET_COMPOSE_GROUP_NAME',
|
|
|
|
payload: { groupName },
|
|
|
|
};
|
|
|
|
}
|
|
|
|
|
2021-06-25 23:52:56 +00:00
|
|
|
function setComposeGroupExpireTimer(
|
2022-11-16 20:18:02 +00:00
|
|
|
groupExpireTimer: DurationInSeconds
|
2021-06-25 23:52:56 +00:00
|
|
|
): SetComposeGroupExpireTimerActionType {
|
|
|
|
return {
|
|
|
|
type: 'SET_COMPOSE_GROUP_EXPIRE_TIMER',
|
|
|
|
payload: { groupExpireTimer },
|
|
|
|
};
|
|
|
|
}
|
|
|
|
|
2021-02-23 20:34:28 +00:00
|
|
|
function setComposeSearchTerm(
|
2021-04-20 23:16:49 +00:00
|
|
|
searchTerm: string
|
2021-02-23 20:34:28 +00:00
|
|
|
): SetComposeSearchTermActionType {
|
|
|
|
return {
|
|
|
|
type: 'SET_COMPOSE_SEARCH_TERM',
|
2021-04-20 23:16:49 +00:00
|
|
|
payload: { searchTerm },
|
2021-02-23 20:34:28 +00:00
|
|
|
};
|
|
|
|
}
|
|
|
|
|
|
|
|
function startComposing(): StartComposingActionType {
|
|
|
|
return { type: 'START_COMPOSING' };
|
|
|
|
}
|
|
|
|
|
2021-03-03 20:09:58 +00:00
|
|
|
function showChooseGroupMembers(): ShowChooseGroupMembersActionType {
|
|
|
|
return { type: 'SHOW_CHOOSE_GROUP_MEMBERS' };
|
|
|
|
}
|
|
|
|
|
|
|
|
function startSettingGroupMetadata(): StartSettingGroupMetadataActionType {
|
|
|
|
return { type: 'START_SETTING_GROUP_METADATA' };
|
|
|
|
}
|
|
|
|
|
|
|
|
function toggleConversationInChooseMembers(
|
|
|
|
conversationId: string
|
|
|
|
): ThunkAction<
|
|
|
|
void,
|
|
|
|
RootStateType,
|
|
|
|
unknown,
|
|
|
|
ToggleConversationInChooseMembersActionType
|
|
|
|
> {
|
|
|
|
return dispatch => {
|
|
|
|
const maxRecommendedGroupSize = getGroupSizeRecommendedLimit(151);
|
|
|
|
const maxGroupSize = Math.max(
|
|
|
|
getGroupSizeHardLimit(1001),
|
|
|
|
maxRecommendedGroupSize + 1
|
|
|
|
);
|
|
|
|
|
2022-09-15 19:17:15 +00:00
|
|
|
assertDev(
|
2021-03-03 20:09:58 +00:00
|
|
|
maxGroupSize > maxRecommendedGroupSize,
|
|
|
|
'Expected the hard max group size to be larger than the recommended maximum'
|
|
|
|
);
|
|
|
|
|
|
|
|
dispatch({
|
|
|
|
type: 'TOGGLE_CONVERSATION_IN_CHOOSE_MEMBERS',
|
|
|
|
payload: { conversationId, maxGroupSize, maxRecommendedGroupSize },
|
|
|
|
});
|
|
|
|
};
|
|
|
|
}
|
|
|
|
|
2022-03-04 21:14:52 +00:00
|
|
|
function toggleHideStories(
|
|
|
|
conversationId: string
|
|
|
|
): ThunkAction<void, RootStateType, unknown, NoopActionType> {
|
|
|
|
return dispatch => {
|
|
|
|
const conversationModel = window.ConversationController.get(conversationId);
|
|
|
|
if (conversationModel) {
|
|
|
|
conversationModel.toggleHideStories();
|
|
|
|
}
|
|
|
|
dispatch({
|
|
|
|
type: 'NOOP',
|
|
|
|
payload: null,
|
|
|
|
});
|
|
|
|
};
|
|
|
|
}
|
|
|
|
|
2021-09-21 22:37:10 +00:00
|
|
|
function removeMemberFromGroup(
|
|
|
|
conversationId: string,
|
|
|
|
contactId: string
|
|
|
|
): ThunkAction<void, RootStateType, unknown, NoopActionType> {
|
|
|
|
return dispatch => {
|
|
|
|
const conversationModel = window.ConversationController.get(conversationId);
|
|
|
|
if (conversationModel) {
|
|
|
|
const idForLogging = conversationModel.idForLogging();
|
2022-12-21 18:41:48 +00:00
|
|
|
void longRunningTaskWrapper({
|
2021-09-21 22:37:10 +00:00
|
|
|
name: 'removeMemberFromGroup',
|
|
|
|
idForLogging,
|
|
|
|
task: () => conversationModel.removeFromGroupV2(contactId),
|
|
|
|
});
|
|
|
|
}
|
|
|
|
dispatch({
|
|
|
|
type: 'NOOP',
|
|
|
|
payload: null,
|
|
|
|
});
|
|
|
|
};
|
|
|
|
}
|
|
|
|
|
2022-12-16 03:12:05 +00:00
|
|
|
function addMembersToGroup(
|
2022-09-26 16:24:52 +00:00
|
|
|
conversationId: string,
|
2022-12-16 03:12:05 +00:00
|
|
|
contactIds: ReadonlyArray<string>,
|
|
|
|
{
|
|
|
|
onSuccess,
|
|
|
|
onFailure,
|
|
|
|
}: {
|
|
|
|
onSuccess?: () => unknown;
|
|
|
|
onFailure?: () => unknown;
|
|
|
|
} = {}
|
2022-09-26 16:24:52 +00:00
|
|
|
): ThunkAction<void, RootStateType, unknown, never> {
|
|
|
|
return async () => {
|
2022-12-16 03:12:05 +00:00
|
|
|
const conversation = window.ConversationController.get(conversationId);
|
|
|
|
if (!conversation) {
|
|
|
|
throw new Error('addMembersToGroup: No conversation found');
|
|
|
|
}
|
|
|
|
|
|
|
|
const idForLogging = conversation.idForLogging();
|
|
|
|
try {
|
2022-09-26 16:24:52 +00:00
|
|
|
await longRunningTaskWrapper({
|
2022-12-16 03:12:05 +00:00
|
|
|
name: 'addMembersToGroup',
|
2022-09-26 16:24:52 +00:00
|
|
|
idForLogging,
|
2022-12-16 03:12:05 +00:00
|
|
|
task: () =>
|
|
|
|
modifyGroupV2({
|
|
|
|
name: 'addMembersToGroup',
|
|
|
|
conversation,
|
|
|
|
usingCredentialsFrom: contactIds
|
|
|
|
.map(id => window.ConversationController.get(id))
|
|
|
|
.filter(isNotNil),
|
|
|
|
createGroupChange: async () =>
|
|
|
|
buildAddMembersChange(conversation.attributes, contactIds),
|
|
|
|
}),
|
|
|
|
});
|
|
|
|
onSuccess?.();
|
|
|
|
} catch {
|
|
|
|
onFailure?.();
|
|
|
|
}
|
|
|
|
};
|
|
|
|
}
|
|
|
|
|
|
|
|
function updateGroupAttributes(
|
|
|
|
conversationId: string,
|
|
|
|
attributes: Readonly<{
|
|
|
|
avatar?: undefined | Uint8Array;
|
|
|
|
description?: string;
|
|
|
|
title?: string;
|
|
|
|
}>,
|
|
|
|
{
|
|
|
|
onSuccess,
|
|
|
|
onFailure,
|
|
|
|
}: {
|
|
|
|
onSuccess?: () => unknown;
|
|
|
|
onFailure?: () => unknown;
|
|
|
|
} = {}
|
|
|
|
): ThunkAction<void, RootStateType, unknown, never> {
|
|
|
|
return async () => {
|
|
|
|
const conversation = window.ConversationController.get(conversationId);
|
|
|
|
if (!conversation) {
|
|
|
|
throw new Error('updateGroupAttributes: No conversation found');
|
|
|
|
}
|
|
|
|
|
|
|
|
const { id, publicParams, revision, secretParams } =
|
|
|
|
conversation.attributes;
|
|
|
|
|
|
|
|
try {
|
|
|
|
await modifyGroupV2({
|
|
|
|
name: 'updateGroupAttributes',
|
|
|
|
conversation,
|
|
|
|
usingCredentialsFrom: [],
|
|
|
|
createGroupChange: async () =>
|
|
|
|
buildUpdateAttributesChange(
|
|
|
|
{ id, publicParams, revision, secretParams },
|
|
|
|
attributes
|
|
|
|
),
|
2022-09-26 16:24:52 +00:00
|
|
|
});
|
2022-12-16 03:12:05 +00:00
|
|
|
onSuccess?.();
|
|
|
|
} catch {
|
|
|
|
onFailure?.();
|
2022-09-26 16:24:52 +00:00
|
|
|
}
|
|
|
|
};
|
|
|
|
}
|
|
|
|
|
2022-12-16 03:12:05 +00:00
|
|
|
function leaveGroup(
|
|
|
|
conversationId: string
|
|
|
|
): ThunkAction<void, RootStateType, unknown, never> {
|
|
|
|
return async () => {
|
|
|
|
const conversation = window.ConversationController.get(conversationId);
|
|
|
|
if (!conversation) {
|
|
|
|
throw new Error('leaveGroup: No conversation found');
|
|
|
|
}
|
|
|
|
|
|
|
|
await longRunningTaskWrapper({
|
|
|
|
idForLogging: conversation.idForLogging(),
|
|
|
|
name: 'leaveGroup',
|
|
|
|
task: () => conversation.leaveGroupV2(),
|
|
|
|
});
|
|
|
|
};
|
|
|
|
}
|
|
|
|
|
2022-08-30 19:13:32 +00:00
|
|
|
function toggleGroupsForStorySend(
|
2022-12-22 00:07:02 +00:00
|
|
|
conversationIds: ReadonlyArray<string>
|
2022-12-09 17:35:34 +00:00
|
|
|
): ThunkAction<Promise<void>, RootStateType, unknown, NoopActionType> {
|
2022-08-10 18:37:19 +00:00
|
|
|
return async dispatch => {
|
|
|
|
await Promise.all(
|
|
|
|
conversationIds.map(async conversationId => {
|
|
|
|
const conversation = window.ConversationController.get(conversationId);
|
|
|
|
if (!conversation) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2022-10-08 00:19:02 +00:00
|
|
|
const oldStorySendMode = conversation.getStorySendMode();
|
|
|
|
const newStorySendMode =
|
|
|
|
oldStorySendMode === StorySendMode.Always
|
|
|
|
? StorySendMode.Never
|
|
|
|
: StorySendMode.Always;
|
|
|
|
|
2022-08-30 19:13:32 +00:00
|
|
|
conversation.set({
|
2022-10-08 00:19:02 +00:00
|
|
|
storySendMode: newStorySendMode,
|
2022-08-30 19:13:32 +00:00
|
|
|
});
|
2022-11-08 20:01:59 +00:00
|
|
|
window.Signal.Data.updateConversation(conversation.attributes);
|
2022-10-08 00:19:02 +00:00
|
|
|
conversation.captureChange('storySendMode');
|
2022-08-10 18:37:19 +00:00
|
|
|
})
|
|
|
|
);
|
|
|
|
|
|
|
|
dispatch({
|
|
|
|
type: 'NOOP',
|
|
|
|
payload: null,
|
|
|
|
});
|
|
|
|
};
|
|
|
|
}
|
|
|
|
|
2021-09-21 22:37:10 +00:00
|
|
|
function toggleAdmin(
|
|
|
|
conversationId: string,
|
|
|
|
contactId: string
|
|
|
|
): ThunkAction<void, RootStateType, unknown, NoopActionType> {
|
|
|
|
return dispatch => {
|
|
|
|
const conversationModel = window.ConversationController.get(conversationId);
|
|
|
|
if (conversationModel) {
|
2022-12-21 18:41:48 +00:00
|
|
|
void conversationModel.toggleAdmin(contactId);
|
2021-09-21 22:37:10 +00:00
|
|
|
}
|
|
|
|
dispatch({
|
|
|
|
type: 'NOOP',
|
|
|
|
payload: null,
|
|
|
|
});
|
|
|
|
};
|
|
|
|
}
|
|
|
|
|
|
|
|
function updateConversationModelSharedGroups(
|
|
|
|
conversationId: string
|
|
|
|
): ThunkAction<void, RootStateType, unknown, NoopActionType> {
|
|
|
|
return dispatch => {
|
|
|
|
const conversation = window.ConversationController.get(conversationId);
|
|
|
|
if (conversation && conversation.throttledUpdateSharedGroups) {
|
2022-12-21 18:41:48 +00:00
|
|
|
void conversation.throttledUpdateSharedGroups();
|
2021-09-21 22:37:10 +00:00
|
|
|
}
|
|
|
|
dispatch({
|
|
|
|
type: 'NOOP',
|
|
|
|
payload: null,
|
|
|
|
});
|
|
|
|
};
|
|
|
|
}
|
|
|
|
|
2022-12-20 01:04:47 +00:00
|
|
|
function showExpiredIncomingTapToViewToast(): ShowToastActionType {
|
|
|
|
log.info(
|
|
|
|
'showExpiredIncomingTapToViewToastShowing expired tap-to-view toast for an incoming message'
|
|
|
|
);
|
|
|
|
return {
|
|
|
|
type: SHOW_TOAST,
|
|
|
|
payload: {
|
|
|
|
toastType: ToastType.TapToViewExpiredIncoming,
|
|
|
|
},
|
|
|
|
};
|
|
|
|
}
|
|
|
|
function showExpiredOutgoingTapToViewToast(): ShowToastActionType {
|
|
|
|
log.info('Showing expired tap-to-view toast for an outgoing message');
|
|
|
|
return {
|
|
|
|
type: SHOW_TOAST,
|
|
|
|
payload: {
|
|
|
|
toastType: ToastType.TapToViewExpiredOutgoing,
|
|
|
|
},
|
|
|
|
};
|
|
|
|
}
|
|
|
|
|
2020-09-14 21:56:35 +00:00
|
|
|
function showInbox(): ShowInboxActionType {
|
2019-03-12 00:20:16 +00:00
|
|
|
return {
|
|
|
|
type: 'SHOW_INBOX',
|
|
|
|
payload: null,
|
|
|
|
};
|
|
|
|
}
|
2022-06-16 19:12:50 +00:00
|
|
|
|
2023-01-13 20:07:26 +00:00
|
|
|
type ShowConversationArgsType = ReadonlyDeep<{
|
2022-06-16 19:12:50 +00:00
|
|
|
conversationId?: string;
|
|
|
|
messageId?: string;
|
|
|
|
switchToAssociatedView?: boolean;
|
2023-01-13 20:07:26 +00:00
|
|
|
}>;
|
|
|
|
export type ShowConversationType = ReadonlyDeep<
|
|
|
|
(options: ShowConversationArgsType) => unknown
|
|
|
|
>;
|
2022-06-16 19:12:50 +00:00
|
|
|
|
|
|
|
function showConversation({
|
|
|
|
conversationId,
|
|
|
|
messageId,
|
|
|
|
switchToAssociatedView,
|
2023-01-05 23:34:47 +00:00
|
|
|
}: ShowConversationArgsType): ThunkAction<
|
|
|
|
void,
|
|
|
|
RootStateType,
|
|
|
|
unknown,
|
2023-08-09 00:53:06 +00:00
|
|
|
TargetedConversationChangedActionType | ChangeNavTabActionType
|
2023-01-05 23:34:47 +00:00
|
|
|
> {
|
|
|
|
return (dispatch, getState) => {
|
2023-08-09 00:53:06 +00:00
|
|
|
const { conversations, nav } = getState();
|
|
|
|
|
|
|
|
if (nav.selectedNavTab !== NavTab.Chats) {
|
|
|
|
dispatch(navActions.changeNavTab(NavTab.Chats));
|
|
|
|
}
|
2023-01-05 23:34:47 +00:00
|
|
|
|
|
|
|
if (conversationId === conversations.selectedConversationId) {
|
2023-01-12 18:51:03 +00:00
|
|
|
if (conversationId && messageId) {
|
2023-08-09 00:53:06 +00:00
|
|
|
dispatch(scrollToMessage(conversationId, messageId));
|
2023-01-12 18:51:03 +00:00
|
|
|
}
|
|
|
|
|
2023-01-05 23:34:47 +00:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2023-03-02 20:55:40 +00:00
|
|
|
// notify composer in case we need to stop recording a voice note
|
|
|
|
if (conversations.selectedConversationId) {
|
|
|
|
dispatch(handleLeaveConversation(conversations.selectedConversationId));
|
|
|
|
}
|
|
|
|
|
2023-01-05 23:34:47 +00:00
|
|
|
dispatch({
|
2023-03-20 22:23:53 +00:00
|
|
|
type: TARGETED_CONVERSATION_CHANGED,
|
2023-01-05 23:34:47 +00:00
|
|
|
payload: {
|
|
|
|
conversationId,
|
|
|
|
messageId,
|
|
|
|
switchToAssociatedView,
|
|
|
|
},
|
|
|
|
});
|
2022-04-05 00:38:22 +00:00
|
|
|
};
|
|
|
|
}
|
2023-01-02 21:34:41 +00:00
|
|
|
|
|
|
|
function onConversationOpened(
|
|
|
|
conversationId: string,
|
|
|
|
messageId?: string
|
|
|
|
): ThunkAction<
|
|
|
|
void,
|
|
|
|
RootStateType,
|
|
|
|
unknown,
|
|
|
|
| ReplaceAttachmentsActionType
|
|
|
|
| ResetComposerActionType
|
|
|
|
| SetFocusActionType
|
|
|
|
| SetQuotedMessageActionType
|
|
|
|
> {
|
|
|
|
return async (dispatch, getState) => {
|
|
|
|
const conversation = window.ConversationController.get(conversationId);
|
|
|
|
if (!conversation) {
|
|
|
|
throw new Error('onConversationOpened: Conversation not found');
|
|
|
|
}
|
|
|
|
|
|
|
|
conversation.onOpenStart();
|
|
|
|
|
|
|
|
if (messageId) {
|
|
|
|
const message = await getMessageById(messageId);
|
|
|
|
|
|
|
|
if (message) {
|
|
|
|
drop(conversation.loadAndScroll(messageId));
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
log.warn(`onOpened: Did not find message ${messageId}`);
|
|
|
|
}
|
|
|
|
|
|
|
|
const { retryPlaceholders } = window.Signal.Services;
|
|
|
|
if (retryPlaceholders) {
|
|
|
|
await retryPlaceholders.findByConversationAndMarkOpened(conversation.id);
|
|
|
|
}
|
|
|
|
|
|
|
|
const loadAndUpdate = async () => {
|
|
|
|
drop(
|
|
|
|
Promise.all([
|
|
|
|
conversation.loadNewestMessages(undefined, undefined),
|
|
|
|
conversation.updateLastMessage(),
|
|
|
|
conversation.updateUnread(),
|
|
|
|
])
|
|
|
|
);
|
|
|
|
};
|
|
|
|
|
|
|
|
drop(loadAndUpdate());
|
|
|
|
|
|
|
|
dispatch(setComposerFocus(conversation.id));
|
|
|
|
|
|
|
|
const quotedMessageId = conversation.get('quotedMessageId');
|
|
|
|
if (quotedMessageId) {
|
|
|
|
setQuoteByMessageId(conversation.id, quotedMessageId)(
|
|
|
|
dispatch,
|
|
|
|
getState,
|
|
|
|
undefined
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
|
|
|
drop(conversation.fetchLatestGroupV2Data());
|
|
|
|
strictAssert(
|
|
|
|
conversation.throttledMaybeMigrateV1Group !== undefined,
|
|
|
|
'Conversation model should be initialized'
|
|
|
|
);
|
|
|
|
drop(conversation.throttledMaybeMigrateV1Group());
|
|
|
|
strictAssert(
|
|
|
|
conversation.throttledFetchSMSOnlyUUID !== undefined,
|
|
|
|
'Conversation model should be initialized'
|
|
|
|
);
|
|
|
|
drop(conversation.throttledFetchSMSOnlyUUID());
|
|
|
|
|
|
|
|
const ourUuid = window.textsecure.storage.user.getUuid(UUIDKind.ACI);
|
|
|
|
if (
|
|
|
|
!isGroup(conversation.attributes) ||
|
|
|
|
(ourUuid && conversation.hasMember(ourUuid))
|
|
|
|
) {
|
|
|
|
strictAssert(
|
|
|
|
conversation.throttledGetProfiles !== undefined,
|
|
|
|
'Conversation model should be initialized'
|
|
|
|
);
|
|
|
|
await conversation.throttledGetProfiles();
|
|
|
|
}
|
|
|
|
|
|
|
|
drop(conversation.updateVerified());
|
|
|
|
|
|
|
|
replaceAttachments(
|
|
|
|
conversation.get('id'),
|
|
|
|
conversation.get('draftAttachments') || []
|
|
|
|
)(dispatch, getState, undefined);
|
2023-01-05 00:22:36 +00:00
|
|
|
dispatch(resetComposer(conversationId));
|
2023-01-02 21:34:41 +00:00
|
|
|
};
|
|
|
|
}
|
|
|
|
|
|
|
|
function onConversationClosed(
|
|
|
|
conversationId: string,
|
|
|
|
reason: string
|
|
|
|
): ThunkAction<void, RootStateType, unknown, ConversationUnloadedActionType> {
|
|
|
|
return async dispatch => {
|
|
|
|
const conversation = window.ConversationController.get(conversationId);
|
|
|
|
if (!conversation) {
|
|
|
|
throw new Error('onConversationClosed: Conversation not found');
|
|
|
|
}
|
|
|
|
|
2023-01-13 01:25:59 +00:00
|
|
|
const logId = `onConversationClosed/${conversation.idForLogging()}`;
|
|
|
|
log.info(`${logId}: unloading due to ${reason}`);
|
2023-01-02 21:34:41 +00:00
|
|
|
|
|
|
|
if (conversation.get('draftChanged')) {
|
|
|
|
if (conversation.hasDraft()) {
|
2023-01-13 01:25:59 +00:00
|
|
|
log.info(`${logId}: new draft info needs update`);
|
2023-01-02 21:34:41 +00:00
|
|
|
const now = Date.now();
|
|
|
|
const activeAt = conversation.get('active_at') || now;
|
|
|
|
|
|
|
|
conversation.set({
|
|
|
|
active_at: activeAt,
|
|
|
|
draftChanged: false,
|
|
|
|
draftTimestamp: now,
|
|
|
|
timestamp: now,
|
|
|
|
});
|
|
|
|
} else {
|
2023-01-13 01:25:59 +00:00
|
|
|
log.info(`${logId}: clearing draft info`);
|
2023-01-02 21:34:41 +00:00
|
|
|
conversation.set({
|
|
|
|
draftChanged: false,
|
|
|
|
draftTimestamp: null,
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
window.Signal.Data.updateConversation(conversation.attributes);
|
|
|
|
|
|
|
|
drop(conversation.updateLastMessage());
|
|
|
|
}
|
|
|
|
|
2023-01-05 00:22:36 +00:00
|
|
|
removeLinkPreview(conversationId);
|
2023-01-02 21:34:41 +00:00
|
|
|
|
|
|
|
dispatch({
|
|
|
|
type: CONVERSATION_UNLOADED,
|
|
|
|
payload: {
|
2023-01-05 00:22:36 +00:00
|
|
|
conversationId,
|
2023-01-02 21:34:41 +00:00
|
|
|
},
|
|
|
|
});
|
|
|
|
};
|
|
|
|
}
|
|
|
|
|
2020-09-14 21:56:35 +00:00
|
|
|
function showArchivedConversations(): ShowArchivedConversationsActionType {
|
2019-03-12 00:20:16 +00:00
|
|
|
return {
|
|
|
|
type: 'SHOW_ARCHIVED_CONVERSATIONS',
|
|
|
|
payload: null,
|
|
|
|
};
|
|
|
|
}
|
|
|
|
|
2021-06-17 17:15:10 +00:00
|
|
|
function doubleCheckMissingQuoteReference(messageId: string): NoopActionType {
|
|
|
|
const message = window.MessageController.getById(messageId);
|
|
|
|
if (message) {
|
2022-12-21 18:41:48 +00:00
|
|
|
void message.doubleCheckMissingQuoteReference();
|
2021-06-17 17:15:10 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
return {
|
|
|
|
type: 'NOOP',
|
|
|
|
payload: null,
|
|
|
|
};
|
|
|
|
}
|
|
|
|
|
2019-01-14 21:49:58 +00:00
|
|
|
// Reducer
|
|
|
|
|
2020-12-07 20:43:19 +00:00
|
|
|
export function getEmptyState(): ConversationsStateType {
|
2019-01-14 21:49:58 +00:00
|
|
|
return {
|
|
|
|
conversationLookup: {},
|
2021-01-06 15:41:43 +00:00
|
|
|
conversationsByE164: {},
|
|
|
|
conversationsByUuid: {},
|
|
|
|
conversationsByGroupId: {},
|
2021-11-12 01:17:29 +00:00
|
|
|
conversationsByUsername: {},
|
2022-02-16 18:36:21 +00:00
|
|
|
verificationDataByConversation: {},
|
2019-03-20 17:42:28 +00:00
|
|
|
messagesByConversation: {},
|
2019-05-31 22:42:01 +00:00
|
|
|
messagesLookup: {},
|
2023-03-20 22:23:53 +00:00
|
|
|
targetedMessage: undefined,
|
|
|
|
targetedMessageCounter: 0,
|
|
|
|
targetedMessageSource: undefined,
|
|
|
|
lastSelectedMessage: undefined,
|
|
|
|
selectedMessageIds: undefined,
|
2019-05-31 22:42:01 +00:00
|
|
|
showArchived: false,
|
2023-07-26 22:23:32 +00:00
|
|
|
targetedConversationPanels: {
|
|
|
|
isAnimating: false,
|
|
|
|
direction: undefined,
|
|
|
|
stack: [],
|
|
|
|
watermark: -1,
|
|
|
|
},
|
2019-01-14 21:49:58 +00:00
|
|
|
};
|
|
|
|
}
|
|
|
|
|
2021-01-06 15:41:43 +00:00
|
|
|
export function updateConversationLookups(
|
|
|
|
added: ConversationType | undefined,
|
|
|
|
removed: ConversationType | undefined,
|
|
|
|
state: ConversationsStateType
|
|
|
|
): Pick<
|
|
|
|
ConversationsStateType,
|
2021-11-12 01:17:29 +00:00
|
|
|
| 'conversationsByE164'
|
|
|
|
| 'conversationsByUuid'
|
|
|
|
| 'conversationsByGroupId'
|
|
|
|
| 'conversationsByUsername'
|
2021-01-06 15:41:43 +00:00
|
|
|
> {
|
|
|
|
const result = {
|
|
|
|
conversationsByE164: state.conversationsByE164,
|
|
|
|
conversationsByUuid: state.conversationsByUuid,
|
|
|
|
conversationsByGroupId: state.conversationsByGroupId,
|
2021-11-12 01:17:29 +00:00
|
|
|
conversationsByUsername: state.conversationsByUsername,
|
2021-01-06 15:41:43 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
if (removed && removed.e164) {
|
|
|
|
result.conversationsByE164 = omit(result.conversationsByE164, removed.e164);
|
|
|
|
}
|
|
|
|
if (removed && removed.uuid) {
|
|
|
|
result.conversationsByUuid = omit(result.conversationsByUuid, removed.uuid);
|
|
|
|
}
|
2022-09-27 20:31:55 +00:00
|
|
|
if (removed && removed.pni) {
|
|
|
|
result.conversationsByUuid = omit(result.conversationsByUuid, removed.pni);
|
|
|
|
}
|
2021-01-06 15:41:43 +00:00
|
|
|
if (removed && removed.groupId) {
|
|
|
|
result.conversationsByGroupId = omit(
|
|
|
|
result.conversationsByGroupId,
|
|
|
|
removed.groupId
|
|
|
|
);
|
|
|
|
}
|
2021-11-12 01:17:29 +00:00
|
|
|
if (removed && removed.username) {
|
|
|
|
result.conversationsByUsername = omit(
|
|
|
|
result.conversationsByUsername,
|
|
|
|
removed.username
|
|
|
|
);
|
|
|
|
}
|
2021-01-06 15:41:43 +00:00
|
|
|
|
|
|
|
if (added && added.e164) {
|
|
|
|
result.conversationsByE164 = {
|
|
|
|
...result.conversationsByE164,
|
|
|
|
[added.e164]: added,
|
|
|
|
};
|
|
|
|
}
|
|
|
|
if (added && added.uuid) {
|
|
|
|
result.conversationsByUuid = {
|
|
|
|
...result.conversationsByUuid,
|
|
|
|
[added.uuid]: added,
|
|
|
|
};
|
|
|
|
}
|
2022-09-27 20:31:55 +00:00
|
|
|
if (added && added.pni) {
|
|
|
|
result.conversationsByUuid = {
|
|
|
|
...result.conversationsByUuid,
|
|
|
|
[added.pni]: added,
|
|
|
|
};
|
|
|
|
}
|
2021-01-06 15:41:43 +00:00
|
|
|
if (added && added.groupId) {
|
|
|
|
result.conversationsByGroupId = {
|
|
|
|
...result.conversationsByGroupId,
|
|
|
|
[added.groupId]: added,
|
|
|
|
};
|
|
|
|
}
|
2021-11-12 01:17:29 +00:00
|
|
|
if (added && added.username) {
|
|
|
|
result.conversationsByUsername = {
|
|
|
|
...result.conversationsByUsername,
|
|
|
|
[added.username]: added,
|
|
|
|
};
|
|
|
|
}
|
2021-01-06 15:41:43 +00:00
|
|
|
|
|
|
|
return result;
|
|
|
|
}
|
|
|
|
|
2021-03-03 20:09:58 +00:00
|
|
|
function closeComposerModal(
|
|
|
|
state: Readonly<ConversationsStateType>,
|
|
|
|
modalToClose: 'maximumGroupSizeModalState' | 'recommendedGroupSizeModalState'
|
|
|
|
): ConversationsStateType {
|
|
|
|
const { composer } = state;
|
|
|
|
if (composer?.step !== ComposerStep.ChooseGroupMembers) {
|
2022-09-15 19:17:15 +00:00
|
|
|
assertDev(
|
|
|
|
false,
|
|
|
|
"Can't close the modal in this composer step. Doing nothing"
|
|
|
|
);
|
2021-03-03 20:09:58 +00:00
|
|
|
return state;
|
|
|
|
}
|
|
|
|
if (composer[modalToClose] !== OneTimeModalState.Showing) {
|
|
|
|
return state;
|
|
|
|
}
|
|
|
|
return {
|
|
|
|
...state,
|
|
|
|
composer: {
|
|
|
|
...composer,
|
|
|
|
[modalToClose]: OneTimeModalState.Shown,
|
|
|
|
},
|
|
|
|
};
|
|
|
|
}
|
|
|
|
|
2022-11-11 04:10:30 +00:00
|
|
|
function getVerificationDataForConversation({
|
|
|
|
conversationId,
|
|
|
|
distributionId,
|
|
|
|
state,
|
|
|
|
untrustedUuids,
|
|
|
|
}: {
|
|
|
|
conversationId: string;
|
|
|
|
distributionId?: string;
|
|
|
|
state: Readonly<VerificationDataByConversation>;
|
|
|
|
untrustedUuids: ReadonlyArray<UUIDStringType>;
|
|
|
|
}): VerificationDataByConversation {
|
|
|
|
const existing = getOwn(state, conversationId);
|
2022-08-16 23:59:11 +00:00
|
|
|
|
|
|
|
if (
|
2022-11-11 04:10:30 +00:00
|
|
|
!existing ||
|
|
|
|
existing.type === ConversationVerificationState.VerificationCancelled
|
2022-08-16 23:59:11 +00:00
|
|
|
) {
|
|
|
|
return {
|
|
|
|
[conversationId]: {
|
|
|
|
type: ConversationVerificationState.PendingVerification as const,
|
2022-11-11 04:10:30 +00:00
|
|
|
uuidsNeedingVerification: distributionId ? [] : untrustedUuids,
|
|
|
|
...(distributionId
|
|
|
|
? {
|
|
|
|
byDistributionId: {
|
|
|
|
[distributionId]: {
|
|
|
|
uuidsNeedingVerification: untrustedUuids,
|
|
|
|
},
|
|
|
|
},
|
|
|
|
}
|
|
|
|
: undefined),
|
2022-08-16 23:59:11 +00:00
|
|
|
},
|
|
|
|
};
|
|
|
|
}
|
|
|
|
|
2022-11-11 04:10:30 +00:00
|
|
|
const existingUuids = distributionId
|
|
|
|
? existing.byDistributionId?.[distributionId]?.uuidsNeedingVerification
|
|
|
|
: existing.uuidsNeedingVerification;
|
|
|
|
|
|
|
|
const uuidsNeedingVerification: ReadonlyArray<UUIDStringType> = Array.from(
|
|
|
|
new Set([...(existingUuids || []), ...untrustedUuids])
|
2022-08-16 23:59:11 +00:00
|
|
|
);
|
|
|
|
|
|
|
|
return {
|
|
|
|
[conversationId]: {
|
2022-11-11 04:10:30 +00:00
|
|
|
...existing,
|
2022-08-16 23:59:11 +00:00
|
|
|
type: ConversationVerificationState.PendingVerification as const,
|
2022-11-11 04:10:30 +00:00
|
|
|
...(distributionId ? undefined : { uuidsNeedingVerification }),
|
|
|
|
...(distributionId
|
|
|
|
? {
|
|
|
|
byDistributionId: {
|
|
|
|
...existing.byDistributionId,
|
|
|
|
[distributionId]: {
|
|
|
|
uuidsNeedingVerification,
|
|
|
|
},
|
|
|
|
},
|
|
|
|
}
|
|
|
|
: undefined),
|
2022-08-16 23:59:11 +00:00
|
|
|
},
|
|
|
|
};
|
|
|
|
}
|
|
|
|
|
2022-11-11 04:10:30 +00:00
|
|
|
// Return same data, and we do nothing. Return undefined, and we'll delete the list.
|
2023-01-13 20:07:26 +00:00
|
|
|
type DistributionVisitor = ReadonlyDeep<
|
|
|
|
(
|
|
|
|
id: string,
|
|
|
|
data: DistributionVerificationData
|
|
|
|
) => DistributionVerificationData | undefined
|
|
|
|
>;
|
2022-11-11 04:10:30 +00:00
|
|
|
|
|
|
|
function visitListsInVerificationData(
|
|
|
|
existing: VerificationDataByConversation,
|
|
|
|
visitor: DistributionVisitor
|
|
|
|
): VerificationDataByConversation {
|
|
|
|
let result = existing;
|
|
|
|
|
|
|
|
Object.entries(result).forEach(([conversationId, conversationData]) => {
|
|
|
|
if (
|
|
|
|
conversationData.type !==
|
|
|
|
ConversationVerificationState.PendingVerification
|
|
|
|
) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
const { byDistributionId } = conversationData;
|
|
|
|
if (!byDistributionId) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
let updatedByDistributionId = byDistributionId;
|
|
|
|
Object.entries(byDistributionId).forEach(
|
|
|
|
([distributionId, distributionData]) => {
|
|
|
|
const visitorResult = visitor(distributionId, distributionData);
|
|
|
|
|
|
|
|
if (!visitorResult) {
|
|
|
|
updatedByDistributionId = omit(updatedByDistributionId, [
|
|
|
|
distributionId,
|
|
|
|
]);
|
|
|
|
} else if (visitorResult !== distributionData) {
|
|
|
|
updatedByDistributionId = {
|
|
|
|
...updatedByDistributionId,
|
|
|
|
[distributionId]: visitorResult,
|
|
|
|
};
|
|
|
|
}
|
|
|
|
}
|
|
|
|
);
|
|
|
|
|
|
|
|
const listCount = Object.keys(updatedByDistributionId).length;
|
|
|
|
if (
|
|
|
|
conversationData.uuidsNeedingVerification.length === 0 &&
|
|
|
|
listCount === 0
|
|
|
|
) {
|
|
|
|
result = omit(result, [conversationId]);
|
|
|
|
} else if (listCount === 0) {
|
|
|
|
result = {
|
|
|
|
...result,
|
|
|
|
[conversationId]: omit(conversationData, ['byDistributionId']),
|
|
|
|
};
|
|
|
|
} else if (updatedByDistributionId !== byDistributionId) {
|
|
|
|
result = {
|
|
|
|
...result,
|
|
|
|
[conversationId]: {
|
|
|
|
...conversationData,
|
|
|
|
byDistributionId: updatedByDistributionId,
|
|
|
|
},
|
|
|
|
};
|
|
|
|
}
|
|
|
|
});
|
|
|
|
|
|
|
|
return result;
|
|
|
|
}
|
|
|
|
|
2022-12-21 20:44:23 +00:00
|
|
|
function maybeUpdateSelectedMessageForDetails(
|
|
|
|
{
|
|
|
|
messageId,
|
2023-03-20 22:23:53 +00:00
|
|
|
targetedMessageForDetails,
|
2022-12-21 20:44:23 +00:00
|
|
|
}: {
|
|
|
|
messageId: string;
|
2023-03-20 22:23:53 +00:00
|
|
|
targetedMessageForDetails: MessageAttributesType | undefined;
|
2022-12-21 20:44:23 +00:00
|
|
|
},
|
|
|
|
state: ConversationsStateType
|
|
|
|
): ConversationsStateType {
|
2023-03-20 22:23:53 +00:00
|
|
|
if (!state.targetedMessageForDetails) {
|
2022-12-21 20:44:23 +00:00
|
|
|
return state;
|
|
|
|
}
|
|
|
|
|
2023-03-20 22:23:53 +00:00
|
|
|
if (state.targetedMessageForDetails.id !== messageId) {
|
2022-12-21 20:44:23 +00:00
|
|
|
return state;
|
|
|
|
}
|
|
|
|
|
|
|
|
return {
|
|
|
|
...state,
|
2023-03-20 22:23:53 +00:00
|
|
|
targetedMessageForDetails,
|
2022-12-21 20:44:23 +00:00
|
|
|
};
|
|
|
|
}
|
|
|
|
|
2019-01-14 21:49:58 +00:00
|
|
|
export function reducer(
|
2020-12-14 19:47:21 +00:00
|
|
|
state: Readonly<ConversationsStateType> = getEmptyState(),
|
2023-08-09 00:53:06 +00:00
|
|
|
action: Readonly<
|
|
|
|
| ConversationActionType
|
|
|
|
| StoryDistributionListsActionType
|
|
|
|
| ChangeNavTabActionType
|
|
|
|
>
|
2019-01-14 21:49:58 +00:00
|
|
|
): ConversationsStateType {
|
2022-02-16 18:36:21 +00:00
|
|
|
if (action.type === CLEAR_CONVERSATIONS_PENDING_VERIFICATION) {
|
|
|
|
return {
|
|
|
|
...state,
|
|
|
|
verificationDataByConversation: {},
|
|
|
|
};
|
|
|
|
}
|
|
|
|
|
|
|
|
if (action.type === CLEAR_CANCELLED_VERIFICATION) {
|
|
|
|
const { conversationId } = action.payload;
|
|
|
|
const { verificationDataByConversation } = state;
|
|
|
|
|
2022-11-11 04:10:30 +00:00
|
|
|
const existing = getOwn(verificationDataByConversation, conversationId);
|
2022-02-16 18:36:21 +00:00
|
|
|
|
|
|
|
// If there are active verifications required, this will do nothing.
|
|
|
|
if (
|
2022-11-11 04:10:30 +00:00
|
|
|
existing &&
|
|
|
|
existing.type === ConversationVerificationState.PendingVerification
|
2022-02-16 18:36:21 +00:00
|
|
|
) {
|
|
|
|
return state;
|
|
|
|
}
|
|
|
|
|
|
|
|
return {
|
|
|
|
...state,
|
|
|
|
verificationDataByConversation: omit(
|
|
|
|
verificationDataByConversation,
|
|
|
|
conversationId
|
|
|
|
),
|
|
|
|
};
|
|
|
|
}
|
|
|
|
|
|
|
|
if (action.type === CANCEL_CONVERSATION_PENDING_VERIFICATION) {
|
|
|
|
const { canceledAt } = action.payload;
|
|
|
|
const { verificationDataByConversation } = state;
|
|
|
|
const newverificationDataByConversation: Record<
|
|
|
|
string,
|
|
|
|
ConversationVerificationData
|
|
|
|
> = {};
|
|
|
|
|
|
|
|
const entries = Object.entries(verificationDataByConversation);
|
|
|
|
if (!entries.length) {
|
|
|
|
log.warn(
|
|
|
|
'CANCEL_CONVERSATION_PENDING_VERIFICATION: No conversations pending verification'
|
|
|
|
);
|
|
|
|
return state;
|
|
|
|
}
|
|
|
|
|
|
|
|
for (const [conversationId, data] of entries) {
|
|
|
|
if (
|
|
|
|
data.type === ConversationVerificationState.VerificationCancelled &&
|
|
|
|
data.canceledAt > canceledAt
|
|
|
|
) {
|
|
|
|
newverificationDataByConversation[conversationId] = data;
|
|
|
|
} else {
|
|
|
|
newverificationDataByConversation[conversationId] = {
|
|
|
|
type: ConversationVerificationState.VerificationCancelled,
|
|
|
|
canceledAt,
|
|
|
|
};
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2021-08-31 20:58:39 +00:00
|
|
|
return {
|
|
|
|
...state,
|
2022-02-16 18:36:21 +00:00
|
|
|
verificationDataByConversation: newverificationDataByConversation,
|
2021-08-31 20:58:39 +00:00
|
|
|
};
|
|
|
|
}
|
|
|
|
|
2021-10-26 22:59:08 +00:00
|
|
|
if (action.type === 'CLEAR_INVITED_UUIDS_FOR_NEWLY_CREATED_GROUP') {
|
|
|
|
return omit(state, 'invitedUuidsForNewlyCreatedGroup');
|
2021-03-03 20:09:58 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
if (action.type === 'CLEAR_GROUP_CREATION_ERROR') {
|
|
|
|
const { composer } = state;
|
|
|
|
if (composer?.step !== ComposerStep.SetGroupMetadata) {
|
2022-09-15 19:17:15 +00:00
|
|
|
assertDev(
|
2021-03-03 20:09:58 +00:00
|
|
|
false,
|
|
|
|
"Can't clear group creation error in this composer state. Doing nothing"
|
|
|
|
);
|
|
|
|
return state;
|
|
|
|
}
|
|
|
|
return {
|
|
|
|
...state,
|
|
|
|
composer: {
|
|
|
|
...composer,
|
|
|
|
hasError: false,
|
|
|
|
},
|
|
|
|
};
|
|
|
|
}
|
|
|
|
|
2021-04-21 16:31:12 +00:00
|
|
|
if (action.type === 'CLOSE_CONTACT_SPOOFING_REVIEW') {
|
|
|
|
return omit(state, 'contactSpoofingReview');
|
|
|
|
}
|
|
|
|
|
2021-03-03 20:09:58 +00:00
|
|
|
if (action.type === 'CLOSE_MAXIMUM_GROUP_SIZE_MODAL') {
|
|
|
|
return closeComposerModal(state, 'maximumGroupSizeModalState' as const);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (action.type === 'CLOSE_RECOMMENDED_GROUP_SIZE_MODAL') {
|
|
|
|
return closeComposerModal(state, 'recommendedGroupSizeModalState' as const);
|
|
|
|
}
|
|
|
|
|
2022-03-03 20:23:10 +00:00
|
|
|
if (action.type === DISCARD_MESSAGES) {
|
2023-03-20 22:23:53 +00:00
|
|
|
if (state.selectedMessageIds != null) {
|
|
|
|
log.info('Not discarding messages because we are in select mode');
|
|
|
|
return state;
|
|
|
|
}
|
|
|
|
|
2022-05-10 20:19:58 +00:00
|
|
|
const { conversationId } = action.payload;
|
|
|
|
if ('numberToKeepAtBottom' in action.payload) {
|
|
|
|
const { numberToKeepAtBottom } = action.payload;
|
|
|
|
const conversationMessages = getOwn(
|
|
|
|
state.messagesByConversation,
|
|
|
|
conversationId
|
|
|
|
);
|
|
|
|
if (!conversationMessages) {
|
|
|
|
return state;
|
|
|
|
}
|
2022-03-03 20:23:10 +00:00
|
|
|
|
2022-05-10 20:19:58 +00:00
|
|
|
const { messageIds: oldMessageIds } = conversationMessages;
|
|
|
|
if (oldMessageIds.length <= numberToKeepAtBottom) {
|
|
|
|
return state;
|
|
|
|
}
|
2022-03-03 20:23:10 +00:00
|
|
|
|
2022-05-10 20:19:58 +00:00
|
|
|
const messageIdsToRemove = oldMessageIds.slice(0, -numberToKeepAtBottom);
|
|
|
|
const messageIdsToKeep = oldMessageIds.slice(-numberToKeepAtBottom);
|
|
|
|
|
|
|
|
return {
|
|
|
|
...state,
|
|
|
|
messagesLookup: omit(state.messagesLookup, messageIdsToRemove),
|
|
|
|
messagesByConversation: {
|
|
|
|
...state.messagesByConversation,
|
|
|
|
[conversationId]: {
|
|
|
|
...conversationMessages,
|
|
|
|
messageIds: messageIdsToKeep,
|
|
|
|
},
|
|
|
|
},
|
|
|
|
};
|
2022-03-03 20:23:10 +00:00
|
|
|
}
|
|
|
|
|
2022-05-10 20:19:58 +00:00
|
|
|
if ('numberToKeepAtTop' in action.payload) {
|
|
|
|
const { numberToKeepAtTop } = action.payload;
|
|
|
|
const conversationMessages = getOwn(
|
|
|
|
state.messagesByConversation,
|
|
|
|
conversationId
|
|
|
|
);
|
|
|
|
if (!conversationMessages) {
|
|
|
|
return state;
|
|
|
|
}
|
2022-03-03 20:23:10 +00:00
|
|
|
|
2022-05-10 20:19:58 +00:00
|
|
|
const { messageIds: oldMessageIds } = conversationMessages;
|
|
|
|
if (oldMessageIds.length <= numberToKeepAtTop) {
|
|
|
|
return state;
|
|
|
|
}
|
|
|
|
|
|
|
|
const messageIdsToRemove = oldMessageIds.slice(numberToKeepAtTop);
|
|
|
|
const messageIdsToKeep = oldMessageIds.slice(0, numberToKeepAtTop);
|
|
|
|
|
|
|
|
return {
|
|
|
|
...state,
|
|
|
|
messagesLookup: omit(state.messagesLookup, messageIdsToRemove),
|
|
|
|
messagesByConversation: {
|
|
|
|
...state.messagesByConversation,
|
|
|
|
[conversationId]: {
|
|
|
|
...conversationMessages,
|
|
|
|
messageIds: messageIdsToKeep,
|
|
|
|
},
|
2022-03-03 20:23:10 +00:00
|
|
|
},
|
2022-05-10 20:19:58 +00:00
|
|
|
};
|
|
|
|
}
|
|
|
|
|
|
|
|
throw missingCaseError(action.payload);
|
2022-03-03 20:23:10 +00:00
|
|
|
}
|
|
|
|
|
2021-01-29 22:16:48 +00:00
|
|
|
if (action.type === 'SET_PRE_JOIN_CONVERSATION') {
|
|
|
|
const { payload } = action;
|
|
|
|
const { data } = payload;
|
|
|
|
|
|
|
|
return {
|
|
|
|
...state,
|
|
|
|
preJoinConversation: data,
|
|
|
|
};
|
|
|
|
}
|
2019-01-14 21:49:58 +00:00
|
|
|
if (action.type === 'CONVERSATION_ADDED') {
|
|
|
|
const { payload } = action;
|
|
|
|
const { id, data } = payload;
|
|
|
|
const { conversationLookup } = state;
|
|
|
|
|
|
|
|
return {
|
|
|
|
...state,
|
|
|
|
conversationLookup: {
|
|
|
|
...conversationLookup,
|
|
|
|
[id]: data,
|
|
|
|
},
|
2021-01-06 15:41:43 +00:00
|
|
|
...updateConversationLookups(data, undefined, state),
|
2019-01-14 21:49:58 +00:00
|
|
|
};
|
|
|
|
}
|
|
|
|
if (action.type === 'CONVERSATION_CHANGED') {
|
|
|
|
const { payload } = action;
|
|
|
|
const { id, data } = payload;
|
|
|
|
const { conversationLookup } = state;
|
|
|
|
|
2021-04-21 16:31:12 +00:00
|
|
|
const { selectedConversationId } = state;
|
|
|
|
let { showArchived } = state;
|
2019-03-12 00:20:16 +00:00
|
|
|
|
|
|
|
const existing = conversationLookup[id];
|
2021-05-21 19:53:05 +00:00
|
|
|
// We only modify the lookup if we already had that conversation and the conversation
|
|
|
|
// changed.
|
|
|
|
if (!existing || data === existing) {
|
2019-01-14 21:49:58 +00:00
|
|
|
return state;
|
|
|
|
}
|
|
|
|
|
2021-04-21 16:31:12 +00:00
|
|
|
const keysToOmit: Array<keyof ConversationsStateType> = [];
|
|
|
|
|
2021-02-12 21:58:14 +00:00
|
|
|
if (selectedConversationId === id) {
|
2019-03-12 00:20:16 +00:00
|
|
|
// Archived -> Inbox: we go back to the normal inbox view
|
|
|
|
if (existing.isArchived && !data.isArchived) {
|
|
|
|
showArchived = false;
|
|
|
|
}
|
|
|
|
// Inbox -> Archived: no conversation is selected
|
2022-02-16 18:36:21 +00:00
|
|
|
// Note: With today's stacked conversations architecture, this can result in weird
|
2019-03-12 00:20:16 +00:00
|
|
|
// behavior - no selected conversation in the left pane, but a conversation show
|
|
|
|
// in the right pane.
|
|
|
|
if (!existing.isArchived && data.isArchived) {
|
2021-04-21 16:31:12 +00:00
|
|
|
keysToOmit.push('selectedConversationId');
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!existing.isBlocked && data.isBlocked) {
|
|
|
|
keysToOmit.push('contactSpoofingReview');
|
2019-03-12 00:20:16 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-01-14 21:49:58 +00:00
|
|
|
return {
|
2021-04-21 16:31:12 +00:00
|
|
|
...omit(state, keysToOmit),
|
2021-02-12 21:58:14 +00:00
|
|
|
selectedConversationId,
|
2019-03-12 00:20:16 +00:00
|
|
|
showArchived,
|
2019-01-14 21:49:58 +00:00
|
|
|
conversationLookup: {
|
|
|
|
...conversationLookup,
|
|
|
|
[id]: data,
|
|
|
|
},
|
2021-01-06 15:41:43 +00:00
|
|
|
...updateConversationLookups(data, existing, state),
|
2019-01-14 21:49:58 +00:00
|
|
|
};
|
|
|
|
}
|
|
|
|
if (action.type === 'CONVERSATION_REMOVED') {
|
|
|
|
const { payload } = action;
|
|
|
|
const { id } = payload;
|
|
|
|
const { conversationLookup } = state;
|
2021-01-06 15:41:43 +00:00
|
|
|
const existing = getOwn(conversationLookup, id);
|
|
|
|
|
|
|
|
// No need to make a change if we didn't have a record of this conversation!
|
|
|
|
if (!existing) {
|
|
|
|
return state;
|
|
|
|
}
|
2019-01-14 21:49:58 +00:00
|
|
|
|
|
|
|
return {
|
|
|
|
...state,
|
|
|
|
conversationLookup: omit(conversationLookup, [id]),
|
2021-01-06 15:41:43 +00:00
|
|
|
...updateConversationLookups(undefined, existing, state),
|
2019-01-14 21:49:58 +00:00
|
|
|
};
|
|
|
|
}
|
2022-12-20 17:50:23 +00:00
|
|
|
if (action.type === CONVERSATION_UNLOADED) {
|
2019-05-31 22:42:01 +00:00
|
|
|
const { payload } = action;
|
2023-01-05 00:22:36 +00:00
|
|
|
const { conversationId } = payload;
|
|
|
|
const existingConversation = state.messagesByConversation[conversationId];
|
2019-05-31 22:42:01 +00:00
|
|
|
if (!existingConversation) {
|
|
|
|
return state;
|
|
|
|
}
|
|
|
|
|
|
|
|
const { messageIds } = existingConversation;
|
2021-02-12 21:58:14 +00:00
|
|
|
const selectedConversationId =
|
2023-01-05 00:22:36 +00:00
|
|
|
state.selectedConversationId !== conversationId
|
2021-02-12 21:58:14 +00:00
|
|
|
? state.selectedConversationId
|
2019-11-07 21:36:16 +00:00
|
|
|
: undefined;
|
2019-05-31 22:42:01 +00:00
|
|
|
|
|
|
|
return {
|
2021-04-21 16:31:12 +00:00
|
|
|
...omit(state, 'contactSpoofingReview'),
|
2021-02-12 21:58:14 +00:00
|
|
|
selectedConversationId,
|
2023-07-26 22:23:32 +00:00
|
|
|
targetedConversationPanels: {
|
|
|
|
isAnimating: false,
|
|
|
|
direction: undefined,
|
|
|
|
stack: [],
|
|
|
|
watermark: -1,
|
|
|
|
},
|
2022-12-22 00:07:02 +00:00
|
|
|
messagesLookup: omit(state.messagesLookup, [...messageIds]),
|
2023-01-05 00:22:36 +00:00
|
|
|
messagesByConversation: omit(state.messagesByConversation, [
|
|
|
|
conversationId,
|
|
|
|
]),
|
2019-05-31 22:42:01 +00:00
|
|
|
};
|
|
|
|
}
|
2019-01-14 21:49:58 +00:00
|
|
|
if (action.type === 'CONVERSATIONS_REMOVE_ALL') {
|
|
|
|
return getEmptyState();
|
|
|
|
}
|
2021-03-03 20:09:58 +00:00
|
|
|
if (action.type === 'CREATE_GROUP_PENDING') {
|
|
|
|
const { composer } = state;
|
|
|
|
if (composer?.step !== ComposerStep.SetGroupMetadata) {
|
|
|
|
// This should be unlikely, but it can happen if someone closes the composer while
|
|
|
|
// a group is being created.
|
|
|
|
return state;
|
|
|
|
}
|
|
|
|
return {
|
|
|
|
...state,
|
|
|
|
composer: {
|
|
|
|
...composer,
|
|
|
|
hasError: false,
|
|
|
|
isCreating: true,
|
|
|
|
},
|
|
|
|
};
|
|
|
|
}
|
|
|
|
if (action.type === 'CREATE_GROUP_FULFILLED') {
|
2022-06-16 19:12:50 +00:00
|
|
|
// We don't do much here and instead rely on `showConversation` to do most of
|
2021-03-03 20:09:58 +00:00
|
|
|
// the work.
|
|
|
|
return {
|
|
|
|
...state,
|
2021-10-26 22:59:08 +00:00
|
|
|
invitedUuidsForNewlyCreatedGroup: action.payload.invitedUuids,
|
2021-03-03 20:09:58 +00:00
|
|
|
};
|
|
|
|
}
|
|
|
|
if (action.type === 'CREATE_GROUP_REJECTED') {
|
|
|
|
const { composer } = state;
|
|
|
|
if (composer?.step !== ComposerStep.SetGroupMetadata) {
|
|
|
|
// This should be unlikely, but it can happen if someone closes the composer while
|
|
|
|
// a group is being created.
|
|
|
|
return state;
|
|
|
|
}
|
|
|
|
return {
|
|
|
|
...state,
|
|
|
|
composer: {
|
|
|
|
...composer,
|
|
|
|
hasError: true,
|
|
|
|
isCreating: false,
|
|
|
|
},
|
|
|
|
};
|
|
|
|
}
|
2023-03-20 22:23:53 +00:00
|
|
|
if (action.type === 'MESSAGE_TARGETED') {
|
2019-11-07 21:36:16 +00:00
|
|
|
const { messageId, conversationId } = action.payload;
|
|
|
|
|
2021-02-12 21:58:14 +00:00
|
|
|
if (state.selectedConversationId !== conversationId) {
|
2019-11-07 21:36:16 +00:00
|
|
|
return state;
|
|
|
|
}
|
|
|
|
|
|
|
|
return {
|
|
|
|
...state,
|
2023-03-20 22:23:53 +00:00
|
|
|
targetedMessage: messageId,
|
|
|
|
targetedMessageCounter: state.targetedMessageCounter + 1,
|
|
|
|
targetedMessageSource: TargetedMessageSource.Focus,
|
|
|
|
};
|
|
|
|
}
|
|
|
|
|
|
|
|
if (action.type === 'TOGGLE_SELECT_MESSAGES') {
|
|
|
|
const { toggledMessageId, messageIds, selected } = action.payload;
|
|
|
|
let { selectedMessageIds = [] } = state;
|
|
|
|
|
|
|
|
if (selected) {
|
|
|
|
selectedMessageIds = selectedMessageIds.concat(messageIds);
|
|
|
|
} else {
|
|
|
|
selectedMessageIds = selectedMessageIds.filter(
|
|
|
|
id => !messageIds.includes(id)
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
|
|
|
const lastSelectedMessage = getOwn(state.messagesLookup, toggledMessageId);
|
|
|
|
|
|
|
|
strictAssert(lastSelectedMessage, 'Message not found in lookup');
|
|
|
|
|
|
|
|
return {
|
|
|
|
...state,
|
|
|
|
lastSelectedMessage: selected
|
|
|
|
? pick(lastSelectedMessage, 'sent_at', 'received_at')
|
|
|
|
: undefined,
|
|
|
|
selectedMessageIds,
|
|
|
|
};
|
|
|
|
}
|
|
|
|
|
|
|
|
if (action.type === 'TOGGLE_SELECT_MODE') {
|
|
|
|
const { on } = action.payload;
|
|
|
|
const { selectedMessageIds = [] } = state;
|
|
|
|
return {
|
|
|
|
...state,
|
|
|
|
lastSelectedMessage: undefined,
|
|
|
|
selectedMessageIds: on ? selectedMessageIds : undefined,
|
2019-11-07 21:36:16 +00:00
|
|
|
};
|
|
|
|
}
|
2022-11-11 04:10:30 +00:00
|
|
|
|
|
|
|
if (action.type === MODIFY_LIST) {
|
|
|
|
const {
|
|
|
|
id: listId,
|
|
|
|
isBlockList,
|
|
|
|
membersToRemove,
|
|
|
|
membersToAdd,
|
|
|
|
} = action.payload;
|
|
|
|
const removedUuids = new Set(isBlockList ? membersToAdd : membersToRemove);
|
|
|
|
|
|
|
|
const nextVerificationData = visitListsInVerificationData(
|
|
|
|
state.verificationDataByConversation,
|
|
|
|
(id, data): DistributionVerificationData | undefined => {
|
|
|
|
if (listId === id) {
|
|
|
|
const uuidsNeedingVerification = data.uuidsNeedingVerification.filter(
|
|
|
|
uuid => !removedUuids.has(uuid)
|
|
|
|
);
|
|
|
|
|
|
|
|
if (!uuidsNeedingVerification.length) {
|
|
|
|
return undefined;
|
|
|
|
}
|
|
|
|
return {
|
|
|
|
...data,
|
|
|
|
uuidsNeedingVerification,
|
|
|
|
};
|
|
|
|
}
|
|
|
|
|
|
|
|
return data;
|
|
|
|
}
|
|
|
|
);
|
|
|
|
|
|
|
|
if (nextVerificationData === state.verificationDataByConversation) {
|
|
|
|
return state;
|
|
|
|
}
|
|
|
|
|
|
|
|
return {
|
|
|
|
...state,
|
|
|
|
verificationDataByConversation: nextVerificationData,
|
|
|
|
};
|
|
|
|
}
|
|
|
|
if (action.type === DELETE_LIST) {
|
|
|
|
const { listId } = action.payload;
|
|
|
|
|
|
|
|
const nextVerificationData = visitListsInVerificationData(
|
|
|
|
state.verificationDataByConversation,
|
|
|
|
(id, data): DistributionVerificationData | undefined => {
|
|
|
|
if (listId === id) {
|
|
|
|
return undefined;
|
|
|
|
}
|
|
|
|
|
|
|
|
return data;
|
|
|
|
}
|
|
|
|
);
|
|
|
|
|
|
|
|
if (nextVerificationData === state.verificationDataByConversation) {
|
|
|
|
return state;
|
|
|
|
}
|
|
|
|
|
|
|
|
return {
|
|
|
|
...state,
|
|
|
|
verificationDataByConversation: nextVerificationData,
|
|
|
|
};
|
|
|
|
}
|
|
|
|
if (action.type === HIDE_MY_STORIES_FROM) {
|
|
|
|
const removedUuids = new Set(action.payload);
|
|
|
|
|
|
|
|
const nextVerificationData = visitListsInVerificationData(
|
|
|
|
state.verificationDataByConversation,
|
|
|
|
(id, data): DistributionVerificationData | undefined => {
|
|
|
|
if (MY_STORY_ID === id) {
|
|
|
|
const uuidsNeedingVerification = data.uuidsNeedingVerification.filter(
|
|
|
|
uuid => !removedUuids.has(uuid)
|
|
|
|
);
|
|
|
|
|
|
|
|
if (!uuidsNeedingVerification.length) {
|
|
|
|
return undefined;
|
|
|
|
}
|
|
|
|
|
|
|
|
return {
|
|
|
|
...data,
|
|
|
|
uuidsNeedingVerification,
|
|
|
|
};
|
|
|
|
}
|
|
|
|
|
|
|
|
return data;
|
|
|
|
}
|
|
|
|
);
|
|
|
|
|
|
|
|
if (nextVerificationData === state.verificationDataByConversation) {
|
|
|
|
return state;
|
|
|
|
}
|
|
|
|
|
|
|
|
return {
|
|
|
|
...state,
|
|
|
|
verificationDataByConversation: nextVerificationData,
|
|
|
|
};
|
|
|
|
}
|
|
|
|
if (action.type === VIEWERS_CHANGED) {
|
|
|
|
const { listId, memberUuids } = action.payload;
|
|
|
|
const newUuids = new Set(memberUuids);
|
|
|
|
|
|
|
|
const nextVerificationData = visitListsInVerificationData(
|
|
|
|
state.verificationDataByConversation,
|
|
|
|
(id, data): DistributionVerificationData | undefined => {
|
|
|
|
if (listId === id) {
|
|
|
|
const uuidsNeedingVerification = data.uuidsNeedingVerification.filter(
|
|
|
|
uuid => newUuids.has(uuid)
|
|
|
|
);
|
|
|
|
|
|
|
|
if (!uuidsNeedingVerification.length) {
|
|
|
|
return undefined;
|
|
|
|
}
|
|
|
|
|
|
|
|
return {
|
|
|
|
...data,
|
|
|
|
uuidsNeedingVerification,
|
|
|
|
};
|
|
|
|
}
|
|
|
|
|
|
|
|
return data;
|
|
|
|
}
|
|
|
|
);
|
|
|
|
|
|
|
|
if (nextVerificationData === state.verificationDataByConversation) {
|
|
|
|
return state;
|
|
|
|
}
|
|
|
|
|
|
|
|
return {
|
|
|
|
...state,
|
|
|
|
verificationDataByConversation: nextVerificationData,
|
|
|
|
};
|
|
|
|
}
|
|
|
|
|
2022-02-16 18:36:21 +00:00
|
|
|
if (action.type === CONVERSATION_STOPPED_BY_MISSING_VERIFICATION) {
|
2022-11-11 04:10:30 +00:00
|
|
|
const { conversationId, distributionId, untrustedUuids } = action.payload;
|
2021-08-31 20:58:39 +00:00
|
|
|
|
2022-11-11 04:10:30 +00:00
|
|
|
const nextVerificationData = getVerificationDataForConversation({
|
2022-08-16 23:59:11 +00:00
|
|
|
conversationId,
|
2022-11-11 04:10:30 +00:00
|
|
|
distributionId,
|
|
|
|
state: state.verificationDataByConversation,
|
|
|
|
untrustedUuids,
|
|
|
|
});
|
2022-02-16 18:36:21 +00:00
|
|
|
|
2022-08-16 23:59:11 +00:00
|
|
|
return {
|
|
|
|
...state,
|
|
|
|
verificationDataByConversation: {
|
|
|
|
...state.verificationDataByConversation,
|
|
|
|
...nextVerificationData,
|
|
|
|
},
|
|
|
|
};
|
|
|
|
}
|
|
|
|
if (action.type === SHOW_SEND_ANYWAY_DIALOG) {
|
|
|
|
const verificationDataByConversation = {
|
|
|
|
...state.verificationDataByConversation,
|
|
|
|
};
|
2022-02-16 18:36:21 +00:00
|
|
|
|
2022-11-11 04:10:30 +00:00
|
|
|
Object.entries(action.payload.untrustedByConversation).forEach(
|
|
|
|
([conversationId, conversationData]) => {
|
|
|
|
const nextConversation = getVerificationDataForConversation({
|
|
|
|
state: verificationDataByConversation,
|
2022-08-16 23:59:11 +00:00
|
|
|
conversationId,
|
2022-11-11 04:10:30 +00:00
|
|
|
untrustedUuids: conversationData.uuids,
|
|
|
|
});
|
|
|
|
Object.assign(verificationDataByConversation, nextConversation);
|
|
|
|
|
|
|
|
if (!conversationData.byDistributionId) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
Object.entries(conversationData.byDistributionId).forEach(
|
|
|
|
([distributionId, distributionData]) => {
|
|
|
|
const nextDistribution = getVerificationDataForConversation({
|
|
|
|
state: verificationDataByConversation,
|
|
|
|
distributionId,
|
|
|
|
conversationId,
|
|
|
|
untrustedUuids: distributionData.uuids,
|
|
|
|
});
|
|
|
|
Object.assign(verificationDataByConversation, nextDistribution);
|
|
|
|
}
|
2022-08-16 23:59:11 +00:00
|
|
|
);
|
|
|
|
}
|
2022-02-16 18:36:21 +00:00
|
|
|
);
|
2021-08-31 20:58:39 +00:00
|
|
|
|
|
|
|
return {
|
|
|
|
...state,
|
2022-08-16 23:59:11 +00:00
|
|
|
verificationDataByConversation,
|
2021-08-31 20:58:39 +00:00
|
|
|
};
|
|
|
|
}
|
2022-12-21 20:44:23 +00:00
|
|
|
|
2023-01-05 22:16:56 +00:00
|
|
|
if (action.type === MESSAGE_CHANGED) {
|
2019-05-31 22:42:01 +00:00
|
|
|
const { id, conversationId, data } = action.payload;
|
|
|
|
const existingConversation = state.messagesByConversation[conversationId];
|
|
|
|
|
|
|
|
// We don't keep track of messages unless their conversation is loaded...
|
|
|
|
if (!existingConversation) {
|
2022-12-21 20:44:23 +00:00
|
|
|
return maybeUpdateSelectedMessageForDetails(
|
2023-03-20 22:23:53 +00:00
|
|
|
{ messageId: id, targetedMessageForDetails: data },
|
2022-12-21 20:44:23 +00:00
|
|
|
state
|
|
|
|
);
|
2019-05-31 22:42:01 +00:00
|
|
|
}
|
2022-12-21 20:44:23 +00:00
|
|
|
|
2019-05-31 22:42:01 +00:00
|
|
|
// ...and we've already loaded that message once
|
2021-11-11 23:45:47 +00:00
|
|
|
const existingMessage = getOwn(state.messagesLookup, id);
|
2019-05-31 22:42:01 +00:00
|
|
|
if (!existingMessage) {
|
2022-12-21 20:44:23 +00:00
|
|
|
return maybeUpdateSelectedMessageForDetails(
|
2023-03-20 22:23:53 +00:00
|
|
|
{ messageId: id, targetedMessageForDetails: data },
|
2022-12-21 20:44:23 +00:00
|
|
|
state
|
|
|
|
);
|
2019-05-31 22:42:01 +00:00
|
|
|
}
|
|
|
|
|
2022-04-20 23:33:38 +00:00
|
|
|
const conversationAttrs = state.conversationLookup[conversationId];
|
|
|
|
const isGroupStoryReply = isGroup(conversationAttrs) && data.storyId;
|
|
|
|
if (isGroupStoryReply) {
|
|
|
|
return state;
|
|
|
|
}
|
|
|
|
|
2023-03-29 21:58:16 +00:00
|
|
|
const toIncrement =
|
|
|
|
data.reactions?.length ||
|
|
|
|
existingMessage.editHistory?.length !== data.editHistory?.length
|
|
|
|
? 1
|
|
|
|
: 0;
|
2022-05-11 22:41:45 +00:00
|
|
|
|
2023-04-10 16:31:45 +00:00
|
|
|
const updatedMessage = {
|
|
|
|
...data,
|
|
|
|
displayLimit: existingMessage.displayLimit,
|
|
|
|
isSpoilerExpanded: existingMessage.isSpoilerExpanded,
|
|
|
|
};
|
|
|
|
|
2019-05-31 22:42:01 +00:00
|
|
|
return {
|
2022-12-21 20:44:23 +00:00
|
|
|
...maybeUpdateSelectedMessageForDetails(
|
|
|
|
{
|
|
|
|
messageId: id,
|
2023-04-10 16:31:45 +00:00
|
|
|
targetedMessageForDetails: updatedMessage,
|
2022-12-21 20:44:23 +00:00
|
|
|
},
|
|
|
|
state
|
|
|
|
),
|
2022-05-11 22:41:45 +00:00
|
|
|
messagesByConversation: {
|
|
|
|
...state.messagesByConversation,
|
|
|
|
[conversationId]: {
|
|
|
|
...existingConversation,
|
|
|
|
messageChangeCounter:
|
|
|
|
(existingConversation.messageChangeCounter || 0) + toIncrement,
|
|
|
|
},
|
|
|
|
},
|
2019-05-31 22:42:01 +00:00
|
|
|
messagesLookup: {
|
|
|
|
...state.messagesLookup,
|
2023-04-10 16:31:45 +00:00
|
|
|
[id]: updatedMessage,
|
2019-05-31 22:42:01 +00:00
|
|
|
},
|
|
|
|
};
|
|
|
|
}
|
2022-12-21 20:44:23 +00:00
|
|
|
|
|
|
|
if (action.type === MESSAGE_EXPIRED) {
|
|
|
|
return maybeUpdateSelectedMessageForDetails(
|
2023-03-20 22:23:53 +00:00
|
|
|
{ messageId: action.payload.id, targetedMessageForDetails: undefined },
|
2022-12-21 20:44:23 +00:00
|
|
|
state
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
2021-11-11 23:45:47 +00:00
|
|
|
if (action.type === 'MESSAGE_EXPANDED') {
|
|
|
|
const { id, displayLimit } = action.payload;
|
|
|
|
|
|
|
|
const existingMessage = state.messagesLookup[id];
|
|
|
|
if (!existingMessage) {
|
|
|
|
return state;
|
|
|
|
}
|
|
|
|
|
2023-04-10 16:31:45 +00:00
|
|
|
const updatedMessage = {
|
|
|
|
...existingMessage,
|
|
|
|
displayLimit,
|
|
|
|
};
|
|
|
|
|
2021-11-11 23:45:47 +00:00
|
|
|
return {
|
|
|
|
...state,
|
2023-04-10 16:31:45 +00:00
|
|
|
...maybeUpdateSelectedMessageForDetails(
|
|
|
|
{
|
|
|
|
messageId: id,
|
|
|
|
targetedMessageForDetails: updatedMessage,
|
|
|
|
},
|
|
|
|
state
|
|
|
|
),
|
2021-11-11 23:45:47 +00:00
|
|
|
messagesLookup: {
|
|
|
|
...state.messagesLookup,
|
2023-04-10 16:31:45 +00:00
|
|
|
[id]: updatedMessage,
|
|
|
|
},
|
|
|
|
};
|
|
|
|
}
|
|
|
|
if (action.type === SHOW_SPOILER) {
|
2023-05-10 00:40:19 +00:00
|
|
|
const { id, data } = action.payload;
|
2023-04-10 16:31:45 +00:00
|
|
|
|
|
|
|
const existingMessage = state.messagesLookup[id];
|
|
|
|
if (!existingMessage) {
|
|
|
|
return state;
|
|
|
|
}
|
|
|
|
|
|
|
|
const updatedMessage = {
|
|
|
|
...existingMessage,
|
2023-05-10 00:40:19 +00:00
|
|
|
isSpoilerExpanded: data,
|
2023-04-10 16:31:45 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
return {
|
|
|
|
...state,
|
|
|
|
...maybeUpdateSelectedMessageForDetails(
|
|
|
|
{
|
|
|
|
messageId: id,
|
|
|
|
targetedMessageForDetails: updatedMessage,
|
2021-11-11 23:45:47 +00:00
|
|
|
},
|
2023-04-10 16:31:45 +00:00
|
|
|
state
|
|
|
|
),
|
|
|
|
messagesLookup: {
|
|
|
|
...state.messagesLookup,
|
|
|
|
[id]: updatedMessage,
|
2021-11-11 23:45:47 +00:00
|
|
|
},
|
|
|
|
};
|
|
|
|
}
|
2023-04-10 16:31:45 +00:00
|
|
|
|
2019-05-31 22:42:01 +00:00
|
|
|
if (action.type === 'MESSAGES_RESET') {
|
|
|
|
const {
|
|
|
|
conversationId,
|
|
|
|
messages,
|
|
|
|
metrics,
|
|
|
|
scrollToMessageId,
|
2020-07-06 17:06:44 +00:00
|
|
|
unboundedFetch,
|
2019-05-31 22:42:01 +00:00
|
|
|
} = action.payload;
|
|
|
|
const { messagesByConversation, messagesLookup } = state;
|
|
|
|
|
|
|
|
const existingConversation = messagesByConversation[conversationId];
|
|
|
|
|
|
|
|
const lookup = fromPairs(messages.map(message => [message.id, message]));
|
2021-09-28 22:11:01 +00:00
|
|
|
const sorted = orderBy(
|
|
|
|
values(lookup),
|
|
|
|
['received_at', 'sent_at'],
|
|
|
|
['ASC', 'ASC']
|
|
|
|
);
|
2019-05-31 22:42:01 +00:00
|
|
|
|
2020-01-16 16:45:06 +00:00
|
|
|
let { newest, oldest } = metrics;
|
|
|
|
|
|
|
|
// If our metrics are a little out of date, we'll fix them up
|
2021-09-28 22:11:01 +00:00
|
|
|
if (sorted.length > 0) {
|
|
|
|
const first = sorted[0];
|
2020-02-03 19:32:03 +00:00
|
|
|
if (first && (!oldest || first.received_at <= oldest.received_at)) {
|
2021-01-13 16:32:18 +00:00
|
|
|
oldest = pick(first, ['id', 'received_at', 'sent_at']);
|
2020-01-16 16:45:06 +00:00
|
|
|
}
|
|
|
|
|
2021-09-28 22:11:01 +00:00
|
|
|
const last = sorted[sorted.length - 1];
|
2020-07-06 17:06:44 +00:00
|
|
|
if (
|
|
|
|
last &&
|
|
|
|
(!newest || unboundedFetch || last.received_at >= newest.received_at)
|
|
|
|
) {
|
2021-01-13 16:32:18 +00:00
|
|
|
newest = pick(last, ['id', 'received_at', 'sent_at']);
|
2020-01-16 16:45:06 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2021-09-28 18:32:54 +00:00
|
|
|
const messageIds = sorted.map(message => message.id);
|
|
|
|
|
2019-05-31 22:42:01 +00:00
|
|
|
return {
|
|
|
|
...state,
|
2022-06-23 16:12:17 +00:00
|
|
|
...(state.selectedConversationId === conversationId
|
|
|
|
? {
|
2023-03-20 22:23:53 +00:00
|
|
|
targetedMessage: scrollToMessageId,
|
|
|
|
targetedMessageCounter: state.targetedMessageCounter + 1,
|
|
|
|
targetedMessageSource: TargetedMessageSource.Reset,
|
2022-06-23 16:12:17 +00:00
|
|
|
}
|
|
|
|
: {}),
|
2019-05-31 22:42:01 +00:00
|
|
|
messagesLookup: {
|
|
|
|
...messagesLookup,
|
|
|
|
...lookup,
|
|
|
|
},
|
|
|
|
messagesByConversation: {
|
|
|
|
...messagesByConversation,
|
|
|
|
[conversationId]: {
|
2022-05-11 22:41:45 +00:00
|
|
|
messageChangeCounter: 0,
|
2019-05-31 22:42:01 +00:00
|
|
|
scrollToMessageId,
|
2019-11-07 21:36:16 +00:00
|
|
|
scrollToMessageCounter: existingConversation
|
|
|
|
? existingConversation.scrollToMessageCounter + 1
|
|
|
|
: 0,
|
2019-05-31 22:42:01 +00:00
|
|
|
messageIds,
|
2020-01-16 16:45:06 +00:00
|
|
|
metrics: {
|
|
|
|
...metrics,
|
|
|
|
newest,
|
|
|
|
oldest,
|
|
|
|
},
|
2019-05-31 22:42:01 +00:00
|
|
|
},
|
|
|
|
},
|
|
|
|
};
|
|
|
|
}
|
2022-03-11 22:31:21 +00:00
|
|
|
if (action.type === 'SET_MESSAGE_LOADING_STATE') {
|
2019-05-31 22:42:01 +00:00
|
|
|
const { payload } = action;
|
2022-03-11 22:31:21 +00:00
|
|
|
const { conversationId, messageLoadingState } = payload;
|
2019-05-31 22:42:01 +00:00
|
|
|
|
|
|
|
const { messagesByConversation } = state;
|
|
|
|
const existingConversation = messagesByConversation[conversationId];
|
|
|
|
|
|
|
|
if (!existingConversation) {
|
|
|
|
return state;
|
|
|
|
}
|
|
|
|
|
|
|
|
return {
|
|
|
|
...state,
|
|
|
|
messagesByConversation: {
|
|
|
|
...messagesByConversation,
|
|
|
|
[conversationId]: {
|
|
|
|
...existingConversation,
|
2022-03-11 22:31:21 +00:00
|
|
|
messageLoadingState,
|
2019-05-31 22:42:01 +00:00
|
|
|
},
|
|
|
|
},
|
|
|
|
};
|
|
|
|
}
|
|
|
|
if (action.type === 'SET_NEAR_BOTTOM') {
|
|
|
|
const { payload } = action;
|
|
|
|
const { conversationId, isNearBottom } = payload;
|
|
|
|
|
|
|
|
const { messagesByConversation } = state;
|
|
|
|
const existingConversation = messagesByConversation[conversationId];
|
|
|
|
|
2022-03-03 20:23:10 +00:00
|
|
|
if (
|
|
|
|
!existingConversation ||
|
|
|
|
existingConversation.isNearBottom === isNearBottom
|
|
|
|
) {
|
2019-05-31 22:42:01 +00:00
|
|
|
return state;
|
|
|
|
}
|
|
|
|
|
|
|
|
return {
|
|
|
|
...state,
|
|
|
|
messagesByConversation: {
|
|
|
|
...messagesByConversation,
|
|
|
|
[conversationId]: {
|
|
|
|
...existingConversation,
|
|
|
|
isNearBottom,
|
|
|
|
},
|
|
|
|
},
|
|
|
|
};
|
|
|
|
}
|
|
|
|
if (action.type === 'SCROLL_TO_MESSAGE') {
|
|
|
|
const { payload } = action;
|
|
|
|
const { conversationId, messageId } = payload;
|
|
|
|
|
|
|
|
const { messagesByConversation, messagesLookup } = state;
|
|
|
|
const existingConversation = messagesByConversation[conversationId];
|
|
|
|
|
|
|
|
if (!existingConversation) {
|
|
|
|
return state;
|
|
|
|
}
|
|
|
|
if (!messagesLookup[messageId]) {
|
|
|
|
return state;
|
|
|
|
}
|
|
|
|
if (!existingConversation.messageIds.includes(messageId)) {
|
|
|
|
return state;
|
|
|
|
}
|
|
|
|
|
|
|
|
return {
|
|
|
|
...state,
|
2023-03-20 22:23:53 +00:00
|
|
|
targetedMessage: messageId,
|
|
|
|
targetedMessageCounter: state.targetedMessageCounter + 1,
|
|
|
|
targetedMessageSource: TargetedMessageSource.NavigateToMessage,
|
2019-05-31 22:42:01 +00:00
|
|
|
messagesByConversation: {
|
|
|
|
...messagesByConversation,
|
|
|
|
[conversationId]: {
|
|
|
|
...existingConversation,
|
2022-03-11 22:31:21 +00:00
|
|
|
messageLoadingState: undefined,
|
2019-05-31 22:42:01 +00:00
|
|
|
scrollToMessageId: messageId,
|
|
|
|
scrollToMessageCounter:
|
|
|
|
existingConversation.scrollToMessageCounter + 1,
|
|
|
|
},
|
|
|
|
},
|
2023-07-26 22:23:32 +00:00
|
|
|
targetedConversationPanels: {
|
|
|
|
...state.targetedConversationPanels,
|
|
|
|
watermark: -1,
|
|
|
|
},
|
2019-05-31 22:42:01 +00:00
|
|
|
};
|
|
|
|
}
|
2022-12-20 17:50:23 +00:00
|
|
|
if (action.type === MESSAGE_DELETED) {
|
2019-05-31 22:42:01 +00:00
|
|
|
const { id, conversationId } = action.payload;
|
|
|
|
const { messagesByConversation, messagesLookup } = state;
|
|
|
|
|
|
|
|
const existingConversation = messagesByConversation[conversationId];
|
|
|
|
if (!existingConversation) {
|
2022-12-21 20:44:23 +00:00
|
|
|
return maybeUpdateSelectedMessageForDetails(
|
2023-03-20 22:23:53 +00:00
|
|
|
{ messageId: id, targetedMessageForDetails: undefined },
|
2022-12-21 20:44:23 +00:00
|
|
|
state
|
|
|
|
);
|
2019-05-31 22:42:01 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// Assuming that we always have contiguous groups of messages in memory, the removal
|
|
|
|
// of one message at one end of our message set be replaced with the message right
|
|
|
|
// next to it.
|
|
|
|
const oldIds = existingConversation.messageIds;
|
|
|
|
let { newest, oldest } = existingConversation.metrics;
|
|
|
|
|
|
|
|
if (oldIds.length > 1) {
|
|
|
|
const firstId = oldIds[0];
|
|
|
|
const lastId = oldIds[oldIds.length - 1];
|
|
|
|
|
|
|
|
if (oldest && oldest.id === firstId && firstId === id) {
|
|
|
|
const second = messagesLookup[oldIds[1]];
|
2021-01-13 16:32:18 +00:00
|
|
|
oldest = second
|
|
|
|
? pick(second, ['id', 'received_at', 'sent_at'])
|
|
|
|
: undefined;
|
2019-05-31 22:42:01 +00:00
|
|
|
}
|
|
|
|
if (newest && newest.id === lastId && lastId === id) {
|
|
|
|
const penultimate = messagesLookup[oldIds[oldIds.length - 2]];
|
|
|
|
newest = penultimate
|
2021-01-13 16:32:18 +00:00
|
|
|
? pick(penultimate, ['id', 'received_at', 'sent_at'])
|
2019-05-31 22:42:01 +00:00
|
|
|
: undefined;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// Removing it from our caches
|
|
|
|
const messageIds = without(existingConversation.messageIds, id);
|
|
|
|
|
2020-09-09 02:25:05 +00:00
|
|
|
let metrics;
|
|
|
|
if (messageIds.length === 0) {
|
|
|
|
metrics = {
|
2022-04-22 18:35:14 +00:00
|
|
|
totalUnseen: 0,
|
2020-09-09 02:25:05 +00:00
|
|
|
};
|
|
|
|
} else {
|
|
|
|
metrics = {
|
|
|
|
...existingConversation.metrics,
|
|
|
|
oldest,
|
|
|
|
newest,
|
|
|
|
};
|
|
|
|
}
|
|
|
|
|
2019-05-31 22:42:01 +00:00
|
|
|
return {
|
2022-12-21 20:44:23 +00:00
|
|
|
...maybeUpdateSelectedMessageForDetails(
|
2023-03-20 22:23:53 +00:00
|
|
|
{ messageId: id, targetedMessageForDetails: undefined },
|
2022-12-21 20:44:23 +00:00
|
|
|
state
|
|
|
|
),
|
2019-05-31 22:42:01 +00:00
|
|
|
messagesLookup: omit(messagesLookup, id),
|
|
|
|
messagesByConversation: {
|
|
|
|
[conversationId]: {
|
|
|
|
...existingConversation,
|
|
|
|
messageIds,
|
2020-09-09 02:25:05 +00:00
|
|
|
metrics,
|
2019-05-31 22:42:01 +00:00
|
|
|
},
|
|
|
|
},
|
|
|
|
};
|
|
|
|
}
|
2020-12-04 20:41:40 +00:00
|
|
|
|
|
|
|
if (action.type === 'REPAIR_NEWEST_MESSAGE') {
|
|
|
|
const { conversationId } = action.payload;
|
|
|
|
const { messagesByConversation, messagesLookup } = state;
|
|
|
|
|
|
|
|
const existingConversation = getOwn(messagesByConversation, conversationId);
|
|
|
|
if (!existingConversation) {
|
|
|
|
return state;
|
|
|
|
}
|
|
|
|
|
|
|
|
const { messageIds } = existingConversation;
|
|
|
|
const lastId =
|
|
|
|
messageIds && messageIds.length
|
|
|
|
? messageIds[messageIds.length - 1]
|
|
|
|
: undefined;
|
|
|
|
const last = lastId ? getOwn(messagesLookup, lastId) : undefined;
|
2021-01-13 16:32:18 +00:00
|
|
|
const newest = last
|
|
|
|
? pick(last, ['id', 'received_at', 'sent_at'])
|
|
|
|
: undefined;
|
2020-12-04 20:41:40 +00:00
|
|
|
|
|
|
|
return {
|
|
|
|
...state,
|
|
|
|
messagesByConversation: {
|
|
|
|
...messagesByConversation,
|
|
|
|
[conversationId]: {
|
|
|
|
...existingConversation,
|
|
|
|
metrics: {
|
|
|
|
...existingConversation.metrics,
|
|
|
|
newest,
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
};
|
|
|
|
}
|
|
|
|
|
|
|
|
if (action.type === 'REPAIR_OLDEST_MESSAGE') {
|
|
|
|
const { conversationId } = action.payload;
|
|
|
|
const { messagesByConversation, messagesLookup } = state;
|
|
|
|
|
|
|
|
const existingConversation = getOwn(messagesByConversation, conversationId);
|
|
|
|
if (!existingConversation) {
|
|
|
|
return state;
|
|
|
|
}
|
|
|
|
|
|
|
|
const { messageIds } = existingConversation;
|
|
|
|
const firstId = messageIds && messageIds.length ? messageIds[0] : undefined;
|
|
|
|
const first = firstId ? getOwn(messagesLookup, firstId) : undefined;
|
2021-01-13 16:32:18 +00:00
|
|
|
const oldest = first
|
|
|
|
? pick(first, ['id', 'received_at', 'sent_at'])
|
|
|
|
: undefined;
|
2020-12-04 20:41:40 +00:00
|
|
|
|
|
|
|
return {
|
|
|
|
...state,
|
|
|
|
messagesByConversation: {
|
|
|
|
...messagesByConversation,
|
|
|
|
[conversationId]: {
|
|
|
|
...existingConversation,
|
|
|
|
metrics: {
|
|
|
|
...existingConversation.metrics,
|
|
|
|
oldest,
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
};
|
|
|
|
}
|
|
|
|
|
2021-06-01 23:30:25 +00:00
|
|
|
if (action.type === 'REVIEW_GROUP_MEMBER_NAME_COLLISION') {
|
|
|
|
return {
|
|
|
|
...state,
|
|
|
|
contactSpoofingReview: {
|
|
|
|
type: ContactSpoofingType.MultipleGroupMembersWithSameTitle,
|
|
|
|
...action.payload,
|
|
|
|
},
|
|
|
|
};
|
|
|
|
}
|
|
|
|
|
2021-04-21 16:31:12 +00:00
|
|
|
if (action.type === 'REVIEW_MESSAGE_REQUEST_NAME_COLLISION') {
|
|
|
|
return {
|
|
|
|
...state,
|
2021-06-01 23:30:25 +00:00
|
|
|
contactSpoofingReview: {
|
|
|
|
type: ContactSpoofingType.DirectConversationWithSameTitle,
|
|
|
|
...action.payload,
|
|
|
|
},
|
2021-04-21 16:31:12 +00:00
|
|
|
};
|
|
|
|
}
|
|
|
|
|
2019-05-31 22:42:01 +00:00
|
|
|
if (action.type === 'MESSAGES_ADDED') {
|
2021-11-30 11:25:24 +00:00
|
|
|
const { conversationId, isActive, isJustSent, isNewMessage, messages } =
|
|
|
|
action.payload;
|
2019-05-31 22:42:01 +00:00
|
|
|
const { messagesByConversation, messagesLookup } = state;
|
|
|
|
|
|
|
|
const existingConversation = messagesByConversation[conversationId];
|
|
|
|
if (!existingConversation) {
|
|
|
|
return state;
|
|
|
|
}
|
|
|
|
|
2022-04-22 18:35:14 +00:00
|
|
|
let { newest, oldest, oldestUnseen, totalUnseen } =
|
2021-11-11 22:43:05 +00:00
|
|
|
existingConversation.metrics;
|
2019-05-31 22:42:01 +00:00
|
|
|
|
2019-08-15 14:59:56 +00:00
|
|
|
if (messages.length < 1) {
|
|
|
|
return state;
|
2019-05-31 22:42:01 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
const lookup = fromPairs(
|
|
|
|
existingConversation.messageIds.map(id => [id, messagesLookup[id]])
|
|
|
|
);
|
|
|
|
messages.forEach(message => {
|
|
|
|
lookup[message.id] = message;
|
|
|
|
});
|
|
|
|
|
2020-10-23 19:20:21 +00:00
|
|
|
const sorted = orderBy(
|
|
|
|
values(lookup),
|
|
|
|
['received_at', 'sent_at'],
|
|
|
|
['ASC', 'ASC']
|
|
|
|
);
|
2019-05-31 22:42:01 +00:00
|
|
|
const messageIds = sorted.map(message => message.id);
|
|
|
|
|
|
|
|
const first = sorted[0];
|
2019-08-15 14:59:56 +00:00
|
|
|
const last = sorted[sorted.length - 1];
|
|
|
|
|
|
|
|
if (!newest) {
|
2021-01-13 16:32:18 +00:00
|
|
|
newest = pick(first, ['id', 'received_at', 'sent_at']);
|
2019-08-15 14:59:56 +00:00
|
|
|
}
|
|
|
|
if (!oldest) {
|
2021-01-13 16:32:18 +00:00
|
|
|
oldest = pick(last, ['id', 'received_at', 'sent_at']);
|
2019-08-15 14:59:56 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
const existingTotal = existingConversation.messageIds.length;
|
|
|
|
if (isNewMessage && existingTotal > 0) {
|
|
|
|
const lastMessageId = existingConversation.messageIds[existingTotal - 1];
|
|
|
|
|
|
|
|
// If our messages in memory don't include the most recent messages, then we
|
|
|
|
// won't add new messages to our message list.
|
|
|
|
const haveLatest = newest && newest.id === lastMessageId;
|
|
|
|
if (!haveLatest) {
|
2021-11-30 11:25:24 +00:00
|
|
|
if (isJustSent) {
|
|
|
|
log.warn(
|
|
|
|
'reducer/MESSAGES_ADDED: isJustSent is true, but haveLatest is false'
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
2019-08-15 14:59:56 +00:00
|
|
|
return state;
|
|
|
|
}
|
|
|
|
}
|
2019-05-31 22:42:01 +00:00
|
|
|
|
2020-09-14 21:56:35 +00:00
|
|
|
// Update oldest and newest if we receive older/newer
|
|
|
|
// messages (or duplicated timestamps!)
|
2020-01-31 15:39:30 +00:00
|
|
|
if (first && oldest && first.received_at <= oldest.received_at) {
|
2021-01-13 16:32:18 +00:00
|
|
|
oldest = pick(first, ['id', 'received_at', 'sent_at']);
|
2019-05-31 22:42:01 +00:00
|
|
|
}
|
2020-01-31 15:39:30 +00:00
|
|
|
if (last && newest && last.received_at >= newest.received_at) {
|
2021-01-13 16:32:18 +00:00
|
|
|
newest = pick(last, ['id', 'received_at', 'sent_at']);
|
2019-05-31 22:42:01 +00:00
|
|
|
}
|
|
|
|
|
2019-08-15 14:59:56 +00:00
|
|
|
const newIds = messages.map(message => message.id);
|
2019-05-31 22:42:01 +00:00
|
|
|
const newMessageIds = difference(newIds, existingConversation.messageIds);
|
|
|
|
const { isNearBottom } = existingConversation;
|
|
|
|
|
2022-04-22 18:35:14 +00:00
|
|
|
if ((!isNearBottom || !isActive) && !oldestUnseen) {
|
2019-05-31 22:42:01 +00:00
|
|
|
const oldestId = newMessageIds.find(messageId => {
|
|
|
|
const message = lookup[messageId];
|
|
|
|
|
2021-07-29 14:29:07 +00:00
|
|
|
return message && isMessageUnread(message);
|
2019-05-31 22:42:01 +00:00
|
|
|
});
|
|
|
|
|
|
|
|
if (oldestId) {
|
2022-04-22 18:35:14 +00:00
|
|
|
oldestUnseen = pick(lookup[oldestId], [
|
2019-05-31 22:42:01 +00:00
|
|
|
'id',
|
|
|
|
'received_at',
|
2021-01-13 16:32:18 +00:00
|
|
|
'sent_at',
|
2019-05-31 22:42:01 +00:00
|
|
|
]) as MessagePointerType;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2022-04-22 18:35:14 +00:00
|
|
|
// If this is a new incoming message, we'll increment our totalUnseen count
|
|
|
|
if (isNewMessage && !isJustSent && oldestUnseen) {
|
2019-05-31 22:42:01 +00:00
|
|
|
const newUnread: number = newMessageIds.reduce((sum, messageId) => {
|
|
|
|
const message = lookup[messageId];
|
|
|
|
|
2021-07-29 14:29:07 +00:00
|
|
|
return sum + (message && isMessageUnread(message) ? 1 : 0);
|
2019-05-31 22:42:01 +00:00
|
|
|
}, 0);
|
2022-04-22 18:35:14 +00:00
|
|
|
totalUnseen = (totalUnseen || 0) + newUnread;
|
2019-05-31 22:42:01 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
return {
|
|
|
|
...state,
|
|
|
|
messagesLookup: {
|
|
|
|
...messagesLookup,
|
|
|
|
...lookup,
|
|
|
|
},
|
|
|
|
messagesByConversation: {
|
|
|
|
...messagesByConversation,
|
|
|
|
[conversationId]: {
|
|
|
|
...existingConversation,
|
|
|
|
messageIds,
|
2022-03-11 22:31:21 +00:00
|
|
|
messageLoadingState: undefined,
|
2021-11-30 11:25:24 +00:00
|
|
|
scrollToMessageId: isJustSent ? last.id : undefined,
|
2019-05-31 22:42:01 +00:00
|
|
|
metrics: {
|
|
|
|
...existingConversation.metrics,
|
|
|
|
newest,
|
|
|
|
oldest,
|
2022-04-22 18:35:14 +00:00
|
|
|
totalUnseen,
|
|
|
|
oldestUnseen,
|
2019-05-31 22:42:01 +00:00
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
};
|
|
|
|
}
|
2023-03-20 22:23:53 +00:00
|
|
|
if (action.type === 'CLEAR_TARGETED_MESSAGE') {
|
2019-05-31 22:42:01 +00:00
|
|
|
return {
|
|
|
|
...state,
|
2023-03-20 22:23:53 +00:00
|
|
|
targetedMessage: undefined,
|
|
|
|
targetedMessageCounter: 0,
|
|
|
|
targetedMessageSource: undefined,
|
2019-05-31 22:42:01 +00:00
|
|
|
};
|
|
|
|
}
|
|
|
|
if (action.type === 'CLEAR_UNREAD_METRICS') {
|
|
|
|
const { payload } = action;
|
|
|
|
const { conversationId } = payload;
|
|
|
|
const existingConversation = state.messagesByConversation[conversationId];
|
|
|
|
|
|
|
|
if (!existingConversation) {
|
|
|
|
return state;
|
|
|
|
}
|
|
|
|
|
|
|
|
return {
|
|
|
|
...state,
|
|
|
|
messagesByConversation: {
|
|
|
|
...state.messagesByConversation,
|
|
|
|
[conversationId]: {
|
|
|
|
...existingConversation,
|
|
|
|
metrics: {
|
|
|
|
...existingConversation.metrics,
|
2022-04-22 18:35:14 +00:00
|
|
|
oldestUnseen: undefined,
|
|
|
|
totalUnseen: 0,
|
2019-05-31 22:42:01 +00:00
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
};
|
2019-01-14 21:49:58 +00:00
|
|
|
}
|
2023-03-20 22:23:53 +00:00
|
|
|
if (action.type === TARGETED_CONVERSATION_CHANGED) {
|
2019-03-12 00:20:16 +00:00
|
|
|
const { payload } = action;
|
2023-01-05 00:22:36 +00:00
|
|
|
const { conversationId, messageId, switchToAssociatedView } = payload;
|
2019-03-12 00:20:16 +00:00
|
|
|
|
2023-05-19 13:28:59 +00:00
|
|
|
let conversation: ConversationType | undefined;
|
|
|
|
|
|
|
|
if (conversationId) {
|
|
|
|
conversation = getOwn(state.conversationLookup, conversationId);
|
|
|
|
if (!conversation) {
|
|
|
|
log.error(`Unknown conversation selected, id: [${conversationId}]`);
|
|
|
|
return state;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2022-06-16 19:12:50 +00:00
|
|
|
const nextState = {
|
2021-04-21 16:31:12 +00:00
|
|
|
...omit(state, 'contactSpoofingReview'),
|
2023-01-05 00:22:36 +00:00
|
|
|
selectedConversationId: conversationId,
|
2023-03-20 22:23:53 +00:00
|
|
|
targetedMessage: messageId,
|
|
|
|
targetedMessageSource: TargetedMessageSource.NavigateToMessage,
|
2019-03-12 00:20:16 +00:00
|
|
|
};
|
2022-06-16 19:12:50 +00:00
|
|
|
|
2023-05-19 13:28:59 +00:00
|
|
|
if (switchToAssociatedView && conversation) {
|
2022-06-16 19:12:50 +00:00
|
|
|
return {
|
2023-03-20 22:23:53 +00:00
|
|
|
...omit(nextState, 'composer', 'selectedMessageIds'),
|
2022-06-16 19:12:50 +00:00
|
|
|
showArchived: Boolean(conversation.isArchived),
|
|
|
|
};
|
|
|
|
}
|
|
|
|
|
|
|
|
return nextState;
|
2019-03-12 00:20:16 +00:00
|
|
|
}
|
|
|
|
if (action.type === 'SHOW_INBOX') {
|
|
|
|
return {
|
2021-02-23 20:34:28 +00:00
|
|
|
...omit(state, 'composer'),
|
2019-03-12 00:20:16 +00:00
|
|
|
showArchived: false,
|
|
|
|
};
|
|
|
|
}
|
|
|
|
if (action.type === 'SHOW_ARCHIVED_CONVERSATIONS') {
|
|
|
|
return {
|
2021-02-23 20:34:28 +00:00
|
|
|
...omit(state, 'composer'),
|
2019-03-12 00:20:16 +00:00
|
|
|
showArchived: true,
|
|
|
|
};
|
|
|
|
}
|
2019-01-14 21:49:58 +00:00
|
|
|
|
2022-12-14 18:41:04 +00:00
|
|
|
if (action.type === PUSH_PANEL) {
|
2023-07-26 22:23:32 +00:00
|
|
|
const currentStack = state.targetedConversationPanels.stack;
|
|
|
|
const watermark = Math.min(
|
|
|
|
state.targetedConversationPanels.watermark + 1,
|
|
|
|
currentStack.length
|
|
|
|
);
|
|
|
|
const stack = [...currentStack.slice(0, watermark), action.payload];
|
|
|
|
|
|
|
|
const targetedConversationPanels = {
|
|
|
|
isAnimating: false,
|
|
|
|
direction: 'push' as const,
|
|
|
|
stack,
|
|
|
|
watermark,
|
|
|
|
};
|
|
|
|
|
2022-12-21 20:44:23 +00:00
|
|
|
if (action.payload.type === PanelType.MessageDetails) {
|
|
|
|
return {
|
|
|
|
...state,
|
2023-07-26 22:23:32 +00:00
|
|
|
targetedConversationPanels,
|
2023-03-20 22:23:53 +00:00
|
|
|
targetedMessageForDetails: action.payload.args.message,
|
2022-12-21 20:44:23 +00:00
|
|
|
};
|
|
|
|
}
|
|
|
|
|
2022-12-14 18:41:04 +00:00
|
|
|
return {
|
|
|
|
...state,
|
2023-07-26 22:23:32 +00:00
|
|
|
targetedConversationPanels,
|
2022-12-14 18:41:04 +00:00
|
|
|
};
|
|
|
|
}
|
|
|
|
|
|
|
|
if (action.type === POP_PANEL) {
|
2023-07-26 22:23:32 +00:00
|
|
|
if (state.targetedConversationPanels.watermark === -1) {
|
|
|
|
return state;
|
|
|
|
}
|
|
|
|
|
|
|
|
const poppedPanel =
|
|
|
|
state.targetedConversationPanels.stack[
|
|
|
|
state.targetedConversationPanels.watermark
|
|
|
|
];
|
2022-12-21 20:44:23 +00:00
|
|
|
|
2023-07-26 22:23:32 +00:00
|
|
|
if (!poppedPanel) {
|
2022-12-21 20:44:23 +00:00
|
|
|
return state;
|
|
|
|
}
|
|
|
|
|
2023-07-26 22:23:32 +00:00
|
|
|
const watermark = Math.max(
|
|
|
|
state.targetedConversationPanels.watermark - 1,
|
|
|
|
-1
|
|
|
|
);
|
|
|
|
|
|
|
|
const targetedConversationPanels = {
|
|
|
|
isAnimating: false,
|
|
|
|
direction: 'pop' as const,
|
|
|
|
stack: state.targetedConversationPanels.stack,
|
|
|
|
watermark,
|
|
|
|
};
|
|
|
|
|
|
|
|
if (poppedPanel.type === PanelType.MessageDetails) {
|
2022-12-21 20:44:23 +00:00
|
|
|
return {
|
|
|
|
...state,
|
2023-07-26 22:23:32 +00:00
|
|
|
targetedConversationPanels,
|
2023-03-20 22:23:53 +00:00
|
|
|
targetedMessageForDetails: undefined,
|
2022-12-21 20:44:23 +00:00
|
|
|
};
|
|
|
|
}
|
2022-12-14 18:41:04 +00:00
|
|
|
|
2021-01-29 21:19:24 +00:00
|
|
|
return {
|
|
|
|
...state,
|
2023-07-26 22:23:32 +00:00
|
|
|
targetedConversationPanels,
|
|
|
|
};
|
|
|
|
}
|
|
|
|
|
|
|
|
if (action.type === PANEL_ANIMATION_STARTED) {
|
|
|
|
return {
|
|
|
|
...state,
|
|
|
|
targetedConversationPanels: {
|
|
|
|
...state.targetedConversationPanels,
|
|
|
|
isAnimating: true,
|
|
|
|
},
|
|
|
|
};
|
|
|
|
}
|
|
|
|
|
|
|
|
if (action.type === PANEL_ANIMATION_DONE) {
|
|
|
|
return {
|
|
|
|
...state,
|
|
|
|
targetedConversationPanels: {
|
|
|
|
...state.targetedConversationPanels,
|
|
|
|
isAnimating: false,
|
|
|
|
},
|
2021-01-29 21:19:24 +00:00
|
|
|
};
|
|
|
|
}
|
|
|
|
|
|
|
|
if (action.type === 'SET_RECENT_MEDIA_ITEMS') {
|
|
|
|
const { id, recentMediaItems } = action.payload;
|
|
|
|
const { conversationLookup } = state;
|
|
|
|
|
|
|
|
const conversationData = conversationLookup[id];
|
|
|
|
|
|
|
|
if (!conversationData) {
|
|
|
|
return state;
|
|
|
|
}
|
|
|
|
|
|
|
|
const data = {
|
|
|
|
...conversationData,
|
|
|
|
recentMediaItems,
|
|
|
|
};
|
|
|
|
|
|
|
|
return {
|
|
|
|
...state,
|
|
|
|
conversationLookup: {
|
|
|
|
...conversationLookup,
|
|
|
|
[id]: data,
|
|
|
|
},
|
|
|
|
...updateConversationLookups(data, undefined, state),
|
|
|
|
};
|
|
|
|
}
|
|
|
|
|
2021-02-23 20:34:28 +00:00
|
|
|
if (action.type === 'START_COMPOSING') {
|
2021-03-03 20:09:58 +00:00
|
|
|
if (state.composer?.step === ComposerStep.StartDirectConversation) {
|
2021-02-23 20:34:28 +00:00
|
|
|
return state;
|
|
|
|
}
|
|
|
|
|
|
|
|
return {
|
|
|
|
...state,
|
|
|
|
showArchived: false,
|
|
|
|
composer: {
|
2021-03-03 20:09:58 +00:00
|
|
|
step: ComposerStep.StartDirectConversation,
|
2021-04-20 23:16:49 +00:00
|
|
|
searchTerm: '',
|
2022-04-05 00:38:22 +00:00
|
|
|
uuidFetchState: {},
|
2021-03-03 20:09:58 +00:00
|
|
|
},
|
|
|
|
};
|
|
|
|
}
|
|
|
|
|
|
|
|
if (action.type === 'SHOW_CHOOSE_GROUP_MEMBERS') {
|
2022-12-22 00:07:02 +00:00
|
|
|
let selectedConversationIds: ReadonlyArray<string>;
|
2021-03-03 20:09:58 +00:00
|
|
|
let recommendedGroupSizeModalState: OneTimeModalState;
|
|
|
|
let maximumGroupSizeModalState: OneTimeModalState;
|
|
|
|
let groupName: string;
|
2021-09-24 00:49:05 +00:00
|
|
|
let groupAvatar: undefined | Uint8Array;
|
2022-11-16 20:18:02 +00:00
|
|
|
let groupExpireTimer: DurationInSeconds;
|
2021-08-06 00:17:05 +00:00
|
|
|
let userAvatarData = getDefaultAvatars(true);
|
2021-03-03 20:09:58 +00:00
|
|
|
|
|
|
|
switch (state.composer?.step) {
|
|
|
|
case ComposerStep.ChooseGroupMembers:
|
|
|
|
return state;
|
|
|
|
case ComposerStep.SetGroupMetadata:
|
|
|
|
({
|
|
|
|
selectedConversationIds,
|
|
|
|
recommendedGroupSizeModalState,
|
|
|
|
maximumGroupSizeModalState,
|
|
|
|
groupName,
|
|
|
|
groupAvatar,
|
2021-06-25 23:52:56 +00:00
|
|
|
groupExpireTimer,
|
2021-08-06 00:17:05 +00:00
|
|
|
userAvatarData,
|
2021-03-03 20:09:58 +00:00
|
|
|
} = state.composer);
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
selectedConversationIds = [];
|
|
|
|
recommendedGroupSizeModalState = OneTimeModalState.NeverShown;
|
|
|
|
maximumGroupSizeModalState = OneTimeModalState.NeverShown;
|
|
|
|
groupName = '';
|
2021-06-25 23:52:56 +00:00
|
|
|
groupExpireTimer = universalExpireTimer.get();
|
2021-03-03 20:09:58 +00:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
return {
|
|
|
|
...state,
|
|
|
|
showArchived: false,
|
|
|
|
composer: {
|
|
|
|
step: ComposerStep.ChooseGroupMembers,
|
2021-04-20 23:16:49 +00:00
|
|
|
searchTerm: '',
|
2022-04-05 00:38:22 +00:00
|
|
|
uuidFetchState: {},
|
2021-03-03 20:09:58 +00:00
|
|
|
selectedConversationIds,
|
|
|
|
recommendedGroupSizeModalState,
|
|
|
|
maximumGroupSizeModalState,
|
|
|
|
groupName,
|
|
|
|
groupAvatar,
|
2021-06-25 23:52:56 +00:00
|
|
|
groupExpireTimer,
|
2021-08-06 00:17:05 +00:00
|
|
|
userAvatarData,
|
2021-02-23 20:34:28 +00:00
|
|
|
},
|
|
|
|
};
|
|
|
|
}
|
|
|
|
|
2021-03-03 20:09:58 +00:00
|
|
|
if (action.type === 'START_SETTING_GROUP_METADATA') {
|
|
|
|
const { composer } = state;
|
|
|
|
|
|
|
|
switch (composer?.step) {
|
|
|
|
case ComposerStep.ChooseGroupMembers:
|
|
|
|
return {
|
|
|
|
...state,
|
|
|
|
showArchived: false,
|
|
|
|
composer: {
|
|
|
|
step: ComposerStep.SetGroupMetadata,
|
2021-08-16 14:33:27 +00:00
|
|
|
isEditingAvatar: false,
|
2021-03-03 20:09:58 +00:00
|
|
|
isCreating: false,
|
|
|
|
hasError: false,
|
|
|
|
...pick(composer, [
|
|
|
|
'groupAvatar',
|
|
|
|
'groupName',
|
2021-06-25 23:52:56 +00:00
|
|
|
'groupExpireTimer',
|
2021-03-03 20:09:58 +00:00
|
|
|
'maximumGroupSizeModalState',
|
|
|
|
'recommendedGroupSizeModalState',
|
|
|
|
'selectedConversationIds',
|
2021-08-06 00:17:05 +00:00
|
|
|
'userAvatarData',
|
2021-03-03 20:09:58 +00:00
|
|
|
]),
|
|
|
|
},
|
|
|
|
};
|
|
|
|
case ComposerStep.SetGroupMetadata:
|
|
|
|
return state;
|
|
|
|
default:
|
2022-09-15 19:17:15 +00:00
|
|
|
assertDev(
|
2021-03-03 20:09:58 +00:00
|
|
|
false,
|
|
|
|
'Cannot transition to setting group metadata from this state'
|
|
|
|
);
|
|
|
|
return state;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (action.type === 'SET_COMPOSE_GROUP_AVATAR') {
|
|
|
|
const { composer } = state;
|
|
|
|
|
|
|
|
switch (composer?.step) {
|
|
|
|
case ComposerStep.ChooseGroupMembers:
|
|
|
|
case ComposerStep.SetGroupMetadata:
|
|
|
|
return {
|
|
|
|
...state,
|
|
|
|
composer: {
|
|
|
|
...composer,
|
|
|
|
groupAvatar: action.payload.groupAvatar,
|
|
|
|
},
|
|
|
|
};
|
|
|
|
default:
|
2022-09-15 19:17:15 +00:00
|
|
|
assertDev(
|
|
|
|
false,
|
|
|
|
'Setting compose group avatar at this step is a no-op'
|
|
|
|
);
|
2021-03-03 20:09:58 +00:00
|
|
|
return state;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (action.type === 'SET_COMPOSE_GROUP_NAME') {
|
|
|
|
const { composer } = state;
|
|
|
|
|
|
|
|
switch (composer?.step) {
|
|
|
|
case ComposerStep.ChooseGroupMembers:
|
|
|
|
case ComposerStep.SetGroupMetadata:
|
|
|
|
return {
|
|
|
|
...state,
|
|
|
|
composer: {
|
|
|
|
...composer,
|
|
|
|
groupName: action.payload.groupName,
|
|
|
|
},
|
|
|
|
};
|
|
|
|
default:
|
2022-09-15 19:17:15 +00:00
|
|
|
assertDev(false, 'Setting compose group name at this step is a no-op');
|
2021-03-03 20:09:58 +00:00
|
|
|
return state;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2021-06-25 23:52:56 +00:00
|
|
|
if (action.type === 'SET_COMPOSE_GROUP_EXPIRE_TIMER') {
|
|
|
|
const { composer } = state;
|
|
|
|
|
|
|
|
switch (composer?.step) {
|
|
|
|
case ComposerStep.ChooseGroupMembers:
|
|
|
|
case ComposerStep.SetGroupMetadata:
|
|
|
|
return {
|
|
|
|
...state,
|
|
|
|
composer: {
|
|
|
|
...composer,
|
|
|
|
groupExpireTimer: action.payload.groupExpireTimer,
|
|
|
|
},
|
|
|
|
};
|
|
|
|
default:
|
2022-09-15 19:17:15 +00:00
|
|
|
assertDev(false, 'Setting compose group name at this step is a no-op');
|
2021-06-25 23:52:56 +00:00
|
|
|
return state;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2021-02-23 20:34:28 +00:00
|
|
|
if (action.type === 'SET_COMPOSE_SEARCH_TERM') {
|
|
|
|
const { composer } = state;
|
|
|
|
if (!composer) {
|
2022-09-15 19:17:15 +00:00
|
|
|
assertDev(
|
2021-02-23 20:34:28 +00:00
|
|
|
false,
|
|
|
|
'Setting compose search term with the composer closed is a no-op'
|
|
|
|
);
|
|
|
|
return state;
|
|
|
|
}
|
2021-11-12 01:17:29 +00:00
|
|
|
if (
|
|
|
|
composer.step !== ComposerStep.StartDirectConversation &&
|
|
|
|
composer.step !== ComposerStep.ChooseGroupMembers
|
|
|
|
) {
|
2022-09-15 19:17:15 +00:00
|
|
|
assertDev(
|
2021-11-12 01:17:29 +00:00
|
|
|
false,
|
|
|
|
`Setting compose search term at step ${composer.step} is a no-op`
|
|
|
|
);
|
2021-03-03 20:09:58 +00:00
|
|
|
return state;
|
|
|
|
}
|
2021-02-23 20:34:28 +00:00
|
|
|
|
|
|
|
return {
|
|
|
|
...state,
|
|
|
|
composer: {
|
|
|
|
...composer,
|
2021-04-20 23:16:49 +00:00
|
|
|
searchTerm: action.payload.searchTerm,
|
2021-02-23 20:34:28 +00:00
|
|
|
},
|
|
|
|
};
|
|
|
|
}
|
|
|
|
|
2022-04-05 00:38:22 +00:00
|
|
|
if (action.type === 'SET_IS_FETCHING_UUID') {
|
2021-11-12 01:17:29 +00:00
|
|
|
const { composer } = state;
|
|
|
|
if (!composer) {
|
2022-09-15 19:17:15 +00:00
|
|
|
assertDev(
|
2021-11-12 01:17:29 +00:00
|
|
|
false,
|
2022-04-05 00:38:22 +00:00
|
|
|
'Setting compose uuid fetch state with the composer closed is a no-op'
|
2021-11-12 01:17:29 +00:00
|
|
|
);
|
|
|
|
return state;
|
|
|
|
}
|
2022-04-05 00:38:22 +00:00
|
|
|
if (
|
|
|
|
composer.step !== ComposerStep.StartDirectConversation &&
|
|
|
|
composer.step !== ComposerStep.ChooseGroupMembers
|
|
|
|
) {
|
2022-09-15 19:17:15 +00:00
|
|
|
assertDev(
|
|
|
|
false,
|
|
|
|
'Setting compose uuid fetch state at this step is a no-op'
|
|
|
|
);
|
2021-11-12 01:17:29 +00:00
|
|
|
return state;
|
|
|
|
}
|
2022-04-05 00:38:22 +00:00
|
|
|
const { identifier, isFetching } = action.payload;
|
|
|
|
|
|
|
|
const { uuidFetchState } = composer;
|
2021-11-12 01:17:29 +00:00
|
|
|
|
|
|
|
return {
|
|
|
|
...state,
|
|
|
|
composer: {
|
|
|
|
...composer,
|
2022-04-05 00:38:22 +00:00
|
|
|
uuidFetchState: isFetching
|
|
|
|
? {
|
|
|
|
...composer.uuidFetchState,
|
|
|
|
[identifier]: isFetching,
|
|
|
|
}
|
|
|
|
: omit(uuidFetchState, identifier),
|
2021-11-12 01:17:29 +00:00
|
|
|
},
|
|
|
|
};
|
|
|
|
}
|
|
|
|
|
2021-08-06 00:17:05 +00:00
|
|
|
if (action.type === COMPOSE_TOGGLE_EDITING_AVATAR) {
|
|
|
|
const { composer } = state;
|
|
|
|
|
|
|
|
switch (composer?.step) {
|
|
|
|
case ComposerStep.SetGroupMetadata:
|
|
|
|
return {
|
|
|
|
...state,
|
|
|
|
composer: {
|
|
|
|
...composer,
|
2021-08-16 14:33:27 +00:00
|
|
|
isEditingAvatar: !composer.isEditingAvatar,
|
2021-08-06 00:17:05 +00:00
|
|
|
},
|
|
|
|
};
|
|
|
|
default:
|
2022-09-15 19:17:15 +00:00
|
|
|
assertDev(false, 'Setting editing avatar at this step is a no-op');
|
2021-08-06 00:17:05 +00:00
|
|
|
return state;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (action.type === COMPOSE_ADD_AVATAR) {
|
|
|
|
const { payload } = action;
|
|
|
|
const { composer } = state;
|
|
|
|
|
|
|
|
switch (composer?.step) {
|
|
|
|
case ComposerStep.ChooseGroupMembers:
|
|
|
|
case ComposerStep.SetGroupMetadata:
|
|
|
|
return {
|
|
|
|
...state,
|
|
|
|
composer: {
|
|
|
|
...composer,
|
|
|
|
userAvatarData: [
|
|
|
|
{
|
|
|
|
...payload,
|
|
|
|
id: getNextAvatarId(composer.userAvatarData),
|
|
|
|
},
|
|
|
|
...composer.userAvatarData,
|
|
|
|
],
|
|
|
|
},
|
|
|
|
};
|
|
|
|
default:
|
2022-09-15 19:17:15 +00:00
|
|
|
assertDev(false, 'Adding an avatar at this step is a no-op');
|
2021-08-06 00:17:05 +00:00
|
|
|
return state;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (action.type === COMPOSE_REMOVE_AVATAR) {
|
|
|
|
const { payload } = action;
|
|
|
|
const { composer } = state;
|
|
|
|
|
|
|
|
switch (composer?.step) {
|
|
|
|
case ComposerStep.ChooseGroupMembers:
|
|
|
|
case ComposerStep.SetGroupMetadata:
|
|
|
|
return {
|
|
|
|
...state,
|
|
|
|
composer: {
|
|
|
|
...composer,
|
|
|
|
userAvatarData: filterAvatarData(composer.userAvatarData, payload),
|
|
|
|
},
|
|
|
|
};
|
|
|
|
default:
|
2022-09-15 19:17:15 +00:00
|
|
|
assertDev(false, 'Removing an avatar at this step is a no-op');
|
2021-08-06 00:17:05 +00:00
|
|
|
return state;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (action.type === COMPOSE_REPLACE_AVATAR) {
|
|
|
|
const { curr, prev } = action.payload;
|
|
|
|
const { composer } = state;
|
|
|
|
|
|
|
|
switch (composer?.step) {
|
|
|
|
case ComposerStep.ChooseGroupMembers:
|
|
|
|
case ComposerStep.SetGroupMetadata:
|
|
|
|
return {
|
|
|
|
...state,
|
|
|
|
composer: {
|
|
|
|
...composer,
|
|
|
|
userAvatarData: [
|
|
|
|
{
|
|
|
|
...curr,
|
|
|
|
id: prev?.id ?? getNextAvatarId(composer.userAvatarData),
|
|
|
|
},
|
|
|
|
...(prev
|
|
|
|
? filterAvatarData(composer.userAvatarData, prev)
|
|
|
|
: composer.userAvatarData),
|
|
|
|
],
|
|
|
|
},
|
|
|
|
};
|
|
|
|
default:
|
2022-09-15 19:17:15 +00:00
|
|
|
assertDev(false, 'Replacing an avatar at this step is a no-op');
|
2021-08-06 00:17:05 +00:00
|
|
|
return state;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2021-03-03 20:09:58 +00:00
|
|
|
if (action.type === 'TOGGLE_CONVERSATION_IN_CHOOSE_MEMBERS') {
|
|
|
|
const { composer } = state;
|
|
|
|
if (composer?.step !== ComposerStep.ChooseGroupMembers) {
|
2022-09-15 19:17:15 +00:00
|
|
|
assertDev(
|
2021-03-03 20:09:58 +00:00
|
|
|
false,
|
|
|
|
'Toggling conversation members is a no-op in this composer step'
|
|
|
|
);
|
|
|
|
return state;
|
|
|
|
}
|
|
|
|
|
|
|
|
return {
|
|
|
|
...state,
|
|
|
|
composer: {
|
|
|
|
...composer,
|
2021-03-11 21:29:31 +00:00
|
|
|
...toggleSelectedContactForGroupAddition(
|
|
|
|
action.payload.conversationId,
|
|
|
|
{
|
|
|
|
maxGroupSize: action.payload.maxGroupSize,
|
|
|
|
maxRecommendedGroupSize: action.payload.maxRecommendedGroupSize,
|
|
|
|
maximumGroupSizeModalState: composer.maximumGroupSizeModalState,
|
|
|
|
// We say you're already in the group, even though it hasn't been created yet.
|
|
|
|
numberOfContactsAlreadyInGroup: 1,
|
|
|
|
recommendedGroupSizeModalState:
|
|
|
|
composer.recommendedGroupSizeModalState,
|
|
|
|
selectedConversationIds: composer.selectedConversationIds,
|
|
|
|
}
|
|
|
|
),
|
2021-03-03 20:09:58 +00:00
|
|
|
},
|
|
|
|
};
|
|
|
|
}
|
|
|
|
|
2021-05-28 16:15:17 +00:00
|
|
|
if (action.type === COLORS_CHANGED) {
|
|
|
|
const { conversationLookup } = state;
|
|
|
|
const { conversationColor, customColorData } = action.payload;
|
|
|
|
|
|
|
|
const nextState = {
|
|
|
|
...state,
|
|
|
|
};
|
|
|
|
|
|
|
|
Object.keys(conversationLookup).forEach(id => {
|
|
|
|
const existing = conversationLookup[id];
|
|
|
|
const added = {
|
|
|
|
...existing,
|
|
|
|
conversationColor,
|
|
|
|
customColor: customColorData?.value,
|
|
|
|
customColorId: customColorData?.id,
|
|
|
|
};
|
|
|
|
|
|
|
|
Object.assign(
|
|
|
|
nextState,
|
|
|
|
updateConversationLookups(added, existing, nextState),
|
|
|
|
{
|
|
|
|
conversationLookup: {
|
|
|
|
...nextState.conversationLookup,
|
|
|
|
[id]: added,
|
|
|
|
},
|
|
|
|
}
|
|
|
|
);
|
|
|
|
});
|
|
|
|
|
|
|
|
return nextState;
|
|
|
|
}
|
|
|
|
|
2021-06-03 21:34:36 +00:00
|
|
|
if (action.type === COLOR_SELECTED) {
|
|
|
|
const { conversationLookup } = state;
|
2021-11-11 22:43:05 +00:00
|
|
|
const { conversationId, conversationColor, customColorData } =
|
|
|
|
action.payload;
|
2021-06-03 21:34:36 +00:00
|
|
|
|
|
|
|
const existing = conversationLookup[conversationId];
|
|
|
|
if (!existing) {
|
|
|
|
return state;
|
|
|
|
}
|
|
|
|
|
|
|
|
const changed = {
|
|
|
|
...existing,
|
|
|
|
conversationColor,
|
|
|
|
customColor: customColorData?.value,
|
|
|
|
customColorId: customColorData?.id,
|
|
|
|
};
|
|
|
|
|
|
|
|
return {
|
|
|
|
...state,
|
|
|
|
conversationLookup: {
|
|
|
|
...conversationLookup,
|
|
|
|
[conversationId]: changed,
|
|
|
|
},
|
|
|
|
...updateConversationLookups(changed, existing, state),
|
|
|
|
};
|
|
|
|
}
|
|
|
|
|
2021-05-28 16:15:17 +00:00
|
|
|
if (action.type === CUSTOM_COLOR_REMOVED) {
|
|
|
|
const { conversationLookup } = state;
|
2021-08-25 00:15:12 +00:00
|
|
|
const { colorId } = action.payload;
|
2021-05-28 16:15:17 +00:00
|
|
|
|
|
|
|
const nextState = {
|
|
|
|
...state,
|
|
|
|
};
|
|
|
|
|
|
|
|
Object.keys(conversationLookup).forEach(id => {
|
|
|
|
const existing = conversationLookup[id];
|
|
|
|
|
|
|
|
if (existing.customColorId !== colorId) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2021-06-02 21:05:09 +00:00
|
|
|
const changed = {
|
|
|
|
...existing,
|
2021-08-25 00:15:12 +00:00
|
|
|
conversationColor: undefined,
|
|
|
|
customColor: undefined,
|
|
|
|
customColorId: undefined,
|
2021-06-02 21:05:09 +00:00
|
|
|
};
|
2021-05-28 16:15:17 +00:00
|
|
|
|
|
|
|
Object.assign(
|
|
|
|
nextState,
|
|
|
|
updateConversationLookups(changed, existing, nextState),
|
|
|
|
{
|
|
|
|
conversationLookup: {
|
|
|
|
...nextState.conversationLookup,
|
|
|
|
[id]: changed,
|
|
|
|
},
|
|
|
|
}
|
|
|
|
);
|
|
|
|
});
|
|
|
|
|
|
|
|
return nextState;
|
|
|
|
}
|
|
|
|
|
2021-08-06 00:17:05 +00:00
|
|
|
if (action.type === REPLACE_AVATARS) {
|
|
|
|
const { conversationLookup } = state;
|
|
|
|
const { conversationId, avatars } = action.payload;
|
|
|
|
|
|
|
|
const conversation = conversationLookup[conversationId];
|
|
|
|
if (!conversation) {
|
|
|
|
return state;
|
|
|
|
}
|
|
|
|
|
|
|
|
const changed = {
|
|
|
|
...conversation,
|
|
|
|
avatars,
|
|
|
|
};
|
|
|
|
|
|
|
|
return {
|
|
|
|
...state,
|
|
|
|
conversationLookup: {
|
|
|
|
...conversationLookup,
|
|
|
|
[conversationId]: changed,
|
|
|
|
},
|
|
|
|
...updateConversationLookups(changed, conversation, state),
|
|
|
|
};
|
|
|
|
}
|
|
|
|
|
2023-08-09 00:53:06 +00:00
|
|
|
if (
|
|
|
|
action.type === CHANGE_NAV_TAB &&
|
|
|
|
action.payload.selectedNavTab === NavTab.Chats
|
|
|
|
) {
|
|
|
|
const { messagesByConversation, selectedConversationId } = state;
|
|
|
|
if (selectedConversationId == null) {
|
|
|
|
return state;
|
|
|
|
}
|
|
|
|
|
|
|
|
const existingConversation = messagesByConversation[selectedConversationId];
|
|
|
|
if (existingConversation == null) {
|
|
|
|
return state;
|
|
|
|
}
|
|
|
|
|
|
|
|
return {
|
|
|
|
...state,
|
|
|
|
messagesByConversation: {
|
|
|
|
...messagesByConversation,
|
|
|
|
[selectedConversationId]: {
|
|
|
|
...existingConversation,
|
|
|
|
isNearBottom: true,
|
|
|
|
},
|
|
|
|
},
|
|
|
|
};
|
|
|
|
}
|
|
|
|
|
2019-01-14 21:49:58 +00:00
|
|
|
return state;
|
|
|
|
}
|