Moves sendMessage and friends to redux
This commit is contained in:
parent
7ea38bb1a9
commit
2378776e1b
27 changed files with 517 additions and 537 deletions
62
ts/util/shouldShowInvalidMessageToast.ts
Normal file
62
ts/util/shouldShowInvalidMessageToast.ts
Normal file
|
@ -0,0 +1,62 @@
|
|||
// Copyright 2021 Signal Messenger, LLC
|
||||
// SPDX-License-Identifier: AGPL-3.0-only
|
||||
|
||||
import type { ConversationAttributesType } from '../model-types';
|
||||
|
||||
import { ToastType } from '../state/ducks/toast';
|
||||
import {
|
||||
isDirectConversation,
|
||||
isGroupV1,
|
||||
isGroupV2,
|
||||
} from './whatTypeOfConversation';
|
||||
|
||||
const MAX_MESSAGE_BODY_LENGTH = 64 * 1024;
|
||||
|
||||
export function shouldShowInvalidMessageToast(
|
||||
conversationAttributes: ConversationAttributesType,
|
||||
messageText?: string
|
||||
): ToastType | undefined {
|
||||
if (window.reduxStore.getState().expiration.hasExpired) {
|
||||
return ToastType.Expired;
|
||||
}
|
||||
|
||||
const isValid =
|
||||
isDirectConversation(conversationAttributes) ||
|
||||
isGroupV1(conversationAttributes) ||
|
||||
isGroupV2(conversationAttributes);
|
||||
|
||||
if (!isValid) {
|
||||
return ToastType.InvalidConversation;
|
||||
}
|
||||
|
||||
const { e164, uuid } = conversationAttributes;
|
||||
if (
|
||||
isDirectConversation(conversationAttributes) &&
|
||||
((e164 && window.storage.blocked.isBlocked(e164)) ||
|
||||
(uuid && window.storage.blocked.isUuidBlocked(uuid)))
|
||||
) {
|
||||
return ToastType.Blocked;
|
||||
}
|
||||
|
||||
const { groupId } = conversationAttributes;
|
||||
if (
|
||||
!isDirectConversation(conversationAttributes) &&
|
||||
groupId &&
|
||||
window.storage.blocked.isGroupBlocked(groupId)
|
||||
) {
|
||||
return ToastType.BlockedGroup;
|
||||
}
|
||||
|
||||
if (
|
||||
!isDirectConversation(conversationAttributes) &&
|
||||
conversationAttributes.left
|
||||
) {
|
||||
return ToastType.LeftGroup;
|
||||
}
|
||||
|
||||
if (messageText && messageText.length > MAX_MESSAGE_BODY_LENGTH) {
|
||||
return ToastType.MessageBodyTooLong;
|
||||
}
|
||||
|
||||
return undefined;
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue