2022-12-08 07:43:48 +00:00
|
|
|
// Copyright 2021-2022 Signal Messenger, LLC
|
2021-06-25 16:08:16 +00:00
|
|
|
// SPDX-License-Identifier: AGPL-3.0-only
|
|
|
|
|
2022-12-08 01:26:59 +00:00
|
|
|
import path from 'path';
|
|
|
|
|
2022-12-08 23:56:17 +00:00
|
|
|
import { debounce } from 'lodash';
|
2021-10-26 19:15:33 +00:00
|
|
|
import type { ThunkAction } from 'redux-thunk';
|
2021-08-09 20:06:21 +00:00
|
|
|
|
2021-11-15 21:54:33 +00:00
|
|
|
import type {
|
2022-12-08 07:43:48 +00:00
|
|
|
AddLinkPreviewActionType,
|
|
|
|
RemoveLinkPreviewActionType,
|
|
|
|
} from './linkPreviews';
|
|
|
|
import type {
|
|
|
|
AttachmentType,
|
2021-11-15 21:54:33 +00:00
|
|
|
AttachmentDraftType,
|
|
|
|
InMemoryAttachmentDraftType,
|
|
|
|
} from '../../types/Attachment';
|
2022-12-15 01:10:09 +00:00
|
|
|
import type { BoundActionCreatorsMapObject } from '../../hooks/useBoundActions';
|
2022-06-17 00:48:57 +00:00
|
|
|
import type {
|
2022-12-08 07:43:48 +00:00
|
|
|
DraftBodyRangesType,
|
|
|
|
ReplacementValuesType,
|
|
|
|
} from '../../types/Util';
|
|
|
|
import type { LinkPreviewType } from '../../types/message/LinkPreviews';
|
|
|
|
import type { MessageAttributesType } from '../../model-types.d';
|
|
|
|
import type { NoopActionType } from './noop';
|
|
|
|
import type { ShowToastActionType } from './toast';
|
|
|
|
import type { StateType as RootStateType } from '../reducer';
|
|
|
|
import type { UUIDStringType } from '../../types/UUID';
|
|
|
|
import * as log from '../../logging/log';
|
|
|
|
import * as Errors from '../../types/errors';
|
2022-06-17 00:48:57 +00:00
|
|
|
import {
|
|
|
|
ADD_PREVIEW as ADD_LINK_PREVIEW,
|
|
|
|
REMOVE_PREVIEW as REMOVE_LINK_PREVIEW,
|
|
|
|
} from './linkPreviews';
|
|
|
|
import { LinkPreviewSourceType } from '../../types/LinkPreview';
|
2022-12-08 01:26:59 +00:00
|
|
|
import { RecordingState } from './audioRecorder';
|
2022-12-15 00:48:36 +00:00
|
|
|
import { SHOW_TOAST } from './toast';
|
|
|
|
import { ToastType } from '../../types/Toast';
|
2022-12-08 07:43:48 +00:00
|
|
|
import { SafetyNumberChangeSource } from '../../components/SafetyNumberChangeDialog';
|
|
|
|
import { UUID } from '../../types/UUID';
|
|
|
|
import { assignWithNoUnnecessaryAllocation } from '../../util/assignWithNoUnnecessaryAllocation';
|
|
|
|
import { blockSendUntilConversationsAreVerified } from '../../util/blockSendUntilConversationsAreVerified';
|
|
|
|
import { clearConversationDraftAttachments } from '../../util/clearConversationDraftAttachments';
|
|
|
|
import { deleteDraftAttachment } from '../../util/deleteDraftAttachment';
|
|
|
|
import {
|
|
|
|
getLinkPreviewForSend,
|
2022-12-08 23:56:17 +00:00
|
|
|
hasLinkPreviewLoaded,
|
|
|
|
maybeGrabLinkPreview,
|
2022-12-14 19:05:32 +00:00
|
|
|
removeLinkPreview,
|
2022-12-08 07:43:48 +00:00
|
|
|
resetLinkPreview,
|
|
|
|
} from '../../services/LinkPreview';
|
2022-12-08 01:26:59 +00:00
|
|
|
import { getMaximumAttachmentSize } from '../../util/attachments';
|
2022-12-08 07:43:48 +00:00
|
|
|
import { getRecipientsByConversation } from '../../util/getRecipientsByConversation';
|
2022-12-08 01:26:59 +00:00
|
|
|
import {
|
|
|
|
getRenderDetailsForLimit,
|
|
|
|
processAttachment,
|
|
|
|
} from '../../util/processAttachment';
|
2022-12-08 07:43:48 +00:00
|
|
|
import { hasDraftAttachments } from '../../util/hasDraftAttachments';
|
|
|
|
import { isFileDangerous } from '../../util/isFileDangerous';
|
|
|
|
import { isImage, isVideo, stringToMIMEType } from '../../types/MIME';
|
|
|
|
import { isNotNil } from '../../util/isNotNil';
|
|
|
|
import { replaceIndex } from '../../util/replaceIndex';
|
|
|
|
import { resolveAttachmentDraftData } from '../../util/resolveAttachmentDraftData';
|
|
|
|
import { resolveDraftAttachmentOnDisk } from '../../util/resolveDraftAttachmentOnDisk';
|
|
|
|
import { shouldShowInvalidMessageToast } from '../../util/shouldShowInvalidMessageToast';
|
|
|
|
import { writeDraftAttachment } from '../../util/writeDraftAttachment';
|
2022-12-09 19:11:14 +00:00
|
|
|
import { getMessageById } from '../../messages/getMessageById';
|
|
|
|
import { canReply } from '../selectors/message';
|
|
|
|
import { getConversationSelector } from '../selectors/conversations';
|
2022-12-20 01:04:47 +00:00
|
|
|
import { enqueueReactionForSend } from '../../reactions/enqueueReactionForSend';
|
2022-12-15 01:10:09 +00:00
|
|
|
import { useBoundActions } from '../../hooks/useBoundActions';
|
2021-06-25 16:08:16 +00:00
|
|
|
|
|
|
|
// State
|
|
|
|
|
|
|
|
export type ComposerStateType = {
|
2021-11-15 21:54:33 +00:00
|
|
|
attachments: ReadonlyArray<AttachmentDraftType>;
|
2022-12-08 23:56:17 +00:00
|
|
|
focusCounter: number;
|
2022-12-08 07:43:48 +00:00
|
|
|
isDisabled: boolean;
|
2021-06-25 16:08:16 +00:00
|
|
|
linkPreviewLoading: boolean;
|
2022-06-17 00:48:57 +00:00
|
|
|
linkPreviewResult?: LinkPreviewType;
|
2022-12-08 07:43:48 +00:00
|
|
|
messageCompositionId: UUIDStringType;
|
2021-06-25 16:08:16 +00:00
|
|
|
quotedMessage?: Pick<MessageAttributesType, 'conversationId' | 'quote'>;
|
2022-12-02 23:54:37 +00:00
|
|
|
shouldSendHighQualityAttachments?: boolean;
|
2021-06-25 16:08:16 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
// Actions
|
|
|
|
|
2021-09-24 20:02:30 +00:00
|
|
|
const ADD_PENDING_ATTACHMENT = 'composer/ADD_PENDING_ATTACHMENT';
|
2021-06-25 16:08:16 +00:00
|
|
|
const REPLACE_ATTACHMENTS = 'composer/REPLACE_ATTACHMENTS';
|
|
|
|
const RESET_COMPOSER = 'composer/RESET_COMPOSER';
|
2022-12-08 23:56:17 +00:00
|
|
|
const SET_FOCUS = 'composer/SET_FOCUS';
|
2021-06-25 16:08:16 +00:00
|
|
|
const SET_HIGH_QUALITY_SETTING = 'composer/SET_HIGH_QUALITY_SETTING';
|
|
|
|
const SET_QUOTED_MESSAGE = 'composer/SET_QUOTED_MESSAGE';
|
2022-12-08 07:43:48 +00:00
|
|
|
const SET_COMPOSER_DISABLED = 'composer/SET_COMPOSER_DISABLED';
|
2021-06-25 16:08:16 +00:00
|
|
|
|
2021-09-24 20:02:30 +00:00
|
|
|
type AddPendingAttachmentActionType = {
|
|
|
|
type: typeof ADD_PENDING_ATTACHMENT;
|
2021-11-15 21:54:33 +00:00
|
|
|
payload: AttachmentDraftType;
|
2021-09-24 20:02:30 +00:00
|
|
|
};
|
|
|
|
|
2021-06-25 16:08:16 +00:00
|
|
|
type ReplaceAttachmentsActionType = {
|
|
|
|
type: typeof REPLACE_ATTACHMENTS;
|
2021-11-15 21:54:33 +00:00
|
|
|
payload: ReadonlyArray<AttachmentDraftType>;
|
2021-06-25 16:08:16 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
type ResetComposerActionType = {
|
|
|
|
type: typeof RESET_COMPOSER;
|
|
|
|
};
|
|
|
|
|
2022-12-08 07:43:48 +00:00
|
|
|
type SetComposerDisabledStateActionType = {
|
|
|
|
type: typeof SET_COMPOSER_DISABLED;
|
|
|
|
payload: boolean;
|
|
|
|
};
|
|
|
|
|
2022-12-08 23:56:17 +00:00
|
|
|
type SetFocusActionType = {
|
|
|
|
type: typeof SET_FOCUS;
|
|
|
|
};
|
|
|
|
|
2021-06-25 16:08:16 +00:00
|
|
|
type SetHighQualitySettingActionType = {
|
|
|
|
type: typeof SET_HIGH_QUALITY_SETTING;
|
|
|
|
payload: boolean;
|
|
|
|
};
|
|
|
|
|
|
|
|
type SetQuotedMessageActionType = {
|
|
|
|
type: typeof SET_QUOTED_MESSAGE;
|
|
|
|
payload?: Pick<MessageAttributesType, 'conversationId' | 'quote'>;
|
|
|
|
};
|
|
|
|
|
|
|
|
type ComposerActionType =
|
2022-06-17 00:48:57 +00:00
|
|
|
| AddLinkPreviewActionType
|
2021-09-24 20:02:30 +00:00
|
|
|
| AddPendingAttachmentActionType
|
|
|
|
| RemoveLinkPreviewActionType
|
2021-06-25 16:08:16 +00:00
|
|
|
| ReplaceAttachmentsActionType
|
|
|
|
| ResetComposerActionType
|
2022-12-08 07:43:48 +00:00
|
|
|
| SetComposerDisabledStateActionType
|
2022-12-08 23:56:17 +00:00
|
|
|
| SetFocusActionType
|
2021-06-25 16:08:16 +00:00
|
|
|
| SetHighQualitySettingActionType
|
|
|
|
| SetQuotedMessageActionType;
|
|
|
|
|
|
|
|
// Action Creators
|
|
|
|
|
|
|
|
export const actions = {
|
2021-09-24 20:02:30 +00:00
|
|
|
addAttachment,
|
|
|
|
addPendingAttachment,
|
2022-12-08 23:56:17 +00:00
|
|
|
onEditorStateChange,
|
2021-09-24 20:02:30 +00:00
|
|
|
processAttachments,
|
2022-12-20 01:04:47 +00:00
|
|
|
reactToMessage,
|
2021-09-24 20:02:30 +00:00
|
|
|
removeAttachment,
|
2021-06-25 16:08:16 +00:00
|
|
|
replaceAttachments,
|
|
|
|
resetComposer,
|
2022-12-08 07:43:48 +00:00
|
|
|
sendMultiMediaMessage,
|
|
|
|
sendStickerMessage,
|
2022-12-08 23:56:17 +00:00
|
|
|
setComposerDisabledState,
|
|
|
|
setComposerFocus,
|
2022-12-09 19:11:14 +00:00
|
|
|
setQuoteByMessageId,
|
2021-06-25 16:08:16 +00:00
|
|
|
setMediaQualitySetting,
|
|
|
|
setQuotedMessage,
|
|
|
|
};
|
|
|
|
|
2022-12-15 01:10:09 +00:00
|
|
|
export const useComposerActions = (): BoundActionCreatorsMapObject<
|
|
|
|
typeof actions
|
|
|
|
> => useBoundActions(actions);
|
|
|
|
|
2022-12-08 07:43:48 +00:00
|
|
|
function sendMultiMediaMessage(
|
|
|
|
conversationId: string,
|
|
|
|
options: {
|
|
|
|
draftAttachments?: ReadonlyArray<AttachmentDraftType>;
|
|
|
|
mentions?: DraftBodyRangesType;
|
|
|
|
message?: string;
|
|
|
|
timestamp?: number;
|
|
|
|
voiceNoteAttachment?: InMemoryAttachmentDraftType;
|
|
|
|
}
|
|
|
|
): ThunkAction<
|
|
|
|
void,
|
|
|
|
RootStateType,
|
|
|
|
unknown,
|
|
|
|
| NoopActionType
|
|
|
|
| ResetComposerActionType
|
|
|
|
| SetComposerDisabledStateActionType
|
|
|
|
| SetQuotedMessageActionType
|
|
|
|
| ShowToastActionType
|
|
|
|
> {
|
|
|
|
return async (dispatch, getState) => {
|
|
|
|
const conversation = window.ConversationController.get(conversationId);
|
|
|
|
if (!conversation) {
|
|
|
|
throw new Error('sendMultiMediaMessage: No conversation found');
|
|
|
|
}
|
|
|
|
|
|
|
|
const {
|
|
|
|
draftAttachments,
|
|
|
|
message = '',
|
|
|
|
mentions,
|
|
|
|
timestamp = Date.now(),
|
|
|
|
voiceNoteAttachment,
|
|
|
|
} = options;
|
|
|
|
|
|
|
|
const state = getState();
|
|
|
|
|
|
|
|
const sendStart = Date.now();
|
|
|
|
const recipientsByConversation = getRecipientsByConversation([
|
|
|
|
conversation.attributes,
|
|
|
|
]);
|
|
|
|
|
|
|
|
try {
|
|
|
|
dispatch(setComposerDisabledState(true));
|
|
|
|
|
|
|
|
const sendAnyway = await blockSendUntilConversationsAreVerified(
|
|
|
|
recipientsByConversation,
|
|
|
|
SafetyNumberChangeSource.MessageSend
|
|
|
|
);
|
|
|
|
if (!sendAnyway) {
|
|
|
|
dispatch(setComposerDisabledState(false));
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
} catch (error) {
|
|
|
|
dispatch(setComposerDisabledState(false));
|
|
|
|
log.error('sendMessage error:', Errors.toLogFormat(error));
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
conversation.clearTypingTimers();
|
|
|
|
|
|
|
|
const toastType = shouldShowInvalidMessageToast(conversation.attributes);
|
|
|
|
if (toastType) {
|
|
|
|
dispatch({
|
|
|
|
type: SHOW_TOAST,
|
|
|
|
payload: {
|
|
|
|
toastType,
|
|
|
|
},
|
|
|
|
});
|
2022-12-19 22:33:55 +00:00
|
|
|
dispatch(setComposerDisabledState(false));
|
2022-12-08 07:43:48 +00:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2022-12-19 22:33:55 +00:00
|
|
|
if (
|
|
|
|
!message.length &&
|
|
|
|
!hasDraftAttachments(conversation.attributes.draftAttachments, {
|
|
|
|
includePending: false,
|
|
|
|
}) &&
|
|
|
|
!voiceNoteAttachment
|
|
|
|
) {
|
|
|
|
dispatch(setComposerDisabledState(false));
|
|
|
|
return;
|
|
|
|
}
|
2022-12-08 07:43:48 +00:00
|
|
|
|
2022-12-19 22:33:55 +00:00
|
|
|
try {
|
2022-12-08 07:43:48 +00:00
|
|
|
let attachments: Array<AttachmentType> = [];
|
|
|
|
if (voiceNoteAttachment) {
|
|
|
|
attachments = [voiceNoteAttachment];
|
|
|
|
} else if (draftAttachments) {
|
|
|
|
attachments = (
|
|
|
|
await Promise.all(draftAttachments.map(resolveAttachmentDraftData))
|
|
|
|
).filter(isNotNil);
|
|
|
|
}
|
|
|
|
|
|
|
|
const quote = state.composer.quotedMessage?.quote;
|
|
|
|
|
|
|
|
const shouldSendHighQualityAttachments = window.reduxStore
|
|
|
|
? state.composer.shouldSendHighQualityAttachments
|
|
|
|
: undefined;
|
|
|
|
|
|
|
|
const sendHQImages =
|
|
|
|
shouldSendHighQualityAttachments !== undefined
|
|
|
|
? shouldSendHighQualityAttachments
|
|
|
|
: state.items['sent-media-quality'] === 'high';
|
|
|
|
|
|
|
|
const sendDelta = Date.now() - sendStart;
|
|
|
|
|
|
|
|
log.info('Send pre-checks took', sendDelta, 'milliseconds');
|
|
|
|
|
|
|
|
await conversation.enqueueMessageForSend(
|
|
|
|
{
|
|
|
|
body: message,
|
|
|
|
attachments,
|
|
|
|
quote,
|
|
|
|
preview: getLinkPreviewForSend(message),
|
|
|
|
mentions,
|
|
|
|
},
|
|
|
|
{
|
|
|
|
sendHQImages,
|
|
|
|
timestamp,
|
|
|
|
extraReduxActions: () => {
|
|
|
|
conversation.setMarkedUnread(false);
|
|
|
|
resetLinkPreview();
|
|
|
|
clearConversationDraftAttachments(conversationId, draftAttachments);
|
2022-12-09 19:11:14 +00:00
|
|
|
setQuoteByMessageId(conversationId, undefined)(
|
|
|
|
dispatch,
|
|
|
|
getState,
|
|
|
|
undefined
|
|
|
|
);
|
2022-12-08 07:43:48 +00:00
|
|
|
dispatch(resetComposer());
|
2022-12-19 22:33:55 +00:00
|
|
|
dispatch(setComposerDisabledState(false));
|
2022-12-08 07:43:48 +00:00
|
|
|
},
|
|
|
|
}
|
|
|
|
);
|
|
|
|
} catch (error) {
|
|
|
|
log.error(
|
|
|
|
'Error pulling attached files before send',
|
|
|
|
Errors.toLogFormat(error)
|
|
|
|
);
|
|
|
|
dispatch(setComposerDisabledState(false));
|
|
|
|
}
|
|
|
|
};
|
|
|
|
}
|
|
|
|
|
|
|
|
function sendStickerMessage(
|
|
|
|
conversationId: string,
|
|
|
|
options: {
|
|
|
|
packId: string;
|
|
|
|
stickerId: number;
|
|
|
|
}
|
|
|
|
): ThunkAction<
|
|
|
|
void,
|
|
|
|
RootStateType,
|
|
|
|
unknown,
|
|
|
|
NoopActionType | ShowToastActionType
|
|
|
|
> {
|
|
|
|
return async dispatch => {
|
|
|
|
const conversation = window.ConversationController.get(conversationId);
|
|
|
|
if (!conversation) {
|
|
|
|
throw new Error('sendStickerMessage: No conversation found');
|
|
|
|
}
|
|
|
|
|
|
|
|
const recipientsByConversation = getRecipientsByConversation([
|
|
|
|
conversation.attributes,
|
|
|
|
]);
|
|
|
|
|
|
|
|
try {
|
|
|
|
const sendAnyway = await blockSendUntilConversationsAreVerified(
|
|
|
|
recipientsByConversation,
|
|
|
|
SafetyNumberChangeSource.MessageSend
|
|
|
|
);
|
|
|
|
if (!sendAnyway) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
const toastType = shouldShowInvalidMessageToast(conversation.attributes);
|
|
|
|
if (toastType) {
|
|
|
|
dispatch({
|
|
|
|
type: SHOW_TOAST,
|
|
|
|
payload: {
|
|
|
|
toastType,
|
|
|
|
},
|
|
|
|
});
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
const { packId, stickerId } = options;
|
|
|
|
conversation.sendStickerMessage(packId, stickerId);
|
|
|
|
} catch (error) {
|
|
|
|
log.error('clickSend error:', Errors.toLogFormat(error));
|
|
|
|
}
|
|
|
|
|
|
|
|
dispatch({
|
|
|
|
type: 'NOOP',
|
|
|
|
payload: null,
|
|
|
|
});
|
|
|
|
};
|
|
|
|
}
|
|
|
|
|
2021-09-24 20:02:30 +00:00
|
|
|
// Not cool that we have to pull from ConversationModel here
|
|
|
|
// but if the current selected conversation isn't the one that we're operating
|
|
|
|
// on then we won't be able to grab attachments from state so we resort to the
|
|
|
|
// next in-memory store.
|
|
|
|
function getAttachmentsFromConversationModel(
|
|
|
|
conversationId: string
|
2021-11-15 21:54:33 +00:00
|
|
|
): Array<AttachmentDraftType> {
|
2021-09-24 20:02:30 +00:00
|
|
|
const conversation = window.ConversationController.get(conversationId);
|
|
|
|
return conversation?.get('draftAttachments') || [];
|
|
|
|
}
|
|
|
|
|
2022-12-09 19:11:14 +00:00
|
|
|
function setQuoteByMessageId(
|
|
|
|
conversationId: string,
|
|
|
|
messageId: string | undefined
|
|
|
|
): ThunkAction<
|
|
|
|
void,
|
|
|
|
RootStateType,
|
|
|
|
unknown,
|
|
|
|
SetComposerDisabledStateActionType | SetQuotedMessageActionType
|
|
|
|
> {
|
|
|
|
return async (dispatch, getState) => {
|
|
|
|
const conversation = window.ConversationController.get(conversationId);
|
|
|
|
if (!conversation) {
|
|
|
|
throw new Error('sendStickerMessage: No conversation found');
|
|
|
|
}
|
|
|
|
|
|
|
|
const message = messageId ? await getMessageById(messageId) : undefined;
|
|
|
|
const state = getState();
|
|
|
|
|
|
|
|
if (
|
|
|
|
message &&
|
|
|
|
!canReply(
|
|
|
|
message.attributes,
|
|
|
|
window.ConversationController.getOurConversationIdOrThrow(),
|
|
|
|
getConversationSelector(state)
|
|
|
|
)
|
|
|
|
) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (message && !message.isNormalBubble()) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
const existing = conversation.get('quotedMessageId');
|
|
|
|
if (existing !== messageId) {
|
|
|
|
const now = Date.now();
|
|
|
|
let activeAt = conversation.get('active_at');
|
|
|
|
let timestamp = conversation.get('timestamp');
|
|
|
|
|
|
|
|
if (!activeAt && messageId) {
|
|
|
|
activeAt = now;
|
|
|
|
timestamp = now;
|
|
|
|
}
|
|
|
|
|
|
|
|
conversation.set({
|
|
|
|
active_at: activeAt,
|
|
|
|
draftChanged: true,
|
|
|
|
quotedMessageId: messageId,
|
|
|
|
timestamp,
|
|
|
|
});
|
|
|
|
|
|
|
|
window.Signal.Data.updateConversation(conversation.attributes);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (message) {
|
|
|
|
const quote = await conversation.makeQuote(message);
|
|
|
|
dispatch(
|
|
|
|
setQuotedMessage({
|
|
|
|
conversationId,
|
|
|
|
quote,
|
|
|
|
})
|
|
|
|
);
|
|
|
|
|
|
|
|
dispatch(setComposerFocus(conversation.id));
|
|
|
|
dispatch(setComposerDisabledState(false));
|
|
|
|
} else {
|
|
|
|
dispatch(setQuotedMessage(undefined));
|
|
|
|
}
|
|
|
|
};
|
|
|
|
}
|
|
|
|
|
2021-09-24 20:02:30 +00:00
|
|
|
function addAttachment(
|
|
|
|
conversationId: string,
|
2021-11-15 21:54:33 +00:00
|
|
|
attachment: InMemoryAttachmentDraftType
|
2021-09-24 20:02:30 +00:00
|
|
|
): ThunkAction<void, RootStateType, unknown, ReplaceAttachmentsActionType> {
|
|
|
|
return async (dispatch, getState) => {
|
2021-11-04 01:38:46 +00:00
|
|
|
// We do async operations first so multiple in-process addAttachments don't stomp on
|
|
|
|
// each other.
|
|
|
|
const onDisk = await writeDraftAttachment(attachment);
|
|
|
|
|
2021-09-24 20:02:30 +00:00
|
|
|
const isSelectedConversation =
|
|
|
|
getState().conversations.selectedConversationId === conversationId;
|
|
|
|
|
|
|
|
const draftAttachments = isSelectedConversation
|
|
|
|
? getState().composer.attachments
|
|
|
|
: getAttachmentsFromConversationModel(conversationId);
|
|
|
|
|
2021-12-01 02:14:25 +00:00
|
|
|
// We expect there to either be a pending draft attachment or an existing
|
|
|
|
// attachment that we'll be replacing.
|
2021-09-24 20:02:30 +00:00
|
|
|
const hasDraftAttachmentPending = draftAttachments.some(
|
2021-12-01 02:14:25 +00:00
|
|
|
draftAttachment => draftAttachment.path === attachment.path
|
2021-09-24 20:02:30 +00:00
|
|
|
);
|
|
|
|
|
|
|
|
// User has canceled the draft so we don't need to continue processing
|
|
|
|
if (!hasDraftAttachmentPending) {
|
2021-11-04 01:38:46 +00:00
|
|
|
await deleteDraftAttachment(onDisk);
|
2021-09-24 20:02:30 +00:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Remove any pending attachments that were transcoding
|
|
|
|
const index = draftAttachments.findIndex(
|
|
|
|
draftAttachment => draftAttachment.path === attachment.path
|
|
|
|
);
|
|
|
|
let nextAttachments = draftAttachments;
|
|
|
|
if (index < 0) {
|
|
|
|
log.warn(
|
|
|
|
`addAttachment: Failed to find pending attachment with path ${attachment.path}`
|
|
|
|
);
|
|
|
|
nextAttachments = [...draftAttachments, onDisk];
|
|
|
|
} else {
|
|
|
|
nextAttachments = replaceIndex(draftAttachments, index, onDisk);
|
|
|
|
}
|
|
|
|
|
|
|
|
replaceAttachments(conversationId, nextAttachments)(
|
|
|
|
dispatch,
|
|
|
|
getState,
|
|
|
|
null
|
|
|
|
);
|
|
|
|
|
|
|
|
const conversation = window.ConversationController.get(conversationId);
|
|
|
|
if (conversation) {
|
|
|
|
conversation.attributes.draftAttachments = nextAttachments;
|
|
|
|
window.Signal.Data.updateConversation(conversation.attributes);
|
|
|
|
}
|
|
|
|
};
|
|
|
|
}
|
|
|
|
|
|
|
|
function addPendingAttachment(
|
|
|
|
conversationId: string,
|
2021-11-15 21:54:33 +00:00
|
|
|
pendingAttachment: AttachmentDraftType
|
2021-09-24 20:02:30 +00:00
|
|
|
): ThunkAction<void, RootStateType, unknown, ReplaceAttachmentsActionType> {
|
|
|
|
return (dispatch, getState) => {
|
|
|
|
const isSelectedConversation =
|
|
|
|
getState().conversations.selectedConversationId === conversationId;
|
|
|
|
|
|
|
|
const draftAttachments = isSelectedConversation
|
|
|
|
? getState().composer.attachments
|
|
|
|
: getAttachmentsFromConversationModel(conversationId);
|
|
|
|
|
|
|
|
const nextAttachments = [...draftAttachments, pendingAttachment];
|
|
|
|
|
|
|
|
dispatch({
|
|
|
|
type: REPLACE_ATTACHMENTS,
|
|
|
|
payload: nextAttachments,
|
|
|
|
});
|
|
|
|
|
|
|
|
const conversation = window.ConversationController.get(conversationId);
|
|
|
|
if (conversation) {
|
|
|
|
conversation.attributes.draftAttachments = nextAttachments;
|
|
|
|
window.Signal.Data.updateConversation(conversation.attributes);
|
|
|
|
}
|
|
|
|
};
|
|
|
|
}
|
|
|
|
|
2022-12-08 23:56:17 +00:00
|
|
|
function setComposerFocus(
|
|
|
|
conversationId: string
|
|
|
|
): ThunkAction<void, RootStateType, unknown, SetFocusActionType> {
|
|
|
|
return async (dispatch, getState) => {
|
|
|
|
if (getState().conversations.selectedConversationId !== conversationId) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
dispatch({
|
|
|
|
type: SET_FOCUS,
|
|
|
|
});
|
|
|
|
};
|
|
|
|
}
|
|
|
|
|
|
|
|
function onEditorStateChange(
|
|
|
|
conversationId: string | undefined,
|
|
|
|
messageText: string,
|
|
|
|
bodyRanges: DraftBodyRangesType,
|
|
|
|
caretLocation?: number
|
|
|
|
): NoopActionType {
|
|
|
|
if (!conversationId) {
|
|
|
|
throw new Error(
|
|
|
|
'onEditorStateChange: Got falsey conversationId, needs local override'
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
|
|
|
const conversation = window.ConversationController.get(conversationId);
|
|
|
|
if (!conversation) {
|
|
|
|
throw new Error('processAttachments: Unable to find conversation');
|
|
|
|
}
|
|
|
|
|
|
|
|
if (messageText.length && conversation.throttledBumpTyping) {
|
|
|
|
conversation.throttledBumpTyping();
|
|
|
|
}
|
|
|
|
|
|
|
|
debouncedSaveDraft(conversationId, messageText, bodyRanges);
|
|
|
|
|
|
|
|
// If we have attachments, don't add link preview
|
|
|
|
if (!hasDraftAttachments(conversation.attributes, { includePending: true })) {
|
|
|
|
maybeGrabLinkPreview(messageText, LinkPreviewSourceType.Composer, {
|
|
|
|
caretLocation,
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
return {
|
|
|
|
type: 'NOOP',
|
|
|
|
payload: null,
|
|
|
|
};
|
|
|
|
}
|
|
|
|
|
2022-12-08 01:26:59 +00:00
|
|
|
function processAttachments({
|
|
|
|
conversationId,
|
|
|
|
files,
|
|
|
|
}: {
|
|
|
|
conversationId: string;
|
|
|
|
files: ReadonlyArray<File>;
|
|
|
|
}): ThunkAction<
|
|
|
|
void,
|
|
|
|
RootStateType,
|
|
|
|
unknown,
|
|
|
|
NoopActionType | ShowToastActionType
|
|
|
|
> {
|
|
|
|
return async (dispatch, getState) => {
|
|
|
|
if (!files.length) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
// If the call came from a conversation we are no longer in we do not
|
|
|
|
// update the state.
|
|
|
|
if (getState().conversations.selectedConversationId !== conversationId) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
const conversation = window.ConversationController.get(conversationId);
|
|
|
|
if (!conversation) {
|
|
|
|
throw new Error('processAttachments: Unable to find conv');
|
|
|
|
}
|
|
|
|
|
|
|
|
const state = getState();
|
|
|
|
const isRecording =
|
|
|
|
state.audioRecorder.recordingState === RecordingState.Recording;
|
|
|
|
|
|
|
|
if (hasLinkPreviewLoaded() || isRecording) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
let toastToShow:
|
|
|
|
| { toastType: ToastType; parameters?: ReplacementValuesType }
|
|
|
|
| undefined;
|
|
|
|
|
|
|
|
const nextDraftAttachments = (
|
|
|
|
conversation.get('draftAttachments') || []
|
|
|
|
).slice();
|
|
|
|
const filesToProcess: Array<File> = [];
|
|
|
|
for (let i = 0; i < files.length; i += 1) {
|
|
|
|
const file = files[i];
|
|
|
|
const processingResult = preProcessAttachment(file, nextDraftAttachments);
|
|
|
|
if (processingResult != null) {
|
|
|
|
toastToShow = processingResult;
|
|
|
|
} else {
|
|
|
|
const pendingAttachment = getPendingAttachment(file);
|
|
|
|
if (pendingAttachment) {
|
|
|
|
addPendingAttachment(conversationId, pendingAttachment)(
|
|
|
|
dispatch,
|
|
|
|
getState,
|
|
|
|
undefined
|
|
|
|
);
|
|
|
|
filesToProcess.push(file);
|
|
|
|
// we keep a running count of the draft attachments so we can show a
|
|
|
|
// toast in case we add too many attachments at once
|
|
|
|
nextDraftAttachments.push(pendingAttachment);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
await Promise.all(
|
|
|
|
filesToProcess.map(async file => {
|
|
|
|
try {
|
|
|
|
const attachment = await processAttachment(file);
|
|
|
|
if (!attachment) {
|
|
|
|
removeAttachment(conversationId, file.path)(
|
|
|
|
dispatch,
|
|
|
|
getState,
|
|
|
|
undefined
|
|
|
|
);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
addAttachment(conversationId, attachment)(
|
|
|
|
dispatch,
|
|
|
|
getState,
|
|
|
|
undefined
|
|
|
|
);
|
|
|
|
} catch (err) {
|
|
|
|
log.error(
|
|
|
|
'handleAttachmentsProcessing: failed to process attachment:',
|
|
|
|
err.stack
|
|
|
|
);
|
|
|
|
removeAttachment(conversationId, file.path)(
|
|
|
|
dispatch,
|
|
|
|
getState,
|
|
|
|
undefined
|
|
|
|
);
|
|
|
|
toastToShow = { toastType: ToastType.UnableToLoadAttachment };
|
|
|
|
}
|
|
|
|
})
|
|
|
|
);
|
|
|
|
|
|
|
|
if (toastToShow) {
|
|
|
|
dispatch({
|
|
|
|
type: SHOW_TOAST,
|
|
|
|
payload: toastToShow,
|
|
|
|
});
|
|
|
|
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2021-09-24 20:02:30 +00:00
|
|
|
dispatch({
|
|
|
|
type: 'NOOP',
|
|
|
|
payload: null,
|
|
|
|
});
|
|
|
|
};
|
|
|
|
}
|
|
|
|
|
2022-12-08 01:26:59 +00:00
|
|
|
function preProcessAttachment(
|
|
|
|
file: File,
|
|
|
|
draftAttachments: Array<AttachmentDraftType>
|
|
|
|
): { toastType: ToastType; parameters?: ReplacementValuesType } | undefined {
|
|
|
|
if (!file) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
const limitKb = getMaximumAttachmentSize();
|
|
|
|
if (file.size > limitKb) {
|
|
|
|
return {
|
|
|
|
toastType: ToastType.FileSize,
|
|
|
|
parameters: getRenderDetailsForLimit(limitKb),
|
|
|
|
};
|
|
|
|
}
|
|
|
|
|
|
|
|
if (isFileDangerous(file.name)) {
|
|
|
|
return { toastType: ToastType.DangerousFileType };
|
|
|
|
}
|
|
|
|
|
|
|
|
if (draftAttachments.length >= 32) {
|
|
|
|
return { toastType: ToastType.MaxAttachments };
|
|
|
|
}
|
|
|
|
|
|
|
|
const haveNonImageOrVideo = draftAttachments.some(
|
|
|
|
(attachment: AttachmentDraftType) => {
|
|
|
|
return (
|
|
|
|
!isImage(attachment.contentType) && !isVideo(attachment.contentType)
|
|
|
|
);
|
|
|
|
}
|
|
|
|
);
|
|
|
|
// You can't add another attachment if you already have a non-image staged
|
|
|
|
if (haveNonImageOrVideo) {
|
|
|
|
return { toastType: ToastType.UnsupportedMultiAttachment };
|
|
|
|
}
|
|
|
|
|
|
|
|
const fileType = stringToMIMEType(file.type);
|
|
|
|
const imageOrVideo = isImage(fileType) || isVideo(fileType);
|
|
|
|
|
|
|
|
// You can't add a non-image attachment if you already have attachments staged
|
|
|
|
if (!imageOrVideo && draftAttachments.length > 0) {
|
|
|
|
return { toastType: ToastType.CannotMixMultiAndNonMultiAttachments };
|
|
|
|
}
|
|
|
|
|
|
|
|
return undefined;
|
|
|
|
}
|
|
|
|
|
|
|
|
function getPendingAttachment(file: File): AttachmentDraftType | undefined {
|
|
|
|
if (!file) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
const fileType = stringToMIMEType(file.type);
|
|
|
|
const { name: fileName } = path.parse(file.name);
|
|
|
|
|
|
|
|
return {
|
|
|
|
contentType: fileType,
|
|
|
|
fileName,
|
|
|
|
size: file.size,
|
|
|
|
path: file.name,
|
|
|
|
pending: true,
|
|
|
|
};
|
|
|
|
}
|
|
|
|
|
2021-09-24 20:02:30 +00:00
|
|
|
function removeAttachment(
|
|
|
|
conversationId: string,
|
|
|
|
filePath: string
|
|
|
|
): ThunkAction<void, RootStateType, unknown, ReplaceAttachmentsActionType> {
|
2021-11-04 01:38:46 +00:00
|
|
|
return async (dispatch, getState) => {
|
2021-09-24 20:02:30 +00:00
|
|
|
const { attachments } = getState().composer;
|
|
|
|
|
2021-11-04 01:38:46 +00:00
|
|
|
const [targetAttachment] = attachments.filter(
|
|
|
|
attachment => attachment.path === filePath
|
|
|
|
);
|
|
|
|
if (!targetAttachment) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2021-09-24 20:02:30 +00:00
|
|
|
const nextAttachments = attachments.filter(
|
|
|
|
attachment => attachment.path !== filePath
|
|
|
|
);
|
|
|
|
|
|
|
|
const conversation = window.ConversationController.get(conversationId);
|
|
|
|
if (conversation) {
|
|
|
|
conversation.attributes.draftAttachments = nextAttachments;
|
|
|
|
conversation.attributes.draftChanged = true;
|
|
|
|
window.Signal.Data.updateConversation(conversation.attributes);
|
|
|
|
}
|
|
|
|
|
|
|
|
replaceAttachments(conversationId, nextAttachments)(
|
|
|
|
dispatch,
|
|
|
|
getState,
|
|
|
|
null
|
|
|
|
);
|
2021-11-04 01:38:46 +00:00
|
|
|
|
|
|
|
if (
|
|
|
|
targetAttachment.path &&
|
|
|
|
targetAttachment.fileName !== targetAttachment.path
|
|
|
|
) {
|
|
|
|
await deleteDraftAttachment(targetAttachment);
|
|
|
|
}
|
2021-09-24 20:02:30 +00:00
|
|
|
};
|
|
|
|
}
|
|
|
|
|
2021-06-25 16:08:16 +00:00
|
|
|
function replaceAttachments(
|
2021-08-09 20:06:21 +00:00
|
|
|
conversationId: string,
|
2021-11-15 21:54:33 +00:00
|
|
|
attachments: ReadonlyArray<AttachmentDraftType>
|
2021-08-09 20:06:21 +00:00
|
|
|
): ThunkAction<void, RootStateType, unknown, ReplaceAttachmentsActionType> {
|
|
|
|
return (dispatch, getState) => {
|
|
|
|
// If the call came from a conversation we are no longer in we do not
|
|
|
|
// update the state.
|
|
|
|
if (getState().conversations.selectedConversationId !== conversationId) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2022-12-14 19:05:32 +00:00
|
|
|
if (hasDraftAttachments(attachments, { includePending: true })) {
|
|
|
|
removeLinkPreview();
|
|
|
|
}
|
|
|
|
|
2021-08-09 20:06:21 +00:00
|
|
|
dispatch({
|
|
|
|
type: REPLACE_ATTACHMENTS,
|
2021-11-15 21:54:33 +00:00
|
|
|
payload: attachments.map(resolveDraftAttachmentOnDisk),
|
2021-08-09 20:06:21 +00:00
|
|
|
});
|
2021-06-25 16:08:16 +00:00
|
|
|
};
|
|
|
|
}
|
|
|
|
|
2022-12-20 01:04:47 +00:00
|
|
|
function reactToMessage(
|
|
|
|
messageId: string,
|
|
|
|
reaction: { emoji: string; remove: boolean }
|
|
|
|
): ThunkAction<
|
|
|
|
void,
|
|
|
|
RootStateType,
|
|
|
|
unknown,
|
|
|
|
NoopActionType | ShowToastActionType
|
|
|
|
> {
|
|
|
|
return async dispatch => {
|
|
|
|
const { emoji, remove } = reaction;
|
|
|
|
try {
|
|
|
|
await enqueueReactionForSend({
|
|
|
|
messageId,
|
|
|
|
emoji,
|
|
|
|
remove,
|
|
|
|
});
|
|
|
|
dispatch({
|
|
|
|
type: 'NOOP',
|
|
|
|
payload: null,
|
|
|
|
});
|
|
|
|
} catch (error) {
|
|
|
|
log.error(
|
|
|
|
'reactToMessage: Error sending reaction',
|
|
|
|
error,
|
|
|
|
messageId,
|
|
|
|
reaction
|
|
|
|
);
|
|
|
|
dispatch({
|
|
|
|
type: SHOW_TOAST,
|
|
|
|
payload: {
|
|
|
|
toastType: ToastType.ReactionFailed,
|
|
|
|
},
|
|
|
|
});
|
|
|
|
}
|
|
|
|
};
|
|
|
|
}
|
|
|
|
|
2021-06-25 16:08:16 +00:00
|
|
|
function resetComposer(): ResetComposerActionType {
|
|
|
|
return {
|
|
|
|
type: RESET_COMPOSER,
|
|
|
|
};
|
|
|
|
}
|
2022-12-08 23:56:17 +00:00
|
|
|
const debouncedSaveDraft = debounce(saveDraft);
|
|
|
|
|
|
|
|
function saveDraft(
|
|
|
|
conversationId: string,
|
|
|
|
messageText: string,
|
|
|
|
bodyRanges: DraftBodyRangesType
|
|
|
|
) {
|
|
|
|
const conversation = window.ConversationController.get(conversationId);
|
|
|
|
if (!conversation) {
|
|
|
|
throw new Error('saveDraft: Unable to find conversation');
|
|
|
|
}
|
|
|
|
|
|
|
|
const trimmed =
|
|
|
|
messageText && messageText.length > 0 ? messageText.trim() : '';
|
|
|
|
|
|
|
|
if (conversation.get('draft') && (!messageText || trimmed.length === 0)) {
|
|
|
|
conversation.set({
|
|
|
|
draft: null,
|
|
|
|
draftChanged: true,
|
|
|
|
draftBodyRanges: [],
|
|
|
|
});
|
|
|
|
window.Signal.Data.updateConversation(conversation.attributes);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (messageText !== conversation.get('draft')) {
|
|
|
|
const now = Date.now();
|
|
|
|
let activeAt = conversation.get('active_at');
|
|
|
|
let timestamp = conversation.get('timestamp');
|
|
|
|
|
|
|
|
if (!activeAt) {
|
|
|
|
activeAt = now;
|
|
|
|
timestamp = now;
|
|
|
|
}
|
|
|
|
|
|
|
|
conversation.set({
|
|
|
|
active_at: activeAt,
|
|
|
|
draft: messageText,
|
|
|
|
draftBodyRanges: bodyRanges,
|
|
|
|
draftChanged: true,
|
|
|
|
timestamp,
|
|
|
|
});
|
|
|
|
window.Signal.Data.updateConversation(conversation.attributes);
|
|
|
|
}
|
|
|
|
}
|
2021-06-25 16:08:16 +00:00
|
|
|
|
2022-12-08 07:43:48 +00:00
|
|
|
function setComposerDisabledState(
|
|
|
|
value: boolean
|
|
|
|
): SetComposerDisabledStateActionType {
|
|
|
|
return {
|
|
|
|
type: SET_COMPOSER_DISABLED,
|
|
|
|
payload: value,
|
|
|
|
};
|
|
|
|
}
|
|
|
|
|
2021-06-25 16:08:16 +00:00
|
|
|
function setMediaQualitySetting(
|
|
|
|
payload: boolean
|
|
|
|
): SetHighQualitySettingActionType {
|
|
|
|
return {
|
|
|
|
type: SET_HIGH_QUALITY_SETTING,
|
|
|
|
payload,
|
|
|
|
};
|
|
|
|
}
|
|
|
|
|
|
|
|
function setQuotedMessage(
|
2022-11-30 21:47:54 +00:00
|
|
|
payload?: Pick<MessageAttributesType, 'conversationId' | 'quote' | 'payment'>
|
2021-06-25 16:08:16 +00:00
|
|
|
): SetQuotedMessageActionType {
|
|
|
|
return {
|
|
|
|
type: SET_QUOTED_MESSAGE,
|
|
|
|
payload,
|
|
|
|
};
|
|
|
|
}
|
|
|
|
|
|
|
|
// Reducer
|
|
|
|
|
|
|
|
export function getEmptyState(): ComposerStateType {
|
|
|
|
return {
|
|
|
|
attachments: [],
|
2022-12-08 23:56:17 +00:00
|
|
|
focusCounter: 0,
|
2022-12-08 07:43:48 +00:00
|
|
|
isDisabled: false,
|
2021-06-25 16:08:16 +00:00
|
|
|
linkPreviewLoading: false,
|
2022-12-08 07:43:48 +00:00
|
|
|
messageCompositionId: UUID.generate().toString(),
|
2021-06-25 16:08:16 +00:00
|
|
|
};
|
|
|
|
}
|
|
|
|
|
|
|
|
export function reducer(
|
|
|
|
state: Readonly<ComposerStateType> = getEmptyState(),
|
|
|
|
action: Readonly<ComposerActionType>
|
|
|
|
): ComposerStateType {
|
|
|
|
if (action.type === RESET_COMPOSER) {
|
|
|
|
return getEmptyState();
|
|
|
|
}
|
|
|
|
|
|
|
|
if (action.type === REPLACE_ATTACHMENTS) {
|
|
|
|
const { payload: attachments } = action;
|
|
|
|
return {
|
|
|
|
...state,
|
|
|
|
attachments,
|
|
|
|
...(attachments.length
|
|
|
|
? {}
|
2022-12-02 23:54:37 +00:00
|
|
|
: { shouldSendHighQualityAttachments: undefined }),
|
2021-06-25 16:08:16 +00:00
|
|
|
};
|
|
|
|
}
|
|
|
|
|
2022-12-08 23:56:17 +00:00
|
|
|
if (action.type === SET_FOCUS) {
|
|
|
|
return {
|
|
|
|
...state,
|
|
|
|
focusCounter: state.focusCounter + 1,
|
|
|
|
};
|
|
|
|
}
|
|
|
|
|
2021-06-25 16:08:16 +00:00
|
|
|
if (action.type === SET_HIGH_QUALITY_SETTING) {
|
|
|
|
return {
|
|
|
|
...state,
|
|
|
|
shouldSendHighQualityAttachments: action.payload,
|
|
|
|
};
|
|
|
|
}
|
|
|
|
|
|
|
|
if (action.type === SET_QUOTED_MESSAGE) {
|
|
|
|
return {
|
|
|
|
...state,
|
|
|
|
quotedMessage: action.payload,
|
|
|
|
};
|
|
|
|
}
|
|
|
|
|
2022-06-17 00:48:57 +00:00
|
|
|
if (action.type === ADD_LINK_PREVIEW) {
|
|
|
|
if (action.payload.source !== LinkPreviewSourceType.Composer) {
|
|
|
|
return state;
|
|
|
|
}
|
|
|
|
|
2021-06-25 16:08:16 +00:00
|
|
|
return {
|
|
|
|
...state,
|
2022-06-17 00:48:57 +00:00
|
|
|
linkPreviewLoading: true,
|
2021-06-25 16:08:16 +00:00
|
|
|
linkPreviewResult: action.payload.linkPreview,
|
|
|
|
};
|
|
|
|
}
|
|
|
|
|
2021-08-18 13:34:22 +00:00
|
|
|
if (action.type === REMOVE_LINK_PREVIEW) {
|
|
|
|
return assignWithNoUnnecessaryAllocation(state, {
|
|
|
|
linkPreviewLoading: false,
|
|
|
|
linkPreviewResult: undefined,
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
2021-09-24 20:02:30 +00:00
|
|
|
if (action.type === ADD_PENDING_ATTACHMENT) {
|
|
|
|
return {
|
|
|
|
...state,
|
|
|
|
attachments: [...state.attachments, action.payload],
|
|
|
|
};
|
|
|
|
}
|
|
|
|
|
2022-12-08 07:43:48 +00:00
|
|
|
if (action.type === SET_COMPOSER_DISABLED) {
|
|
|
|
return {
|
|
|
|
...state,
|
|
|
|
isDisabled: action.payload,
|
|
|
|
};
|
|
|
|
}
|
|
|
|
|
2021-06-25 16:08:16 +00:00
|
|
|
return state;
|
|
|
|
}
|