2021-01-06 15:41:43 +00:00
|
|
|
// Copyright 2019-2021 Signal Messenger, LLC
|
2020-10-30 20:34:04 +00:00
|
|
|
// SPDX-License-Identifier: AGPL-3.0-only
|
|
|
|
|
2020-09-14 21:56:35 +00:00
|
|
|
/* eslint-disable camelcase */
|
2020-12-09 23:21:34 +00:00
|
|
|
import { ThunkAction } from 'redux-thunk';
|
2019-05-31 22:42:01 +00:00
|
|
|
import {
|
|
|
|
difference,
|
|
|
|
fromPairs,
|
|
|
|
intersection,
|
|
|
|
omit,
|
|
|
|
orderBy,
|
|
|
|
pick,
|
|
|
|
uniq,
|
|
|
|
values,
|
|
|
|
without,
|
|
|
|
} from 'lodash';
|
2020-12-04 20:41:40 +00:00
|
|
|
|
2020-12-09 23:21:34 +00:00
|
|
|
import { 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';
|
2021-08-06 00:17:05 +00:00
|
|
|
import { assert, strictAssert } from '../../util/assert';
|
2021-06-25 23:52:56 +00:00
|
|
|
import * as universalExpireTimer from '../../util/universalExpireTimer';
|
2019-01-14 21:49:58 +00:00
|
|
|
import { trigger } from '../../shims/events';
|
2021-07-19 19:26:06 +00:00
|
|
|
import {
|
|
|
|
TOGGLE_PROFILE_EDITOR_ERROR,
|
|
|
|
ToggleProfileEditorErrorActionType,
|
|
|
|
} from './globalModals';
|
2021-06-17 17:15:10 +00:00
|
|
|
|
2021-05-28 16:15:17 +00:00
|
|
|
import {
|
|
|
|
AvatarColorType,
|
|
|
|
ConversationColorType,
|
|
|
|
CustomColorType,
|
|
|
|
} from '../../types/Colors';
|
2021-06-17 17:15:10 +00:00
|
|
|
import {
|
|
|
|
LastMessageStatus,
|
|
|
|
ConversationAttributesType,
|
|
|
|
MessageAttributesType,
|
|
|
|
} from '../../model-types.d';
|
2020-11-03 01:19:52 +00:00
|
|
|
import { BodyRangeType } from '../../types/Util';
|
2021-06-17 17:15:10 +00:00
|
|
|
import { CallMode } from '../../types/Calling';
|
2021-08-23 23:14:53 +00:00
|
|
|
import { MediaItemType } from '../../types/MediaItem';
|
2021-03-03 20:09:58 +00:00
|
|
|
import {
|
|
|
|
getGroupSizeRecommendedLimit,
|
|
|
|
getGroupSizeHardLimit,
|
|
|
|
} from '../../groups/limits';
|
2021-08-31 20:58:39 +00:00
|
|
|
import { getMessagesById } from '../../messages/getMessagesById';
|
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-06-01 23:30:25 +00:00
|
|
|
import { GroupNameCollisionsWithIdsByTitle } from '../../util/groupMemberNameCollisions';
|
|
|
|
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 {
|
|
|
|
getMe,
|
|
|
|
getMessageIdsPendingBecauseOfVerification,
|
|
|
|
} from '../selectors/conversations';
|
2021-08-06 00:17:05 +00:00
|
|
|
import { AvatarDataType, getDefaultAvatars } from '../../types/Avatar';
|
|
|
|
import { getAvatarData } from '../../util/getAvatarData';
|
|
|
|
import { isSameAvatarData } from '../../util/isSameAvatarData';
|
2019-01-14 21:49:58 +00:00
|
|
|
|
2021-06-17 17:15:10 +00:00
|
|
|
import { NoopActionType } from './noop';
|
|
|
|
|
2019-01-14 21:49:58 +00:00
|
|
|
// State
|
|
|
|
|
2020-02-06 19:52:05 +00:00
|
|
|
export type DBConversationType = {
|
|
|
|
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;
|
|
|
|
};
|
2020-09-24 20:57:54 +00:00
|
|
|
|
2021-06-17 17:15:10 +00:00
|
|
|
export const InteractionModes = ['mouse', 'keyboard'] as const;
|
|
|
|
export type InteractionModeType = typeof InteractionModes[number];
|
2020-09-24 20:57:54 +00:00
|
|
|
|
2021-06-17 17:15:10 +00:00
|
|
|
export type MessageType = MessageAttributesType & {
|
|
|
|
interactionType?: InteractionModeType;
|
|
|
|
};
|
|
|
|
|
|
|
|
export const ConversationTypes = ['direct', 'group'] as const;
|
|
|
|
export type ConversationTypeType = typeof ConversationTypes[number];
|
2020-09-24 20:57:54 +00:00
|
|
|
|
2019-01-14 21:49:58 +00:00
|
|
|
export type ConversationType = {
|
|
|
|
id: string;
|
2020-06-26 00:08:58 +00:00
|
|
|
uuid?: string;
|
2020-07-24 01:35:32 +00:00
|
|
|
e164?: string;
|
2019-01-14 21:49:58 +00:00
|
|
|
name?: string;
|
2021-07-19 19:26:06 +00:00
|
|
|
familyName?: string;
|
2020-07-29 23:20:05 +00:00
|
|
|
firstName?: string;
|
2020-05-27 21:37:06 +00:00
|
|
|
profileName?: string;
|
2021-01-26 01:01:19 +00:00
|
|
|
about?: string;
|
2021-07-19 19:26:06 +00:00
|
|
|
aboutText?: string;
|
|
|
|
aboutEmoji?: string;
|
2021-08-06 00:17:05 +00:00
|
|
|
avatars?: Array<AvatarDataType>;
|
2020-05-27 21:37:06 +00:00
|
|
|
avatarPath?: string;
|
2021-07-19 19:26:06 +00:00
|
|
|
avatarHash?: string;
|
2021-04-30 19:40:25 +00:00
|
|
|
unblurredAvatarPath?: string;
|
2020-11-11 17:36:05 +00:00
|
|
|
areWeAdmin?: boolean;
|
2020-10-26 14:39:45 +00:00
|
|
|
areWePending?: boolean;
|
2021-01-29 22:16:48 +00:00
|
|
|
areWePendingApproval?: boolean;
|
2020-10-30 17:52:21 +00:00
|
|
|
canChangeTimer?: boolean;
|
2021-01-29 21:19:24 +00:00
|
|
|
canEditGroupInfo?: boolean;
|
2021-05-28 16:15:17 +00:00
|
|
|
color?: AvatarColorType;
|
|
|
|
conversationColor?: ConversationColorType;
|
|
|
|
customColor?: CustomColorType;
|
|
|
|
customColorId?: string;
|
2021-02-23 20:34:28 +00:00
|
|
|
discoveredUnregisteredAt?: number;
|
2020-05-27 21:37:06 +00:00
|
|
|
isArchived?: boolean;
|
|
|
|
isBlocked?: boolean;
|
2020-12-01 16:42:35 +00:00
|
|
|
isGroupV1AndDisabled?: boolean;
|
2021-03-03 20:09:58 +00:00
|
|
|
isGroupV2Capable?: boolean;
|
2020-09-29 22:07:03 +00:00
|
|
|
isPinned?: boolean;
|
2020-12-08 19:37:04 +00:00
|
|
|
isUntrusted?: boolean;
|
2020-06-26 00:08:58 +00:00
|
|
|
isVerified?: boolean;
|
2019-01-14 21:49:58 +00:00
|
|
|
activeAt?: number;
|
2020-07-24 01:35:32 +00:00
|
|
|
timestamp?: number;
|
|
|
|
inboxPosition?: number;
|
2020-10-30 17:52:21 +00:00
|
|
|
left?: boolean;
|
2019-01-14 21:49:58 +00:00
|
|
|
lastMessage?: {
|
2020-09-24 20:57:54 +00:00
|
|
|
status: LastMessageStatus;
|
2019-01-14 21:49:58 +00:00
|
|
|
text: string;
|
2020-10-28 21:54:33 +00:00
|
|
|
deletedForEveryone?: boolean;
|
2019-01-14 21:49:58 +00:00
|
|
|
};
|
2020-11-20 17:30:45 +00:00
|
|
|
markedUnread?: boolean;
|
2020-07-24 01:35:32 +00:00
|
|
|
phoneNumber?: string;
|
2020-05-27 21:37:06 +00:00
|
|
|
membersCount?: number;
|
2021-03-04 18:06:49 +00:00
|
|
|
messageCount?: number;
|
2021-01-29 21:19:24 +00:00
|
|
|
accessControlAddFromInviteLink?: number;
|
|
|
|
accessControlAttributes?: number;
|
|
|
|
accessControlMembers?: number;
|
2021-07-20 20:18:35 +00:00
|
|
|
announcementsOnly?: boolean;
|
|
|
|
announcementsOnlyReady?: boolean;
|
2020-10-30 17:52:21 +00:00
|
|
|
expireTimer?: number;
|
2021-04-29 18:32:38 +00:00
|
|
|
memberships?: Array<{
|
|
|
|
conversationId: string;
|
|
|
|
isAdmin: boolean;
|
|
|
|
}>;
|
|
|
|
pendingMemberships?: Array<{
|
|
|
|
conversationId: string;
|
|
|
|
addedByUserId?: string;
|
|
|
|
}>;
|
|
|
|
pendingApprovalMemberships?: Array<{
|
|
|
|
conversationId: string;
|
|
|
|
}>;
|
2020-08-27 19:45:08 +00:00
|
|
|
muteExpiresAt?: number;
|
2021-08-05 12:35:33 +00:00
|
|
|
dontNotifyForMentionsIfMuted?: boolean;
|
2020-09-24 20:57:54 +00:00
|
|
|
type: ConversationTypeType;
|
2021-05-07 22:21:10 +00:00
|
|
|
isMe: boolean;
|
2020-11-20 17:30:45 +00:00
|
|
|
lastUpdated?: number;
|
2021-01-29 21:19:24 +00:00
|
|
|
// This is used by the CompositionInput for @mentions
|
|
|
|
sortedGroupMembers?: Array<ConversationType>;
|
2020-06-26 00:08:58 +00:00
|
|
|
title: string;
|
2021-04-27 22:35:35 +00:00
|
|
|
searchableTitle?: string;
|
2020-07-29 23:20:05 +00:00
|
|
|
unreadCount?: number;
|
|
|
|
isSelected?: boolean;
|
2021-05-13 20:57:27 +00:00
|
|
|
isFetchingUUID?: boolean;
|
2019-05-31 22:42:01 +00:00
|
|
|
typingContact?: {
|
2021-08-11 16:23:21 +00:00
|
|
|
acceptedMessageRequest: boolean;
|
2019-05-31 22:42:01 +00:00
|
|
|
avatarPath?: string;
|
2021-08-11 16:23:21 +00:00
|
|
|
color?: AvatarColorType;
|
|
|
|
isMe: boolean;
|
2019-05-31 22:42:01 +00:00
|
|
|
name?: string;
|
2020-09-24 20:57:54 +00:00
|
|
|
phoneNumber?: string;
|
2019-05-31 22:42:01 +00:00
|
|
|
profileName?: string;
|
2021-08-11 16:23:21 +00:00
|
|
|
sharedGroupNames: Array<string>;
|
|
|
|
title: string;
|
2020-09-24 20:57:54 +00:00
|
|
|
} | null;
|
2021-01-29 21:19:24 +00:00
|
|
|
recentMediaItems?: Array<MediaItemType>;
|
2021-02-23 20:34:28 +00:00
|
|
|
profileSharing?: boolean;
|
2019-08-07 00:40:25 +00:00
|
|
|
|
|
|
|
shouldShowDraft?: boolean;
|
2020-09-24 20:57:54 +00:00
|
|
|
draftText?: string | null;
|
2020-11-03 01:19:52 +00:00
|
|
|
draftBodyRanges?: Array<BodyRangeType>;
|
2019-08-07 00:40:25 +00:00
|
|
|
draftPreview?: string;
|
2020-05-27 21:37:06 +00:00
|
|
|
|
2021-05-07 22:21:10 +00:00
|
|
|
sharedGroupNames: Array<string>;
|
2021-06-02 00:24:28 +00:00
|
|
|
groupDescription?: string;
|
2020-10-16 18:31:57 +00:00
|
|
|
groupVersion?: 1 | 2;
|
2020-11-13 19:57:55 +00:00
|
|
|
groupId?: string;
|
2021-01-29 21:19:24 +00:00
|
|
|
groupLink?: string;
|
2020-05-27 21:37:06 +00:00
|
|
|
messageRequestsEnabled?: boolean;
|
2021-05-07 22:21:10 +00:00
|
|
|
acceptedMessageRequest: boolean;
|
2020-11-13 19:57:55 +00:00
|
|
|
secretParams?: string;
|
|
|
|
publicParams?: string;
|
2021-06-01 23:30:25 +00:00
|
|
|
acknowledgedGroupNameCollisions?: GroupNameCollisionsWithIdsByTitle;
|
2021-07-19 19:26:06 +00:00
|
|
|
profileKey?: string;
|
2019-01-14 21:49:58 +00:00
|
|
|
};
|
2021-07-19 19:26:06 +00:00
|
|
|
export type ProfileDataType = {
|
|
|
|
firstName: string;
|
|
|
|
} & Pick<ConversationType, 'aboutEmoji' | 'aboutText' | 'familyName'>;
|
|
|
|
|
2019-01-14 21:49:58 +00:00
|
|
|
export type ConversationLookupType = {
|
|
|
|
[key: string]: ConversationType;
|
|
|
|
};
|
2021-04-05 22:18:19 +00:00
|
|
|
export type CustomError = Error & {
|
|
|
|
identifier?: string;
|
|
|
|
number?: string;
|
|
|
|
};
|
2019-05-31 22:42:01 +00:00
|
|
|
|
|
|
|
type MessagePointerType = {
|
|
|
|
id: string;
|
|
|
|
received_at: number;
|
2021-01-13 16:32:18 +00:00
|
|
|
sent_at?: number;
|
2019-05-31 22:42:01 +00:00
|
|
|
};
|
|
|
|
type MessageMetricsType = {
|
|
|
|
newest?: MessagePointerType;
|
|
|
|
oldest?: MessagePointerType;
|
|
|
|
oldestUnread?: MessagePointerType;
|
|
|
|
totalUnread: number;
|
|
|
|
};
|
|
|
|
|
2019-03-20 17:42:28 +00:00
|
|
|
export type MessageLookupType = {
|
2021-06-17 17:15:10 +00:00
|
|
|
[key: string]: MessageAttributesType;
|
2019-03-20 17:42:28 +00:00
|
|
|
};
|
|
|
|
export type ConversationMessageType = {
|
2019-05-31 22:42:01 +00:00
|
|
|
heightChangeMessageIds: Array<string>;
|
|
|
|
isLoadingMessages: boolean;
|
|
|
|
isNearBottom?: boolean;
|
|
|
|
loadCountdownStart?: number;
|
|
|
|
messageIds: Array<string>;
|
|
|
|
metrics: MessageMetricsType;
|
|
|
|
resetCounter: number;
|
|
|
|
scrollToMessageId?: string;
|
|
|
|
scrollToMessageCounter: number;
|
2019-03-20 17:42:28 +00:00
|
|
|
};
|
2019-05-31 22:42:01 +00:00
|
|
|
|
2019-03-20 17:42:28 +00:00
|
|
|
export type MessagesByConversationType = {
|
2021-01-06 15:41:43 +00:00
|
|
|
[key: string]: ConversationMessageType | undefined;
|
2019-03-20 17:42:28 +00:00
|
|
|
};
|
2019-01-14 21:49:58 +00:00
|
|
|
|
2021-01-29 22:16:48 +00:00
|
|
|
export type PreJoinConversationType = {
|
|
|
|
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;
|
|
|
|
};
|
|
|
|
|
2021-03-03 20:09:58 +00:00
|
|
|
export enum ComposerStep {
|
2021-06-25 23:52:56 +00:00
|
|
|
StartDirectConversation = 'StartDirectConversation',
|
|
|
|
ChooseGroupMembers = 'ChooseGroupMembers',
|
|
|
|
SetGroupMetadata = 'SetGroupMetadata',
|
2021-03-03 20:09:58 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
export enum OneTimeModalState {
|
|
|
|
NeverShown,
|
|
|
|
Showing,
|
|
|
|
Shown,
|
|
|
|
}
|
|
|
|
|
|
|
|
type ComposerGroupCreationState = {
|
|
|
|
groupAvatar: undefined | ArrayBuffer;
|
|
|
|
groupName: string;
|
2021-06-25 23:52:56 +00:00
|
|
|
groupExpireTimer: number;
|
2021-03-03 20:09:58 +00:00
|
|
|
maximumGroupSizeModalState: OneTimeModalState;
|
|
|
|
recommendedGroupSizeModalState: OneTimeModalState;
|
|
|
|
selectedConversationIds: Array<string>;
|
2021-08-06 00:17:05 +00:00
|
|
|
userAvatarData: Array<AvatarDataType>;
|
2021-03-03 20:09:58 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
type ComposerStateType =
|
|
|
|
| {
|
|
|
|
step: ComposerStep.StartDirectConversation;
|
2021-04-20 23:16:49 +00:00
|
|
|
searchTerm: string;
|
2021-03-03 20:09:58 +00:00
|
|
|
}
|
|
|
|
| ({
|
|
|
|
step: ComposerStep.ChooseGroupMembers;
|
2021-04-20 23:16:49 +00:00
|
|
|
searchTerm: string;
|
2021-03-03 20:09:58 +00:00
|
|
|
cantAddContactIdForModal: undefined | string;
|
|
|
|
} & 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 }
|
|
|
|
));
|
|
|
|
|
2021-06-01 23:30:25 +00:00
|
|
|
type ContactSpoofingReviewStateType =
|
|
|
|
| {
|
|
|
|
type: ContactSpoofingType.DirectConversationWithSameTitle;
|
|
|
|
safeConversationId: string;
|
|
|
|
}
|
|
|
|
| {
|
|
|
|
type: ContactSpoofingType.MultipleGroupMembersWithSameTitle;
|
|
|
|
groupConversationId: string;
|
|
|
|
};
|
2021-04-21 16:31:12 +00:00
|
|
|
|
2019-01-14 21:49:58 +00:00
|
|
|
export type ConversationsStateType = {
|
2021-01-29 22:16:48 +00:00
|
|
|
preJoinConversation?: PreJoinConversationType;
|
2021-03-03 20:09:58 +00:00
|
|
|
invitedConversationIdsForNewlyCreatedGroup?: Array<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-02-12 21:58:14 +00:00
|
|
|
selectedConversationId?: string;
|
2019-05-31 22:42:01 +00:00
|
|
|
selectedMessage?: string;
|
|
|
|
selectedMessageCounter: number;
|
2021-01-29 21:19:24 +00:00
|
|
|
selectedConversationTitle?: string;
|
2020-10-30 17:52:21 +00:00
|
|
|
selectedConversationPanelDepth: number;
|
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
|
|
|
/**
|
|
|
|
* Each key is a conversation ID. Each value is an array of message IDs stopped by that
|
|
|
|
* conversation being unverified.
|
|
|
|
*/
|
|
|
|
outboundMessagesPendingConversationVerification: Record<
|
|
|
|
string,
|
|
|
|
Array<string>
|
|
|
|
>;
|
|
|
|
|
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;
|
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
|
|
|
|
|
2021-08-18 20:08:14 +00:00
|
|
|
export const COLORS_CHANGED = 'conversations/COLORS_CHANGED';
|
|
|
|
export const COLOR_SELECTED = 'conversations/COLOR_SELECTED';
|
2021-08-31 20:58:39 +00:00
|
|
|
const CANCEL_MESSAGES_PENDING_CONVERSATION_VERIFICATION =
|
|
|
|
'conversations/CANCEL_MESSAGES_PENDING_CONVERSATION_VERIFICATION';
|
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';
|
2021-08-31 20:58:39 +00:00
|
|
|
const MESSAGE_STOPPED_BY_MISSING_VERIFICATION =
|
|
|
|
'conversations/MESSAGE_STOPPED_BY_MISSING_VERIFICATION';
|
2021-08-06 00:17:05 +00:00
|
|
|
const REPLACE_AVATARS = 'conversations/REPLACE_AVATARS';
|
2021-05-28 16:15:17 +00:00
|
|
|
|
2021-08-31 20:58:39 +00:00
|
|
|
type CancelMessagesPendingConversationVerificationActionType = {
|
|
|
|
type: typeof CANCEL_MESSAGES_PENDING_CONVERSATION_VERIFICATION;
|
|
|
|
};
|
2021-03-03 20:09:58 +00:00
|
|
|
type CantAddContactToGroupActionType = {
|
|
|
|
type: 'CANT_ADD_CONTACT_TO_GROUP';
|
|
|
|
payload: {
|
|
|
|
conversationId: string;
|
|
|
|
};
|
|
|
|
};
|
|
|
|
type ClearGroupCreationErrorActionType = { type: 'CLEAR_GROUP_CREATION_ERROR' };
|
|
|
|
type ClearInvitedConversationsForNewlyCreatedGroupActionType = {
|
|
|
|
type: 'CLEAR_INVITED_CONVERSATIONS_FOR_NEWLY_CREATED_GROUP';
|
|
|
|
};
|
|
|
|
type CloseCantAddContactToGroupModalActionType = {
|
|
|
|
type: 'CLOSE_CANT_ADD_CONTACT_TO_GROUP_MODAL';
|
|
|
|
};
|
2021-04-21 16:31:12 +00:00
|
|
|
type CloseContactSpoofingReviewActionType = {
|
|
|
|
type: 'CLOSE_CONTACT_SPOOFING_REVIEW';
|
|
|
|
};
|
2021-03-03 20:09:58 +00:00
|
|
|
type CloseMaximumGroupSizeModalActionType = {
|
|
|
|
type: 'CLOSE_MAXIMUM_GROUP_SIZE_MODAL';
|
|
|
|
};
|
|
|
|
type CloseRecommendedGroupSizeModalActionType = {
|
|
|
|
type: 'CLOSE_RECOMMENDED_GROUP_SIZE_MODAL';
|
|
|
|
};
|
2021-05-28 16:15:17 +00:00
|
|
|
type ColorsChangedActionType = {
|
|
|
|
type: typeof COLORS_CHANGED;
|
|
|
|
payload: {
|
|
|
|
conversationColor?: ConversationColorType;
|
|
|
|
customColorData?: {
|
|
|
|
id: string;
|
|
|
|
value: CustomColorType;
|
|
|
|
};
|
|
|
|
};
|
|
|
|
};
|
2021-06-03 21:34:36 +00:00
|
|
|
type ColorSelectedPayloadType = {
|
|
|
|
conversationId: string;
|
|
|
|
conversationColor?: ConversationColorType;
|
|
|
|
customColorData?: {
|
|
|
|
id: string;
|
|
|
|
value: CustomColorType;
|
|
|
|
};
|
|
|
|
};
|
|
|
|
export type ColorSelectedActionType = {
|
|
|
|
type: typeof COLOR_SELECTED;
|
|
|
|
payload: ColorSelectedPayloadType;
|
|
|
|
};
|
2021-08-06 00:17:05 +00:00
|
|
|
type ComposeDeleteAvatarActionType = {
|
|
|
|
type: typeof COMPOSE_REMOVE_AVATAR;
|
|
|
|
payload: AvatarDataType;
|
|
|
|
};
|
|
|
|
type ComposeReplaceAvatarsActionType = {
|
|
|
|
type: typeof COMPOSE_REPLACE_AVATAR;
|
|
|
|
payload: {
|
|
|
|
curr: AvatarDataType;
|
|
|
|
prev?: AvatarDataType;
|
|
|
|
};
|
|
|
|
};
|
|
|
|
type ComposeSaveAvatarActionType = {
|
|
|
|
type: typeof COMPOSE_ADD_AVATAR;
|
|
|
|
payload: AvatarDataType;
|
|
|
|
};
|
2021-05-28 16:15:17 +00:00
|
|
|
type CustomColorRemovedActionType = {
|
|
|
|
type: typeof CUSTOM_COLOR_REMOVED;
|
2021-06-02 21:05:09 +00:00
|
|
|
payload: {
|
|
|
|
colorId: string;
|
|
|
|
};
|
2021-05-28 16:15:17 +00:00
|
|
|
};
|
2021-01-29 22:16:48 +00:00
|
|
|
type SetPreJoinConversationActionType = {
|
|
|
|
type: 'SET_PRE_JOIN_CONVERSATION';
|
|
|
|
payload: {
|
|
|
|
data: PreJoinConversationType | undefined;
|
|
|
|
};
|
|
|
|
};
|
|
|
|
|
2019-01-14 21:49:58 +00:00
|
|
|
type ConversationAddedActionType = {
|
|
|
|
type: 'CONVERSATION_ADDED';
|
|
|
|
payload: {
|
|
|
|
id: string;
|
|
|
|
data: ConversationType;
|
|
|
|
};
|
|
|
|
};
|
|
|
|
type ConversationChangedActionType = {
|
|
|
|
type: 'CONVERSATION_CHANGED';
|
|
|
|
payload: {
|
|
|
|
id: string;
|
|
|
|
data: ConversationType;
|
|
|
|
};
|
|
|
|
};
|
|
|
|
type ConversationRemovedActionType = {
|
|
|
|
type: 'CONVERSATION_REMOVED';
|
|
|
|
payload: {
|
|
|
|
id: string;
|
|
|
|
};
|
|
|
|
};
|
2019-11-07 21:36:16 +00:00
|
|
|
export type ConversationUnloadedActionType = {
|
2019-05-31 22:42:01 +00:00
|
|
|
type: 'CONVERSATION_UNLOADED';
|
|
|
|
payload: {
|
|
|
|
id: string;
|
|
|
|
};
|
|
|
|
};
|
2021-03-03 20:09:58 +00:00
|
|
|
type CreateGroupPendingActionType = {
|
|
|
|
type: 'CREATE_GROUP_PENDING';
|
|
|
|
};
|
|
|
|
type CreateGroupFulfilledActionType = {
|
|
|
|
type: 'CREATE_GROUP_FULFILLED';
|
|
|
|
payload: {
|
|
|
|
invitedConversationIds: Array<string>;
|
|
|
|
};
|
|
|
|
};
|
|
|
|
type CreateGroupRejectedActionType = {
|
|
|
|
type: 'CREATE_GROUP_REJECTED';
|
|
|
|
};
|
2019-01-14 21:49:58 +00:00
|
|
|
export type RemoveAllConversationsActionType = {
|
|
|
|
type: 'CONVERSATIONS_REMOVE_ALL';
|
|
|
|
payload: null;
|
|
|
|
};
|
2019-11-07 21:36:16 +00:00
|
|
|
export type MessageSelectedActionType = {
|
|
|
|
type: 'MESSAGE_SELECTED';
|
|
|
|
payload: {
|
|
|
|
messageId: string;
|
|
|
|
conversationId: string;
|
|
|
|
};
|
|
|
|
};
|
2021-08-31 20:58:39 +00:00
|
|
|
type MessageStoppedByMissingVerificationActionType = {
|
|
|
|
type: typeof MESSAGE_STOPPED_BY_MISSING_VERIFICATION;
|
|
|
|
payload: {
|
|
|
|
messageId: string;
|
|
|
|
untrustedConversationIds: ReadonlyArray<string>;
|
|
|
|
};
|
|
|
|
};
|
2019-05-31 22:42:01 +00:00
|
|
|
export type MessageChangedActionType = {
|
|
|
|
type: '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
|
|
|
};
|
|
|
|
};
|
|
|
|
export type MessageDeletedActionType = {
|
|
|
|
type: 'MESSAGE_DELETED';
|
|
|
|
payload: {
|
|
|
|
id: string;
|
|
|
|
conversationId: string;
|
|
|
|
};
|
|
|
|
};
|
2020-12-07 20:43:19 +00:00
|
|
|
type MessageSizeChangedActionType = {
|
|
|
|
type: 'MESSAGE_SIZE_CHANGED';
|
|
|
|
payload: {
|
|
|
|
id: string;
|
|
|
|
conversationId: string;
|
|
|
|
};
|
|
|
|
};
|
2019-05-31 22:42:01 +00:00
|
|
|
export type MessagesAddedActionType = {
|
|
|
|
type: 'MESSAGES_ADDED';
|
|
|
|
payload: {
|
|
|
|
conversationId: string;
|
2021-06-17 17:15:10 +00:00
|
|
|
messages: Array<MessageAttributesType>;
|
2019-05-31 22:42:01 +00:00
|
|
|
isNewMessage: boolean;
|
2019-09-19 22:16:46 +00:00
|
|
|
isActive: boolean;
|
2019-05-31 22:42:01 +00:00
|
|
|
};
|
|
|
|
};
|
2020-12-04 20:41:40 +00:00
|
|
|
|
|
|
|
export type RepairNewestMessageActionType = {
|
|
|
|
type: 'REPAIR_NEWEST_MESSAGE';
|
|
|
|
payload: {
|
|
|
|
conversationId: string;
|
|
|
|
};
|
|
|
|
};
|
|
|
|
export type RepairOldestMessageActionType = {
|
|
|
|
type: 'REPAIR_OLDEST_MESSAGE';
|
|
|
|
payload: {
|
|
|
|
conversationId: string;
|
|
|
|
};
|
|
|
|
};
|
2019-05-31 22:42:01 +00:00
|
|
|
export type MessagesResetActionType = {
|
|
|
|
type: 'MESSAGES_RESET';
|
|
|
|
payload: {
|
|
|
|
conversationId: string;
|
2021-06-17 17:15:10 +00:00
|
|
|
messages: Array<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
|
|
|
};
|
|
|
|
};
|
|
|
|
export type SetMessagesLoadingActionType = {
|
|
|
|
type: 'SET_MESSAGES_LOADING';
|
|
|
|
payload: {
|
|
|
|
conversationId: string;
|
|
|
|
isLoadingMessages: boolean;
|
|
|
|
};
|
|
|
|
};
|
|
|
|
export type SetLoadCountdownStartActionType = {
|
|
|
|
type: 'SET_LOAD_COUNTDOWN_START';
|
|
|
|
payload: {
|
|
|
|
conversationId: string;
|
|
|
|
loadCountdownStart?: number;
|
|
|
|
};
|
|
|
|
};
|
|
|
|
export type SetIsNearBottomActionType = {
|
|
|
|
type: 'SET_NEAR_BOTTOM';
|
|
|
|
payload: {
|
|
|
|
conversationId: string;
|
|
|
|
isNearBottom: boolean;
|
|
|
|
};
|
|
|
|
};
|
2021-01-29 21:19:24 +00:00
|
|
|
export type SetConversationHeaderTitleActionType = {
|
|
|
|
type: 'SET_CONVERSATION_HEADER_TITLE';
|
|
|
|
payload: { title?: string };
|
|
|
|
};
|
2020-10-30 17:52:21 +00:00
|
|
|
export type SetSelectedConversationPanelDepthActionType = {
|
|
|
|
type: 'SET_SELECTED_CONVERSATION_PANEL_DEPTH';
|
|
|
|
payload: { panelDepth: number };
|
|
|
|
};
|
2019-05-31 22:42:01 +00:00
|
|
|
export type ScrollToMessageActionType = {
|
|
|
|
type: 'SCROLL_TO_MESSAGE';
|
|
|
|
payload: {
|
|
|
|
conversationId: string;
|
|
|
|
messageId: string;
|
|
|
|
};
|
|
|
|
};
|
|
|
|
export type ClearChangedMessagesActionType = {
|
|
|
|
type: 'CLEAR_CHANGED_MESSAGES';
|
|
|
|
payload: {
|
|
|
|
conversationId: string;
|
|
|
|
};
|
|
|
|
};
|
|
|
|
export type ClearSelectedMessageActionType = {
|
|
|
|
type: 'CLEAR_SELECTED_MESSAGE';
|
|
|
|
payload: null;
|
|
|
|
};
|
|
|
|
export type ClearUnreadMetricsActionType = {
|
|
|
|
type: 'CLEAR_UNREAD_METRICS';
|
|
|
|
payload: {
|
|
|
|
conversationId: string;
|
2019-01-14 21:49:58 +00:00
|
|
|
};
|
|
|
|
};
|
|
|
|
export type SelectedConversationChangedActionType = {
|
|
|
|
type: 'SELECTED_CONVERSATION_CHANGED';
|
|
|
|
payload: {
|
|
|
|
id: string;
|
|
|
|
messageId?: string;
|
|
|
|
};
|
|
|
|
};
|
2021-06-01 23:30:25 +00:00
|
|
|
type ReviewGroupMemberNameCollisionActionType = {
|
|
|
|
type: 'REVIEW_GROUP_MEMBER_NAME_COLLISION';
|
|
|
|
payload: {
|
|
|
|
groupConversationId: string;
|
|
|
|
};
|
|
|
|
};
|
2021-04-21 16:31:12 +00:00
|
|
|
type ReviewMessageRequestNameCollisionActionType = {
|
|
|
|
type: 'REVIEW_MESSAGE_REQUEST_NAME_COLLISION';
|
|
|
|
payload: {
|
|
|
|
safeConversationId: string;
|
|
|
|
};
|
|
|
|
};
|
2019-03-12 00:20:16 +00:00
|
|
|
type ShowInboxActionType = {
|
|
|
|
type: 'SHOW_INBOX';
|
|
|
|
payload: null;
|
|
|
|
};
|
2019-11-07 21:36:16 +00:00
|
|
|
export type ShowArchivedConversationsActionType = {
|
2019-03-12 00:20:16 +00:00
|
|
|
type: 'SHOW_ARCHIVED_CONVERSATIONS';
|
|
|
|
payload: null;
|
|
|
|
};
|
2021-03-03 20:09:58 +00:00
|
|
|
type SetComposeGroupAvatarActionType = {
|
|
|
|
type: 'SET_COMPOSE_GROUP_AVATAR';
|
|
|
|
payload: { groupAvatar: undefined | ArrayBuffer };
|
|
|
|
};
|
|
|
|
type SetComposeGroupNameActionType = {
|
|
|
|
type: 'SET_COMPOSE_GROUP_NAME';
|
|
|
|
payload: { groupName: string };
|
|
|
|
};
|
2021-06-25 23:52:56 +00:00
|
|
|
type SetComposeGroupExpireTimerActionType = {
|
|
|
|
type: 'SET_COMPOSE_GROUP_EXPIRE_TIMER';
|
|
|
|
payload: { groupExpireTimer: number };
|
|
|
|
};
|
2021-02-23 20:34:28 +00:00
|
|
|
type SetComposeSearchTermActionType = {
|
|
|
|
type: 'SET_COMPOSE_SEARCH_TERM';
|
2021-04-20 23:16:49 +00:00
|
|
|
payload: { searchTerm: string };
|
2021-02-23 20:34:28 +00:00
|
|
|
};
|
2021-01-29 21:19:24 +00:00
|
|
|
type SetRecentMediaItemsActionType = {
|
|
|
|
type: 'SET_RECENT_MEDIA_ITEMS';
|
|
|
|
payload: {
|
|
|
|
id: string;
|
|
|
|
recentMediaItems: Array<MediaItemType>;
|
|
|
|
};
|
|
|
|
};
|
2021-08-06 00:17:05 +00:00
|
|
|
type ToggleComposeEditingAvatarActionType = {
|
|
|
|
type: typeof COMPOSE_TOGGLE_EDITING_AVATAR;
|
|
|
|
};
|
2021-02-23 20:34:28 +00:00
|
|
|
type StartComposingActionType = {
|
|
|
|
type: 'START_COMPOSING';
|
|
|
|
};
|
2021-03-03 20:09:58 +00:00
|
|
|
type ShowChooseGroupMembersActionType = {
|
|
|
|
type: 'SHOW_CHOOSE_GROUP_MEMBERS';
|
|
|
|
};
|
|
|
|
type StartSettingGroupMetadataActionType = {
|
|
|
|
type: 'START_SETTING_GROUP_METADATA';
|
|
|
|
};
|
2021-02-23 20:34:28 +00:00
|
|
|
export type SwitchToAssociatedViewActionType = {
|
|
|
|
type: 'SWITCH_TO_ASSOCIATED_VIEW';
|
|
|
|
payload: { conversationId: string };
|
|
|
|
};
|
2021-03-03 20:09:58 +00:00
|
|
|
export type ToggleConversationInChooseMembersActionType = {
|
|
|
|
type: 'TOGGLE_CONVERSATION_IN_CHOOSE_MEMBERS';
|
|
|
|
payload: {
|
|
|
|
conversationId: string;
|
|
|
|
maxRecommendedGroupSize: number;
|
|
|
|
maxGroupSize: number;
|
|
|
|
};
|
|
|
|
};
|
2021-08-06 00:17:05 +00:00
|
|
|
|
|
|
|
type ReplaceAvatarsActionType = {
|
|
|
|
type: typeof REPLACE_AVATARS;
|
|
|
|
payload: {
|
|
|
|
conversationId: string;
|
|
|
|
avatars: Array<AvatarDataType>;
|
|
|
|
};
|
|
|
|
};
|
2019-01-14 21:49:58 +00:00
|
|
|
export type ConversationActionType =
|
2021-08-31 20:58:39 +00:00
|
|
|
| CancelMessagesPendingConversationVerificationActionType
|
2021-03-03 20:09:58 +00:00
|
|
|
| CantAddContactToGroupActionType
|
2021-01-29 22:16:48 +00:00
|
|
|
| ClearChangedMessagesActionType
|
2021-03-03 20:09:58 +00:00
|
|
|
| ClearGroupCreationErrorActionType
|
|
|
|
| ClearInvitedConversationsForNewlyCreatedGroupActionType
|
2021-01-29 22:16:48 +00:00
|
|
|
| ClearSelectedMessageActionType
|
|
|
|
| ClearUnreadMetricsActionType
|
2021-03-03 20:09:58 +00:00
|
|
|
| CloseCantAddContactToGroupModalActionType
|
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
|
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
|
2021-08-31 20:58:39 +00:00
|
|
|
| MessageStoppedByMissingVerificationActionType
|
2019-05-31 22:42:01 +00:00
|
|
|
| MessageChangedActionType
|
|
|
|
| MessageDeletedActionType
|
2021-01-29 22:16:48 +00:00
|
|
|
| MessageSelectedActionType
|
|
|
|
| MessageSizeChangedActionType
|
2021-08-06 00:17:05 +00:00
|
|
|
| MessagesAddedActionType
|
2021-01-29 22:16:48 +00:00
|
|
|
| MessagesResetActionType
|
|
|
|
| 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
|
2019-03-12 00:20:16 +00:00
|
|
|
| SelectedConversationChangedActionType
|
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
|
2021-01-29 22:16:48 +00:00
|
|
|
| SetConversationHeaderTitleActionType
|
|
|
|
| SetIsNearBottomActionType
|
|
|
|
| SetLoadCountdownStartActionType
|
|
|
|
| SetMessagesLoadingActionType
|
|
|
|
| SetPreJoinConversationActionType
|
2021-01-29 21:19:24 +00:00
|
|
|
| SetRecentMediaItemsActionType
|
2021-01-29 22:16:48 +00:00
|
|
|
| SetSelectedConversationPanelDepthActionType
|
|
|
|
| ShowArchivedConversationsActionType
|
2021-08-06 00:17:05 +00:00
|
|
|
| ShowChooseGroupMembersActionType
|
2021-02-23 20:34:28 +00:00
|
|
|
| ShowInboxActionType
|
|
|
|
| StartComposingActionType
|
2021-03-03 20:09:58 +00:00
|
|
|
| StartSettingGroupMetadataActionType
|
|
|
|
| SwitchToAssociatedViewActionType
|
2021-08-06 00:17:05 +00:00
|
|
|
| ToggleConversationInChooseMembersActionType
|
|
|
|
| ToggleComposeEditingAvatarActionType;
|
2019-01-14 21:49:58 +00:00
|
|
|
|
|
|
|
// Action Creators
|
|
|
|
|
|
|
|
export const actions = {
|
2021-08-31 20:58:39 +00:00
|
|
|
cancelMessagesPendingConversationVerification,
|
2021-03-03 20:09:58 +00:00
|
|
|
cantAddContactToGroup,
|
2021-01-29 21:19:24 +00:00
|
|
|
clearChangedMessages,
|
2021-03-03 20:09:58 +00:00
|
|
|
clearGroupCreationError,
|
2021-08-06 00:17:05 +00:00
|
|
|
clearInvitedConversationsForNewlyCreatedGroup,
|
2021-01-29 21:19:24 +00:00
|
|
|
clearSelectedMessage,
|
|
|
|
clearUnreadMetrics,
|
2021-03-03 20:09:58 +00:00
|
|
|
closeCantAddContactToGroupModal,
|
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,
|
2019-05-31 22:42:01 +00:00
|
|
|
conversationUnloaded,
|
2021-03-03 20:09:58 +00:00
|
|
|
createGroup,
|
2021-08-06 00:17:05 +00:00
|
|
|
deleteAvatarFromDisk,
|
2021-06-17 17:15:10 +00:00
|
|
|
doubleCheckMissingQuoteReference,
|
2021-08-31 20:58:39 +00:00
|
|
|
messageStoppedByMissingVerification,
|
2019-05-31 22:42:01 +00:00
|
|
|
messageChanged,
|
2021-01-29 21:19:24 +00:00
|
|
|
messageDeleted,
|
2021-01-29 22:16:48 +00:00
|
|
|
messageSizeChanged,
|
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,
|
2019-01-14 21:49:58 +00:00
|
|
|
openConversationExternal,
|
2021-01-29 21:19:24 +00:00
|
|
|
openConversationInternal,
|
|
|
|
removeAllConversations,
|
2021-05-28 16:15:17 +00:00
|
|
|
removeCustomColorOnConversations,
|
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,
|
2021-06-01 23:30:25 +00:00
|
|
|
reviewGroupMemberNameCollision,
|
2021-04-21 16:31:12 +00:00
|
|
|
reviewMessageRequestNameCollision,
|
2021-08-06 00:17:05 +00:00
|
|
|
saveAvatarToDisk,
|
2021-01-29 21:19:24 +00:00
|
|
|
scrollToMessage,
|
|
|
|
selectMessage,
|
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,
|
2021-01-29 21:19:24 +00:00
|
|
|
setIsNearBottom,
|
|
|
|
setLoadCountdownStart,
|
|
|
|
setMessagesLoading,
|
2021-01-29 22:16:48 +00:00
|
|
|
setPreJoinConversation,
|
2021-01-29 21:19:24 +00:00
|
|
|
setRecentMediaItems,
|
|
|
|
setSelectedConversationHeaderTitle,
|
|
|
|
setSelectedConversationPanelDepth,
|
|
|
|
showArchivedConversations,
|
2021-08-06 00:17:05 +00:00
|
|
|
showChooseGroupMembers,
|
2021-01-29 21:19:24 +00:00
|
|
|
showInbox,
|
2021-02-23 20:34:28 +00:00
|
|
|
startComposing,
|
|
|
|
startNewConversationFromPhoneNumber,
|
2021-03-03 20:09:58 +00:00
|
|
|
startSettingGroupMetadata,
|
|
|
|
toggleConversationInChooseMembers,
|
2021-08-06 00:17:05 +00:00
|
|
|
toggleComposeEditingAvatar,
|
2021-08-31 20:58:39 +00:00
|
|
|
verifyConversationsStoppingMessageSend,
|
2019-01-14 21:49:58 +00:00
|
|
|
};
|
|
|
|
|
2021-08-06 00:17:05 +00:00
|
|
|
function filterAvatarData(
|
|
|
|
avatars: ReadonlyArray<AvatarDataType>,
|
|
|
|
data: AvatarDataType
|
|
|
|
): Array<AvatarDataType> {
|
|
|
|
return avatars.filter(avatarData => !isSameAvatarData(data, avatarData));
|
|
|
|
}
|
|
|
|
|
|
|
|
function getNextAvatarId(avatars: Array<AvatarDataType>): number {
|
|
|
|
return Math.max(...avatars.map(x => Number(x.id))) + 1;
|
|
|
|
}
|
|
|
|
|
|
|
|
async function getAvatarsAndUpdateConversation(
|
|
|
|
conversations: ConversationsStateType,
|
|
|
|
conversationId: string,
|
|
|
|
getNextAvatarsData: (
|
|
|
|
avatars: Array<AvatarDataType>,
|
|
|
|
nextId: number
|
|
|
|
) => Array<AvatarDataType>
|
|
|
|
): Promise<Array<AvatarDataType>> {
|
|
|
|
const conversation = window.ConversationController.get(conversationId);
|
|
|
|
if (!conversation) {
|
|
|
|
throw new Error('No conversation found');
|
|
|
|
}
|
|
|
|
|
|
|
|
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'])
|
|
|
|
);
|
|
|
|
await window.Signal.Data.updateConversation(conversation.attributes);
|
|
|
|
|
|
|
|
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 {
|
|
|
|
window.log.info(
|
|
|
|
'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,
|
|
|
|
},
|
|
|
|
});
|
|
|
|
};
|
|
|
|
}
|
|
|
|
|
|
|
|
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) {
|
|
|
|
throw new Error('No avatar ArrayBuffer provided');
|
|
|
|
}
|
|
|
|
|
|
|
|
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,
|
2021-08-06 00:17:05 +00:00
|
|
|
avatarBuffer?: ArrayBuffer
|
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,
|
|
|
|
},
|
2021-08-06 00:17:05 +00:00
|
|
|
avatarBuffer
|
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) {
|
|
|
|
log.error('myProfileChanged', err && err.stack ? err.stack : err);
|
|
|
|
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
|
|
|
},
|
|
|
|
});
|
|
|
|
};
|
|
|
|
}
|
|
|
|
|
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;
|
|
|
|
}
|
|
|
|
|
|
|
|
await window.Signal.Data.updateConversation(conversation.attributes);
|
|
|
|
}
|
|
|
|
|
|
|
|
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,
|
|
|
|
};
|
|
|
|
}
|
|
|
|
|
2021-08-31 20:58:39 +00:00
|
|
|
function verifyConversationsStoppingMessageSend(): ThunkAction<
|
|
|
|
void,
|
|
|
|
RootStateType,
|
|
|
|
unknown,
|
|
|
|
never
|
|
|
|
> {
|
|
|
|
return async (_dispatch, getState) => {
|
|
|
|
const conversationIds = Object.keys(
|
|
|
|
getState().conversations.outboundMessagesPendingConversationVerification
|
|
|
|
);
|
|
|
|
|
|
|
|
await Promise.all(
|
|
|
|
conversationIds.map(async conversationId => {
|
|
|
|
const conversation = window.ConversationController.get(conversationId);
|
|
|
|
await conversation?.setVerifiedDefault();
|
|
|
|
})
|
|
|
|
);
|
|
|
|
};
|
|
|
|
}
|
|
|
|
|
2021-08-06 00:17:05 +00:00
|
|
|
function composeSaveAvatarToDisk(
|
|
|
|
avatarData: AvatarDataType
|
|
|
|
): ThunkAction<void, RootStateType, unknown, ComposeSaveAvatarActionType> {
|
|
|
|
return async dispatch => {
|
|
|
|
if (!avatarData.buffer) {
|
|
|
|
throw new Error('No avatar ArrayBuffer provided');
|
|
|
|
}
|
|
|
|
|
|
|
|
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 {
|
|
|
|
window.log.info(
|
|
|
|
'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-08-31 20:58:39 +00:00
|
|
|
function cancelMessagesPendingConversationVerification(): ThunkAction<
|
|
|
|
void,
|
|
|
|
RootStateType,
|
|
|
|
unknown,
|
|
|
|
CancelMessagesPendingConversationVerificationActionType
|
|
|
|
> {
|
|
|
|
return async (dispatch, getState) => {
|
|
|
|
const messageIdsPending = getMessageIdsPendingBecauseOfVerification(
|
|
|
|
getState()
|
|
|
|
);
|
|
|
|
const messagesStopped = await getMessagesById([...messageIdsPending]);
|
|
|
|
messagesStopped.forEach(message => {
|
|
|
|
message.markFailed();
|
|
|
|
});
|
|
|
|
|
|
|
|
dispatch({
|
|
|
|
type: CANCEL_MESSAGES_PENDING_CONVERSATION_VERIFICATION,
|
|
|
|
});
|
|
|
|
|
|
|
|
await window.Signal.Data.saveMessages(
|
|
|
|
messagesStopped.map(message => message.attributes)
|
|
|
|
);
|
|
|
|
};
|
|
|
|
}
|
|
|
|
|
2021-03-03 20:09:58 +00:00
|
|
|
function cantAddContactToGroup(
|
|
|
|
conversationId: string
|
|
|
|
): CantAddContactToGroupActionType {
|
|
|
|
return {
|
|
|
|
type: 'CANT_ADD_CONTACT_TO_GROUP',
|
|
|
|
payload: { conversationId },
|
|
|
|
};
|
|
|
|
}
|
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> {
|
2021-08-31 20:58:39 +00:00
|
|
|
return async (dispatch, getState) => {
|
2020-12-09 23:21:34 +00:00
|
|
|
calling.groupMembersChanged(id);
|
|
|
|
|
2021-08-31 20:58:39 +00:00
|
|
|
if (!data.isUntrusted) {
|
|
|
|
const messageIdsPending =
|
|
|
|
getOwn(
|
|
|
|
getState().conversations
|
|
|
|
.outboundMessagesPendingConversationVerification,
|
|
|
|
id
|
|
|
|
) ?? [];
|
|
|
|
const messagesPending = await getMessagesById(messageIdsPending);
|
|
|
|
messagesPending.forEach(message => {
|
|
|
|
message.retrySend();
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
2020-12-09 23:21:34 +00:00
|
|
|
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,
|
|
|
|
},
|
|
|
|
};
|
|
|
|
}
|
2019-05-31 22:42:01 +00:00
|
|
|
function conversationUnloaded(id: string): ConversationUnloadedActionType {
|
|
|
|
return {
|
|
|
|
type: 'CONVERSATION_UNLOADED',
|
|
|
|
payload: {
|
|
|
|
id,
|
|
|
|
},
|
|
|
|
};
|
|
|
|
}
|
2021-03-03 20:09:58 +00:00
|
|
|
|
|
|
|
function createGroup(): ThunkAction<
|
|
|
|
void,
|
|
|
|
RootStateType,
|
|
|
|
unknown,
|
|
|
|
| CreateGroupPendingActionType
|
|
|
|
| CreateGroupFulfilledActionType
|
|
|
|
| CreateGroupRejectedActionType
|
|
|
|
| SwitchToAssociatedViewActionType
|
|
|
|
> {
|
|
|
|
return async (dispatch, getState, ...args) => {
|
|
|
|
const { composer } = getState().conversations;
|
|
|
|
if (
|
|
|
|
composer?.step !== ComposerStep.SetGroupMetadata ||
|
|
|
|
composer.isCreating
|
|
|
|
) {
|
|
|
|
assert(false, 'Cannot create group in this stage; doing nothing');
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
dispatch({ type: 'CREATE_GROUP_PENDING' });
|
|
|
|
|
|
|
|
try {
|
|
|
|
const conversation = await groups.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: {
|
|
|
|
invitedConversationIds: (
|
|
|
|
conversation.get('pendingMembersV2') || []
|
|
|
|
).map(member => member.conversationId),
|
|
|
|
},
|
|
|
|
});
|
|
|
|
openConversationInternal({
|
|
|
|
conversationId: conversation.id,
|
|
|
|
switchToAssociatedView: true,
|
|
|
|
})(dispatch, getState, ...args);
|
|
|
|
} catch (err) {
|
2021-03-11 00:32:13 +00:00
|
|
|
window.log.error(
|
|
|
|
'Failed to create group',
|
|
|
|
err && err.stack ? err.stack : 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
|
|
|
|
2020-09-14 21:56:35 +00:00
|
|
|
function selectMessage(
|
|
|
|
messageId: string,
|
|
|
|
conversationId: string
|
|
|
|
): MessageSelectedActionType {
|
2019-11-07 21:36:16 +00:00
|
|
|
return {
|
|
|
|
type: 'MESSAGE_SELECTED',
|
|
|
|
payload: {
|
|
|
|
messageId,
|
|
|
|
conversationId,
|
|
|
|
},
|
|
|
|
};
|
|
|
|
}
|
|
|
|
|
2021-08-31 20:58:39 +00:00
|
|
|
function messageStoppedByMissingVerification(
|
|
|
|
messageId: string,
|
|
|
|
untrustedConversationIds: ReadonlyArray<string>
|
|
|
|
): MessageStoppedByMissingVerificationActionType {
|
|
|
|
return {
|
|
|
|
type: MESSAGE_STOPPED_BY_MISSING_VERIFICATION,
|
|
|
|
payload: {
|
|
|
|
messageId,
|
|
|
|
untrustedConversationIds,
|
|
|
|
},
|
|
|
|
};
|
|
|
|
}
|
|
|
|
|
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 {
|
|
|
|
type: 'MESSAGE_CHANGED',
|
|
|
|
payload: {
|
|
|
|
id,
|
|
|
|
conversationId,
|
|
|
|
data,
|
|
|
|
},
|
|
|
|
};
|
|
|
|
}
|
|
|
|
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 {
|
2019-05-31 22:42:01 +00:00
|
|
|
type: 'MESSAGE_DELETED',
|
2019-01-14 21:49:58 +00:00
|
|
|
payload: {
|
|
|
|
id,
|
|
|
|
conversationId,
|
|
|
|
},
|
|
|
|
};
|
|
|
|
}
|
2020-12-07 20:43:19 +00:00
|
|
|
function messageSizeChanged(
|
|
|
|
id: string,
|
|
|
|
conversationId: string
|
|
|
|
): MessageSizeChangedActionType {
|
|
|
|
return {
|
|
|
|
type: 'MESSAGE_SIZE_CHANGED',
|
|
|
|
payload: {
|
|
|
|
id,
|
|
|
|
conversationId,
|
|
|
|
},
|
|
|
|
};
|
|
|
|
}
|
2019-05-31 22:42:01 +00:00
|
|
|
function messagesAdded(
|
|
|
|
conversationId: string,
|
2021-06-17 17:15:10 +00:00
|
|
|
messages: Array<MessageAttributesType>,
|
2019-05-31 22:42:01 +00:00
|
|
|
isNewMessage: boolean,
|
2019-09-19 22:16:46 +00:00
|
|
|
isActive: boolean
|
2019-05-31 22:42:01 +00:00
|
|
|
): MessagesAddedActionType {
|
|
|
|
return {
|
|
|
|
type: 'MESSAGES_ADDED',
|
|
|
|
payload: {
|
|
|
|
conversationId,
|
|
|
|
messages,
|
|
|
|
isNewMessage,
|
2019-09-19 22:16:46 +00:00
|
|
|
isActive,
|
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 };
|
|
|
|
}
|
|
|
|
|
2019-05-31 22:42:01 +00:00
|
|
|
function messagesReset(
|
|
|
|
conversationId: string,
|
2021-06-17 17:15:10 +00:00
|
|
|
messages: Array<MessageAttributesType>,
|
2019-05-31 22:42:01 +00:00
|
|
|
metrics: MessageMetricsType,
|
2020-07-06 17:06:44 +00:00
|
|
|
scrollToMessageId?: string,
|
|
|
|
unboundedFetch?: boolean
|
2019-05-31 22:42:01 +00:00
|
|
|
): MessagesResetActionType {
|
|
|
|
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,
|
|
|
|
},
|
|
|
|
};
|
|
|
|
}
|
|
|
|
function setMessagesLoading(
|
|
|
|
conversationId: string,
|
|
|
|
isLoadingMessages: boolean
|
|
|
|
): SetMessagesLoadingActionType {
|
|
|
|
return {
|
|
|
|
type: 'SET_MESSAGES_LOADING',
|
|
|
|
payload: {
|
|
|
|
conversationId,
|
|
|
|
isLoadingMessages,
|
|
|
|
},
|
|
|
|
};
|
|
|
|
}
|
|
|
|
function setLoadCountdownStart(
|
|
|
|
conversationId: string,
|
|
|
|
loadCountdownStart?: number
|
|
|
|
): SetLoadCountdownStartActionType {
|
|
|
|
return {
|
|
|
|
type: 'SET_LOAD_COUNTDOWN_START',
|
|
|
|
payload: {
|
|
|
|
conversationId,
|
|
|
|
loadCountdownStart,
|
|
|
|
},
|
|
|
|
};
|
|
|
|
}
|
|
|
|
function setIsNearBottom(
|
|
|
|
conversationId: string,
|
|
|
|
isNearBottom: boolean
|
|
|
|
): SetIsNearBottomActionType {
|
|
|
|
return {
|
|
|
|
type: 'SET_NEAR_BOTTOM',
|
|
|
|
payload: {
|
|
|
|
conversationId,
|
|
|
|
isNearBottom,
|
|
|
|
},
|
|
|
|
};
|
|
|
|
}
|
2021-01-29 21:19:24 +00:00
|
|
|
function setSelectedConversationHeaderTitle(
|
|
|
|
title?: string
|
|
|
|
): SetConversationHeaderTitleActionType {
|
|
|
|
return {
|
|
|
|
type: 'SET_CONVERSATION_HEADER_TITLE',
|
|
|
|
payload: { title },
|
|
|
|
};
|
|
|
|
}
|
2020-10-30 17:52:21 +00:00
|
|
|
function setSelectedConversationPanelDepth(
|
|
|
|
panelDepth: number
|
|
|
|
): SetSelectedConversationPanelDepthActionType {
|
|
|
|
return {
|
|
|
|
type: 'SET_SELECTED_CONVERSATION_PANEL_DEPTH',
|
|
|
|
payload: { panelDepth },
|
|
|
|
};
|
|
|
|
}
|
2021-01-29 21:19:24 +00:00
|
|
|
function setRecentMediaItems(
|
|
|
|
id: string,
|
|
|
|
recentMediaItems: Array<MediaItemType>
|
|
|
|
): SetRecentMediaItemsActionType {
|
|
|
|
return {
|
|
|
|
type: 'SET_RECENT_MEDIA_ITEMS',
|
|
|
|
payload: { id, recentMediaItems },
|
|
|
|
};
|
|
|
|
}
|
2019-05-31 22:42:01 +00:00
|
|
|
function clearChangedMessages(
|
|
|
|
conversationId: string
|
|
|
|
): ClearChangedMessagesActionType {
|
|
|
|
return {
|
|
|
|
type: 'CLEAR_CHANGED_MESSAGES',
|
|
|
|
payload: {
|
|
|
|
conversationId,
|
|
|
|
},
|
|
|
|
};
|
|
|
|
}
|
2021-03-03 20:09:58 +00:00
|
|
|
function clearInvitedConversationsForNewlyCreatedGroup(): ClearInvitedConversationsForNewlyCreatedGroupActionType {
|
|
|
|
return { type: 'CLEAR_INVITED_CONVERSATIONS_FOR_NEWLY_CREATED_GROUP' };
|
|
|
|
}
|
|
|
|
function clearGroupCreationError(): ClearGroupCreationErrorActionType {
|
|
|
|
return { type: 'CLEAR_GROUP_CREATION_ERROR' };
|
|
|
|
}
|
2019-05-31 22:42:01 +00:00
|
|
|
function clearSelectedMessage(): ClearSelectedMessageActionType {
|
|
|
|
return {
|
|
|
|
type: 'CLEAR_SELECTED_MESSAGE',
|
|
|
|
payload: null,
|
|
|
|
};
|
|
|
|
}
|
|
|
|
function clearUnreadMetrics(
|
|
|
|
conversationId: string
|
|
|
|
): ClearUnreadMetricsActionType {
|
|
|
|
return {
|
|
|
|
type: 'CLEAR_UNREAD_METRICS',
|
|
|
|
payload: {
|
|
|
|
conversationId,
|
|
|
|
},
|
|
|
|
};
|
|
|
|
}
|
2021-03-03 20:09:58 +00:00
|
|
|
function closeCantAddContactToGroupModal(): CloseCantAddContactToGroupModalActionType {
|
|
|
|
return { type: 'CLOSE_CANT_ADD_CONTACT_TO_GROUP_MODAL' };
|
|
|
|
}
|
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' };
|
|
|
|
}
|
2019-05-31 22:42:01 +00:00
|
|
|
function scrollToMessage(
|
|
|
|
conversationId: string,
|
|
|
|
messageId: string
|
|
|
|
): ScrollToMessageActionType {
|
|
|
|
return {
|
|
|
|
type: 'SCROLL_TO_MESSAGE',
|
|
|
|
payload: {
|
|
|
|
conversationId,
|
|
|
|
messageId,
|
|
|
|
},
|
|
|
|
};
|
|
|
|
}
|
2019-01-14 21:49:58 +00:00
|
|
|
|
2021-03-03 20:09:58 +00:00
|
|
|
function setComposeGroupAvatar(
|
|
|
|
groupAvatar: undefined | ArrayBuffer
|
|
|
|
): 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(
|
|
|
|
groupExpireTimer: number
|
|
|
|
): 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' };
|
|
|
|
}
|
|
|
|
|
2021-02-23 20:34:28 +00:00
|
|
|
function startNewConversationFromPhoneNumber(
|
|
|
|
e164: string
|
|
|
|
): ThunkAction<void, RootStateType, unknown, ShowInboxActionType> {
|
|
|
|
return dispatch => {
|
|
|
|
trigger('showConversation', e164);
|
|
|
|
|
|
|
|
dispatch(showInbox());
|
|
|
|
};
|
|
|
|
}
|
|
|
|
|
2021-03-03 20:09:58 +00:00
|
|
|
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
|
|
|
|
);
|
|
|
|
|
|
|
|
assert(
|
|
|
|
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 },
|
|
|
|
});
|
|
|
|
};
|
|
|
|
}
|
|
|
|
|
2019-01-14 21:49:58 +00:00
|
|
|
// Note: we need two actions here to simplify. Operations outside of the left pane can
|
2019-05-31 22:42:01 +00:00
|
|
|
// trigger an 'openConversation' so we go through Whisper.events for all
|
|
|
|
// conversation selection. Internal just triggers the Whisper.event, and External
|
|
|
|
// makes the changes to the store.
|
2021-02-23 20:34:28 +00:00
|
|
|
function openConversationInternal({
|
|
|
|
conversationId,
|
|
|
|
messageId,
|
|
|
|
switchToAssociatedView,
|
|
|
|
}: Readonly<{
|
|
|
|
conversationId: string;
|
|
|
|
messageId?: string;
|
|
|
|
switchToAssociatedView?: boolean;
|
|
|
|
}>): ThunkAction<
|
|
|
|
void,
|
|
|
|
RootStateType,
|
|
|
|
unknown,
|
|
|
|
SwitchToAssociatedViewActionType
|
|
|
|
> {
|
|
|
|
return dispatch => {
|
|
|
|
trigger('showConversation', conversationId, messageId);
|
2019-01-14 21:49:58 +00:00
|
|
|
|
2021-02-23 20:34:28 +00:00
|
|
|
if (switchToAssociatedView) {
|
|
|
|
dispatch({
|
|
|
|
type: 'SWITCH_TO_ASSOCIATED_VIEW',
|
|
|
|
payload: { conversationId },
|
|
|
|
});
|
|
|
|
}
|
2019-01-14 21:49:58 +00:00
|
|
|
};
|
|
|
|
}
|
|
|
|
function openConversationExternal(
|
|
|
|
id: string,
|
|
|
|
messageId?: string
|
|
|
|
): SelectedConversationChangedActionType {
|
|
|
|
return {
|
|
|
|
type: 'SELECTED_CONVERSATION_CHANGED',
|
|
|
|
payload: {
|
|
|
|
id,
|
|
|
|
messageId,
|
|
|
|
},
|
|
|
|
};
|
|
|
|
}
|
|
|
|
|
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,
|
|
|
|
};
|
|
|
|
}
|
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) {
|
|
|
|
message.doubleCheckMissingQuoteReference();
|
|
|
|
}
|
|
|
|
|
|
|
|
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-08-31 20:58:39 +00:00
|
|
|
outboundMessagesPendingConversationVerification: {},
|
2019-03-20 17:42:28 +00:00
|
|
|
messagesByConversation: {},
|
2019-05-31 22:42:01 +00:00
|
|
|
messagesLookup: {},
|
|
|
|
selectedMessageCounter: 0,
|
|
|
|
showArchived: false,
|
2021-01-29 21:19:24 +00:00
|
|
|
selectedConversationTitle: '',
|
2020-10-30 17:52:21 +00:00
|
|
|
selectedConversationPanelDepth: 0,
|
2019-01-14 21:49:58 +00:00
|
|
|
};
|
|
|
|
}
|
|
|
|
|
2019-05-31 22:42:01 +00:00
|
|
|
function hasMessageHeightChanged(
|
2021-06-17 17:15:10 +00:00
|
|
|
message: MessageAttributesType,
|
|
|
|
previous: MessageAttributesType
|
2020-09-14 21:56:35 +00:00
|
|
|
): boolean {
|
2019-08-22 22:04:14 +00:00
|
|
|
const messageAttachments = message.attachments || [];
|
|
|
|
const previousAttachments = previous.attachments || [];
|
|
|
|
|
2020-03-25 22:48:10 +00:00
|
|
|
const errorStatusChanged =
|
|
|
|
(!message.errors && previous.errors) ||
|
|
|
|
(message.errors && !previous.errors) ||
|
|
|
|
(message.errors &&
|
|
|
|
previous.errors &&
|
|
|
|
message.errors.length !== previous.errors.length);
|
|
|
|
if (errorStatusChanged) {
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2020-03-26 21:47:35 +00:00
|
|
|
const groupUpdateChanged = message.group_update !== previous.group_update;
|
|
|
|
if (groupUpdateChanged) {
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2019-08-22 22:04:14 +00:00
|
|
|
const stickerPendingChanged =
|
|
|
|
message.sticker &&
|
|
|
|
message.sticker.data &&
|
|
|
|
previous.sticker &&
|
|
|
|
previous.sticker.data &&
|
2020-11-12 21:22:40 +00:00
|
|
|
!previous.sticker.data.blurHash &&
|
2019-08-22 22:04:14 +00:00
|
|
|
previous.sticker.data.pending !== message.sticker.data.pending;
|
|
|
|
if (stickerPendingChanged) {
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2019-10-17 17:19:41 +00:00
|
|
|
const longMessageAttachmentLoaded =
|
|
|
|
previous.bodyPending && !message.bodyPending;
|
|
|
|
if (longMessageAttachmentLoaded) {
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2019-09-04 21:11:30 +00:00
|
|
|
const firstAttachmentNoLongerPending =
|
2019-08-22 22:04:14 +00:00
|
|
|
previousAttachments[0] &&
|
|
|
|
previousAttachments[0].pending &&
|
|
|
|
messageAttachments[0] &&
|
|
|
|
!messageAttachments[0].pending;
|
2019-09-04 21:11:30 +00:00
|
|
|
if (firstAttachmentNoLongerPending) {
|
2019-08-22 22:04:14 +00:00
|
|
|
return true;
|
|
|
|
}
|
2019-08-20 19:34:52 +00:00
|
|
|
|
2020-02-03 20:02:49 +00:00
|
|
|
const currentReactions = message.reactions || [];
|
|
|
|
const lastReactions = previous.reactions || [];
|
|
|
|
const reactionsChanged =
|
|
|
|
(currentReactions.length === 0) !== (lastReactions.length === 0);
|
|
|
|
if (reactionsChanged) {
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2020-04-29 21:24:12 +00:00
|
|
|
const isDeletedForEveryone = message.deletedForEveryone;
|
|
|
|
const wasDeletedForEveryone = previous.deletedForEveryone;
|
|
|
|
if (isDeletedForEveryone !== wasDeletedForEveryone) {
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2019-08-22 22:04:14 +00:00
|
|
|
return false;
|
2019-05-31 22:42:01 +00:00
|
|
|
}
|
|
|
|
|
2021-01-06 15:41:43 +00:00
|
|
|
export function updateConversationLookups(
|
|
|
|
added: ConversationType | undefined,
|
|
|
|
removed: ConversationType | undefined,
|
|
|
|
state: ConversationsStateType
|
|
|
|
): Pick<
|
|
|
|
ConversationsStateType,
|
|
|
|
'conversationsByE164' | 'conversationsByUuid' | 'conversationsByGroupId'
|
|
|
|
> {
|
|
|
|
const result = {
|
|
|
|
conversationsByE164: state.conversationsByE164,
|
|
|
|
conversationsByUuid: state.conversationsByUuid,
|
|
|
|
conversationsByGroupId: state.conversationsByGroupId,
|
|
|
|
};
|
|
|
|
|
|
|
|
if (removed && removed.e164) {
|
|
|
|
result.conversationsByE164 = omit(result.conversationsByE164, removed.e164);
|
|
|
|
}
|
|
|
|
if (removed && removed.uuid) {
|
|
|
|
result.conversationsByUuid = omit(result.conversationsByUuid, removed.uuid);
|
|
|
|
}
|
|
|
|
if (removed && removed.groupId) {
|
|
|
|
result.conversationsByGroupId = omit(
|
|
|
|
result.conversationsByGroupId,
|
|
|
|
removed.groupId
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (added && added.e164) {
|
|
|
|
result.conversationsByE164 = {
|
|
|
|
...result.conversationsByE164,
|
|
|
|
[added.e164]: added,
|
|
|
|
};
|
|
|
|
}
|
|
|
|
if (added && added.uuid) {
|
|
|
|
result.conversationsByUuid = {
|
|
|
|
...result.conversationsByUuid,
|
|
|
|
[added.uuid]: added,
|
|
|
|
};
|
|
|
|
}
|
|
|
|
if (added && added.groupId) {
|
|
|
|
result.conversationsByGroupId = {
|
|
|
|
...result.conversationsByGroupId,
|
|
|
|
[added.groupId]: added,
|
|
|
|
};
|
|
|
|
}
|
|
|
|
|
|
|
|
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) {
|
|
|
|
assert(false, "Can't close the modal in this composer step. Doing nothing");
|
|
|
|
return state;
|
|
|
|
}
|
|
|
|
if (composer[modalToClose] !== OneTimeModalState.Showing) {
|
|
|
|
return state;
|
|
|
|
}
|
|
|
|
return {
|
|
|
|
...state,
|
|
|
|
composer: {
|
|
|
|
...composer,
|
|
|
|
[modalToClose]: OneTimeModalState.Shown,
|
|
|
|
},
|
|
|
|
};
|
|
|
|
}
|
|
|
|
|
2019-01-14 21:49:58 +00:00
|
|
|
export function reducer(
|
2020-12-14 19:47:21 +00:00
|
|
|
state: Readonly<ConversationsStateType> = getEmptyState(),
|
|
|
|
action: Readonly<ConversationActionType>
|
2019-01-14 21:49:58 +00:00
|
|
|
): ConversationsStateType {
|
2021-08-31 20:58:39 +00:00
|
|
|
if (action.type === CANCEL_MESSAGES_PENDING_CONVERSATION_VERIFICATION) {
|
|
|
|
return {
|
|
|
|
...state,
|
|
|
|
outboundMessagesPendingConversationVerification: {},
|
|
|
|
};
|
|
|
|
}
|
|
|
|
|
2021-03-03 20:09:58 +00:00
|
|
|
if (action.type === 'CANT_ADD_CONTACT_TO_GROUP') {
|
|
|
|
const { composer } = state;
|
|
|
|
if (composer?.step !== ComposerStep.ChooseGroupMembers) {
|
|
|
|
assert(false, "Can't update modal in this composer step. Doing nothing");
|
|
|
|
return state;
|
|
|
|
}
|
|
|
|
return {
|
|
|
|
...state,
|
|
|
|
composer: {
|
|
|
|
...composer,
|
|
|
|
cantAddContactIdForModal: action.payload.conversationId,
|
|
|
|
},
|
|
|
|
};
|
|
|
|
}
|
|
|
|
|
|
|
|
if (action.type === 'CLEAR_INVITED_CONVERSATIONS_FOR_NEWLY_CREATED_GROUP') {
|
|
|
|
return omit(state, 'invitedConversationIdsForNewlyCreatedGroup');
|
|
|
|
}
|
|
|
|
|
|
|
|
if (action.type === 'CLEAR_GROUP_CREATION_ERROR') {
|
|
|
|
const { composer } = state;
|
|
|
|
if (composer?.step !== ComposerStep.SetGroupMetadata) {
|
|
|
|
assert(
|
|
|
|
false,
|
|
|
|
"Can't clear group creation error in this composer state. Doing nothing"
|
|
|
|
);
|
|
|
|
return state;
|
|
|
|
}
|
|
|
|
return {
|
|
|
|
...state,
|
|
|
|
composer: {
|
|
|
|
...composer,
|
|
|
|
hasError: false,
|
|
|
|
},
|
|
|
|
};
|
|
|
|
}
|
|
|
|
|
|
|
|
if (action.type === 'CLOSE_CANT_ADD_CONTACT_TO_GROUP_MODAL') {
|
|
|
|
const { composer } = state;
|
|
|
|
if (composer?.step !== ComposerStep.ChooseGroupMembers) {
|
|
|
|
assert(
|
|
|
|
false,
|
|
|
|
"Can't close the modal in this composer step. Doing nothing"
|
|
|
|
);
|
|
|
|
return state;
|
|
|
|
}
|
|
|
|
return {
|
|
|
|
...state,
|
|
|
|
composer: {
|
|
|
|
...composer,
|
|
|
|
cantAddContactIdForModal: undefined,
|
|
|
|
},
|
|
|
|
};
|
|
|
|
}
|
|
|
|
|
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);
|
|
|
|
}
|
|
|
|
|
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),
|
2021-08-31 20:58:39 +00:00
|
|
|
outboundMessagesPendingConversationVerification: data.isUntrusted
|
|
|
|
? state.outboundMessagesPendingConversationVerification
|
|
|
|
: omit(state.outboundMessagesPendingConversationVerification, id),
|
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
|
|
|
|
// Note: With today's stacked converastions architecture, this can result in weird
|
|
|
|
// 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),
|
2021-08-31 20:58:39 +00:00
|
|
|
outboundMessagesPendingConversationVerification: data.isUntrusted
|
|
|
|
? state.outboundMessagesPendingConversationVerification
|
|
|
|
: omit(state.outboundMessagesPendingConversationVerification, id),
|
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
|
|
|
};
|
|
|
|
}
|
2019-05-31 22:42:01 +00:00
|
|
|
if (action.type === 'CONVERSATION_UNLOADED') {
|
|
|
|
const { payload } = action;
|
|
|
|
const { id } = payload;
|
|
|
|
const existingConversation = state.messagesByConversation[id];
|
|
|
|
if (!existingConversation) {
|
|
|
|
return state;
|
|
|
|
}
|
|
|
|
|
|
|
|
const { messageIds } = existingConversation;
|
2021-02-12 21:58:14 +00:00
|
|
|
const selectedConversationId =
|
|
|
|
state.selectedConversationId !== id
|
|
|
|
? 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,
|
2020-10-30 17:52:21 +00:00
|
|
|
selectedConversationPanelDepth: 0,
|
2019-05-31 22:42:01 +00:00
|
|
|
messagesLookup: omit(state.messagesLookup, messageIds),
|
|
|
|
messagesByConversation: omit(state.messagesByConversation, [id]),
|
|
|
|
};
|
|
|
|
}
|
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') {
|
|
|
|
// We don't do much here and instead rely on `openConversationInternal` to do most of
|
|
|
|
// the work.
|
|
|
|
return {
|
|
|
|
...state,
|
|
|
|
invitedConversationIdsForNewlyCreatedGroup:
|
|
|
|
action.payload.invitedConversationIds,
|
|
|
|
};
|
|
|
|
}
|
|
|
|
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,
|
|
|
|
},
|
|
|
|
};
|
|
|
|
}
|
2020-10-30 17:52:21 +00:00
|
|
|
if (action.type === 'SET_SELECTED_CONVERSATION_PANEL_DEPTH') {
|
|
|
|
return {
|
|
|
|
...state,
|
|
|
|
selectedConversationPanelDepth: action.payload.panelDepth,
|
|
|
|
};
|
|
|
|
}
|
2019-11-07 21:36:16 +00:00
|
|
|
if (action.type === 'MESSAGE_SELECTED') {
|
|
|
|
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,
|
|
|
|
selectedMessage: messageId,
|
|
|
|
selectedMessageCounter: state.selectedMessageCounter + 1,
|
|
|
|
};
|
|
|
|
}
|
2021-08-31 20:58:39 +00:00
|
|
|
if (action.type === MESSAGE_STOPPED_BY_MISSING_VERIFICATION) {
|
|
|
|
const { messageId, untrustedConversationIds } = action.payload;
|
|
|
|
|
|
|
|
const newOutboundMessagesPendingConversationVerification = {
|
|
|
|
...state.outboundMessagesPendingConversationVerification,
|
|
|
|
};
|
|
|
|
untrustedConversationIds.forEach(conversationId => {
|
|
|
|
const existingPendingMessageIds =
|
|
|
|
getOwn(
|
|
|
|
newOutboundMessagesPendingConversationVerification,
|
|
|
|
conversationId
|
|
|
|
) ?? [];
|
|
|
|
if (!existingPendingMessageIds.includes(messageId)) {
|
|
|
|
newOutboundMessagesPendingConversationVerification[conversationId] = [
|
|
|
|
...existingPendingMessageIds,
|
|
|
|
messageId,
|
|
|
|
];
|
|
|
|
}
|
|
|
|
});
|
|
|
|
|
|
|
|
return {
|
|
|
|
...state,
|
|
|
|
outboundMessagesPendingConversationVerification: newOutboundMessagesPendingConversationVerification,
|
|
|
|
};
|
|
|
|
}
|
2019-05-31 22:42:01 +00:00
|
|
|
if (action.type === 'MESSAGE_CHANGED') {
|
|
|
|
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) {
|
|
|
|
return state;
|
|
|
|
}
|
|
|
|
// ...and we've already loaded that message once
|
|
|
|
const existingMessage = state.messagesLookup[id];
|
|
|
|
if (!existingMessage) {
|
|
|
|
return state;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Check for changes which could affect height - that's why we need this
|
|
|
|
// heightChangeMessageIds field. It tells Timeline to recalculate all of its heights
|
|
|
|
const hasHeightChanged = hasMessageHeightChanged(data, existingMessage);
|
|
|
|
|
|
|
|
const { heightChangeMessageIds } = existingConversation;
|
|
|
|
const updatedChanges = hasHeightChanged
|
|
|
|
? uniq([...heightChangeMessageIds, id])
|
|
|
|
: heightChangeMessageIds;
|
|
|
|
|
|
|
|
return {
|
|
|
|
...state,
|
|
|
|
messagesLookup: {
|
|
|
|
...state.messagesLookup,
|
|
|
|
[id]: data,
|
|
|
|
},
|
|
|
|
messagesByConversation: {
|
|
|
|
...state.messagesByConversation,
|
|
|
|
[conversationId]: {
|
|
|
|
...existingConversation,
|
|
|
|
heightChangeMessageIds: updatedChanges,
|
|
|
|
},
|
|
|
|
},
|
|
|
|
};
|
|
|
|
}
|
2020-12-07 20:43:19 +00:00
|
|
|
if (action.type === 'MESSAGE_SIZE_CHANGED') {
|
|
|
|
const { id, conversationId } = action.payload;
|
|
|
|
|
|
|
|
const existingConversation = getOwn(
|
|
|
|
state.messagesByConversation,
|
|
|
|
conversationId
|
|
|
|
);
|
|
|
|
if (!existingConversation) {
|
|
|
|
return state;
|
|
|
|
}
|
|
|
|
|
|
|
|
return {
|
|
|
|
...state,
|
|
|
|
messagesByConversation: {
|
|
|
|
...state.messagesByConversation,
|
|
|
|
[conversationId]: {
|
|
|
|
...existingConversation,
|
|
|
|
heightChangeMessageIds: uniq([
|
|
|
|
...existingConversation.heightChangeMessageIds,
|
|
|
|
id,
|
|
|
|
]),
|
|
|
|
},
|
|
|
|
},
|
|
|
|
};
|
|
|
|
}
|
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 resetCounter = existingConversation
|
|
|
|
? existingConversation.resetCounter + 1
|
|
|
|
: 0;
|
|
|
|
|
2020-10-23 19:20:21 +00:00
|
|
|
const sorted = orderBy(
|
|
|
|
messages,
|
|
|
|
['received_at', 'sent_at'],
|
|
|
|
['ASC', 'ASC']
|
|
|
|
);
|
2019-05-31 22:42:01 +00:00
|
|
|
const messageIds = sorted.map(message => message.id);
|
|
|
|
|
|
|
|
const lookup = fromPairs(messages.map(message => [message.id, message]));
|
|
|
|
|
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
|
|
|
|
if (messages.length > 0) {
|
|
|
|
const first = messages[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
|
|
|
}
|
|
|
|
|
|
|
|
const last = messages[messages.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
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-05-31 22:42:01 +00:00
|
|
|
return {
|
|
|
|
...state,
|
|
|
|
selectedMessage: scrollToMessageId,
|
|
|
|
selectedMessageCounter: state.selectedMessageCounter + 1,
|
|
|
|
messagesLookup: {
|
|
|
|
...messagesLookup,
|
|
|
|
...lookup,
|
|
|
|
},
|
|
|
|
messagesByConversation: {
|
|
|
|
...messagesByConversation,
|
|
|
|
[conversationId]: {
|
|
|
|
isLoadingMessages: false,
|
|
|
|
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
|
|
|
resetCounter,
|
|
|
|
heightChangeMessageIds: [],
|
|
|
|
},
|
|
|
|
},
|
|
|
|
};
|
|
|
|
}
|
|
|
|
if (action.type === 'SET_MESSAGES_LOADING') {
|
|
|
|
const { payload } = action;
|
|
|
|
const { conversationId, isLoadingMessages } = payload;
|
|
|
|
|
|
|
|
const { messagesByConversation } = state;
|
|
|
|
const existingConversation = messagesByConversation[conversationId];
|
|
|
|
|
|
|
|
if (!existingConversation) {
|
|
|
|
return state;
|
|
|
|
}
|
|
|
|
|
|
|
|
return {
|
|
|
|
...state,
|
|
|
|
messagesByConversation: {
|
|
|
|
...messagesByConversation,
|
|
|
|
[conversationId]: {
|
|
|
|
...existingConversation,
|
|
|
|
loadCountdownStart: undefined,
|
|
|
|
isLoadingMessages,
|
|
|
|
},
|
|
|
|
},
|
|
|
|
};
|
|
|
|
}
|
|
|
|
if (action.type === 'SET_LOAD_COUNTDOWN_START') {
|
|
|
|
const { payload } = action;
|
|
|
|
const { conversationId, loadCountdownStart } = payload;
|
|
|
|
|
|
|
|
const { messagesByConversation } = state;
|
|
|
|
const existingConversation = messagesByConversation[conversationId];
|
|
|
|
|
|
|
|
if (!existingConversation) {
|
|
|
|
return state;
|
|
|
|
}
|
|
|
|
|
|
|
|
return {
|
|
|
|
...state,
|
|
|
|
messagesByConversation: {
|
|
|
|
...messagesByConversation,
|
|
|
|
[conversationId]: {
|
|
|
|
...existingConversation,
|
|
|
|
loadCountdownStart,
|
|
|
|
},
|
|
|
|
},
|
|
|
|
};
|
|
|
|
}
|
|
|
|
if (action.type === 'SET_NEAR_BOTTOM') {
|
|
|
|
const { payload } = action;
|
|
|
|
const { conversationId, isNearBottom } = payload;
|
|
|
|
|
|
|
|
const { messagesByConversation } = state;
|
|
|
|
const existingConversation = messagesByConversation[conversationId];
|
|
|
|
|
|
|
|
if (!existingConversation) {
|
|
|
|
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,
|
|
|
|
selectedMessage: messageId,
|
|
|
|
selectedMessageCounter: state.selectedMessageCounter + 1,
|
|
|
|
messagesByConversation: {
|
|
|
|
...messagesByConversation,
|
|
|
|
[conversationId]: {
|
|
|
|
...existingConversation,
|
|
|
|
isLoadingMessages: false,
|
|
|
|
scrollToMessageId: messageId,
|
|
|
|
scrollToMessageCounter:
|
|
|
|
existingConversation.scrollToMessageCounter + 1,
|
|
|
|
},
|
|
|
|
},
|
|
|
|
};
|
|
|
|
}
|
|
|
|
if (action.type === 'MESSAGE_DELETED') {
|
|
|
|
const { id, conversationId } = action.payload;
|
|
|
|
const { messagesByConversation, messagesLookup } = state;
|
|
|
|
|
|
|
|
const existingConversation = messagesByConversation[conversationId];
|
|
|
|
if (!existingConversation) {
|
|
|
|
return state;
|
|
|
|
}
|
|
|
|
|
|
|
|
// 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);
|
|
|
|
const heightChangeMessageIds = without(
|
|
|
|
existingConversation.heightChangeMessageIds,
|
|
|
|
id
|
|
|
|
);
|
|
|
|
|
2020-09-09 02:25:05 +00:00
|
|
|
let metrics;
|
|
|
|
if (messageIds.length === 0) {
|
|
|
|
metrics = {
|
|
|
|
totalUnread: 0,
|
|
|
|
};
|
|
|
|
} else {
|
|
|
|
metrics = {
|
|
|
|
...existingConversation.metrics,
|
|
|
|
oldest,
|
|
|
|
newest,
|
|
|
|
};
|
|
|
|
}
|
|
|
|
|
2019-05-31 22:42:01 +00:00
|
|
|
return {
|
|
|
|
...state,
|
|
|
|
messagesLookup: omit(messagesLookup, id),
|
|
|
|
messagesByConversation: {
|
|
|
|
[conversationId]: {
|
|
|
|
...existingConversation,
|
|
|
|
messageIds,
|
|
|
|
heightChangeMessageIds,
|
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') {
|
2019-09-19 22:16:46 +00:00
|
|
|
const { conversationId, isActive, isNewMessage, messages } = action.payload;
|
2019-05-31 22:42:01 +00:00
|
|
|
const { messagesByConversation, messagesLookup } = state;
|
|
|
|
|
|
|
|
const existingConversation = messagesByConversation[conversationId];
|
|
|
|
if (!existingConversation) {
|
|
|
|
return state;
|
|
|
|
}
|
|
|
|
|
|
|
|
let {
|
|
|
|
newest,
|
|
|
|
oldest,
|
|
|
|
oldestUnread,
|
|
|
|
totalUnread,
|
|
|
|
} = existingConversation.metrics;
|
|
|
|
|
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) {
|
|
|
|
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;
|
|
|
|
|
2019-09-19 22:16:46 +00:00
|
|
|
if ((!isNearBottom || !isActive) && !oldestUnread) {
|
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) {
|
|
|
|
oldestUnread = pick(lookup[oldestId], [
|
|
|
|
'id',
|
|
|
|
'received_at',
|
2021-01-13 16:32:18 +00:00
|
|
|
'sent_at',
|
2019-05-31 22:42:01 +00:00
|
|
|
]) as MessagePointerType;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (oldestUnread) {
|
|
|
|
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);
|
|
|
|
totalUnread = (totalUnread || 0) + newUnread;
|
|
|
|
}
|
|
|
|
|
2019-08-15 14:59:56 +00:00
|
|
|
const changedIds = intersection(newIds, existingConversation.messageIds);
|
|
|
|
const heightChangeMessageIds = uniq([
|
|
|
|
...changedIds,
|
|
|
|
...existingConversation.heightChangeMessageIds,
|
|
|
|
]);
|
|
|
|
|
2019-05-31 22:42:01 +00:00
|
|
|
return {
|
|
|
|
...state,
|
|
|
|
messagesLookup: {
|
|
|
|
...messagesLookup,
|
|
|
|
...lookup,
|
|
|
|
},
|
|
|
|
messagesByConversation: {
|
|
|
|
...messagesByConversation,
|
|
|
|
[conversationId]: {
|
|
|
|
...existingConversation,
|
|
|
|
isLoadingMessages: false,
|
|
|
|
messageIds,
|
|
|
|
heightChangeMessageIds,
|
|
|
|
scrollToMessageId: undefined,
|
|
|
|
metrics: {
|
|
|
|
...existingConversation.metrics,
|
|
|
|
newest,
|
|
|
|
oldest,
|
|
|
|
totalUnread,
|
|
|
|
oldestUnread,
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
};
|
|
|
|
}
|
|
|
|
if (action.type === 'CLEAR_SELECTED_MESSAGE') {
|
|
|
|
return {
|
|
|
|
...state,
|
|
|
|
selectedMessage: undefined,
|
|
|
|
};
|
|
|
|
}
|
|
|
|
if (action.type === 'CLEAR_CHANGED_MESSAGES') {
|
|
|
|
const { payload } = action;
|
|
|
|
const { conversationId } = payload;
|
|
|
|
const existingConversation = state.messagesByConversation[conversationId];
|
|
|
|
|
|
|
|
if (!existingConversation) {
|
|
|
|
return state;
|
|
|
|
}
|
|
|
|
|
|
|
|
return {
|
|
|
|
...state,
|
|
|
|
messagesByConversation: {
|
|
|
|
...state.messagesByConversation,
|
|
|
|
[conversationId]: {
|
|
|
|
...existingConversation,
|
|
|
|
heightChangeMessageIds: [],
|
|
|
|
},
|
|
|
|
},
|
|
|
|
};
|
|
|
|
}
|
|
|
|
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,
|
|
|
|
oldestUnread: undefined,
|
|
|
|
totalUnread: 0,
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
};
|
2019-01-14 21:49:58 +00:00
|
|
|
}
|
2019-03-12 00:20:16 +00:00
|
|
|
if (action.type === 'SELECTED_CONVERSATION_CHANGED') {
|
|
|
|
const { payload } = action;
|
|
|
|
const { id } = payload;
|
|
|
|
|
|
|
|
return {
|
2021-04-21 16:31:12 +00:00
|
|
|
...omit(state, 'contactSpoofingReview'),
|
2021-02-12 21:58:14 +00:00
|
|
|
selectedConversationId: id,
|
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
|
|
|
|
2021-01-29 21:19:24 +00:00
|
|
|
if (action.type === 'SET_CONVERSATION_HEADER_TITLE') {
|
|
|
|
return {
|
|
|
|
...state,
|
|
|
|
selectedConversationTitle: action.payload.title,
|
|
|
|
};
|
|
|
|
}
|
|
|
|
|
|
|
|
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: '',
|
2021-03-03 20:09:58 +00:00
|
|
|
},
|
|
|
|
};
|
|
|
|
}
|
|
|
|
|
|
|
|
if (action.type === 'SHOW_CHOOSE_GROUP_MEMBERS') {
|
|
|
|
let selectedConversationIds: Array<string>;
|
|
|
|
let recommendedGroupSizeModalState: OneTimeModalState;
|
|
|
|
let maximumGroupSizeModalState: OneTimeModalState;
|
|
|
|
let groupName: string;
|
|
|
|
let groupAvatar: undefined | ArrayBuffer;
|
2021-06-25 23:52:56 +00:00
|
|
|
let groupExpireTimer: number;
|
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: '',
|
2021-03-03 20:09:58 +00:00
|
|
|
selectedConversationIds,
|
|
|
|
cantAddContactIdForModal: undefined,
|
|
|
|
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:
|
|
|
|
assert(
|
|
|
|
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:
|
|
|
|
assert(false, 'Setting compose group avatar at this step is a no-op');
|
|
|
|
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:
|
|
|
|
assert(false, 'Setting compose group name at this step is a no-op');
|
|
|
|
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:
|
|
|
|
assert(false, 'Setting compose group name at this step is a no-op');
|
|
|
|
return state;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2021-02-23 20:34:28 +00:00
|
|
|
if (action.type === 'SET_COMPOSE_SEARCH_TERM') {
|
|
|
|
const { composer } = state;
|
|
|
|
if (!composer) {
|
|
|
|
assert(
|
|
|
|
false,
|
|
|
|
'Setting compose search term with the composer closed is a no-op'
|
|
|
|
);
|
|
|
|
return state;
|
|
|
|
}
|
2021-03-03 20:09:58 +00:00
|
|
|
if (composer?.step === ComposerStep.SetGroupMetadata) {
|
|
|
|
assert(false, 'Setting compose search term at this step is a no-op');
|
|
|
|
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
|
|
|
},
|
|
|
|
};
|
|
|
|
}
|
|
|
|
|
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:
|
|
|
|
assert(false, 'Setting editing avatar at this step is a no-op');
|
|
|
|
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:
|
|
|
|
assert(false, 'Adding an avatar at this step is a no-op');
|
|
|
|
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:
|
|
|
|
assert(false, 'Removing an avatar at this step is a no-op');
|
|
|
|
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:
|
|
|
|
assert(false, 'Replacing an avatar at this step is a no-op');
|
|
|
|
return state;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2021-02-23 20:34:28 +00:00
|
|
|
if (action.type === 'SWITCH_TO_ASSOCIATED_VIEW') {
|
|
|
|
const conversation = getOwn(
|
|
|
|
state.conversationLookup,
|
|
|
|
action.payload.conversationId
|
|
|
|
);
|
|
|
|
if (!conversation) {
|
|
|
|
return state;
|
|
|
|
}
|
|
|
|
return {
|
|
|
|
...omit(state, 'composer'),
|
|
|
|
showArchived: Boolean(conversation.isArchived),
|
|
|
|
};
|
|
|
|
}
|
|
|
|
|
2021-03-03 20:09:58 +00:00
|
|
|
if (action.type === 'TOGGLE_CONVERSATION_IN_CHOOSE_MEMBERS') {
|
|
|
|
const { composer } = state;
|
|
|
|
if (composer?.step !== ComposerStep.ChooseGroupMembers) {
|
|
|
|
assert(
|
|
|
|
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;
|
|
|
|
const {
|
|
|
|
conversationId,
|
|
|
|
conversationColor,
|
|
|
|
customColorData,
|
|
|
|
} = action.payload;
|
|
|
|
|
|
|
|
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),
|
|
|
|
};
|
|
|
|
}
|
|
|
|
|
2019-01-14 21:49:58 +00:00
|
|
|
return state;
|
|
|
|
}
|