From 7c747c28b6eaf6854202af7ad2fdffd5c6003812 Mon Sep 17 00:00:00 2001 From: Erin A Date: Thu, 30 Nov 2023 00:49:20 -0800 Subject: [PATCH] [MM-54529] Prevent Persistent Notifications Error Message for DM Channel (#7648) * Update index.ts persistentNotifications to include param and conditions for channelType * Update message for "no recipients mentioned" to not occur for `DM_CHANNEL`. * Update send message to either start with "Recipients" for DM channel or "@mentioned recipients" * Include `channelType` in call to `persistentNotificationsConfirmation` * Fix typo in persisten(t)NotificationsEnabled * Remove ternary in translatable string * Add channelType to callback's dependencies * Make channelType optional --- app/components/post_draft/draft_input/index.tsx | 12 ++++++------ app/utils/post/index.ts | 6 +++--- 2 files changed, 9 insertions(+), 9 deletions(-) diff --git a/app/components/post_draft/draft_input/index.tsx b/app/components/post_draft/draft_input/index.tsx index cb3c5c77c..fdabc65f1 100644 --- a/app/components/post_draft/draft_input/index.tsx +++ b/app/components/post_draft/draft_input/index.tsx @@ -147,28 +147,28 @@ export default function DraftInput({ const sendActionTestID = `${testID}.send_action`; const style = getStyleSheet(theme); - const persistenNotificationsEnabled = postPriority.persistent_notifications && postPriority.priority === PostPriorityType.URGENT; + const persistentNotificationsEnabled = postPriority.persistent_notifications && postPriority.priority === PostPriorityType.URGENT; const {noMentionsError, mentionsList} = useMemo(() => { let error = false; let mentions: string[] = []; if ( channelType !== General.DM_CHANNEL && - persistenNotificationsEnabled + persistentNotificationsEnabled ) { mentions = (value.match(MENTIONS_REGEX) || []); error = mentions.length === 0; } return {noMentionsError: error, mentionsList: mentions}; - }, [channelType, persistenNotificationsEnabled, value]); + }, [channelType, persistentNotificationsEnabled, value]); const handleSendMessage = useCallback(async () => { - if (persistenNotificationsEnabled) { - persistentNotificationsConfirmation(serverUrl, value, mentionsList, intl, sendMessage, persistentNotificationMaxRecipients, persistentNotificationInterval); + if (persistentNotificationsEnabled) { + persistentNotificationsConfirmation(serverUrl, value, mentionsList, intl, sendMessage, persistentNotificationMaxRecipients, persistentNotificationInterval, channelType); } else { sendMessage(); } - }, [serverUrl, mentionsList, persistenNotificationsEnabled, persistentNotificationMaxRecipients, sendMessage, value]); + }, [serverUrl, mentionsList, persistentNotificationsEnabled, persistentNotificationMaxRecipients, sendMessage, value, channelType]); const sendActionDisabled = !canSend || noMentionsError; diff --git a/app/utils/post/index.ts b/app/utils/post/index.ts index 830a23cfb..a155ea174 100644 --- a/app/utils/post/index.ts +++ b/app/utils/post/index.ts @@ -4,7 +4,7 @@ import {Alert, type AlertButton} from 'react-native'; import {getUsersCountFromMentions} from '@actions/local/post'; -import {Post} from '@constants'; +import {General, Post} from '@constants'; import {SPECIAL_MENTIONS_REGEX} from '@constants/autocomplete'; import {POST_TIME_TO_FAIL} from '@constants/post'; import {DEFAULT_LOCALE} from '@i18n'; @@ -104,7 +104,7 @@ export function hasSpecialMentions(message: string): boolean { return result; } -export async function persistentNotificationsConfirmation(serverUrl: string, value: string, mentionsList: string[], intl: IntlShape, sendMessage: () => void, persistentNotificationMaxRecipients: number, persistentNotificationInterval: number) { +export async function persistentNotificationsConfirmation(serverUrl: string, value: string, mentionsList: string[], intl: IntlShape, sendMessage: () => void, persistentNotificationMaxRecipients: number, persistentNotificationInterval: number, channelType?: ChannelType) { let title = ''; let description = ''; let buttons: AlertButton[] = [{ @@ -136,7 +136,7 @@ export async function persistentNotificationsConfirmation(serverUrl: string, val max: persistentNotificationMaxRecipients, count: mentionsList.length, }); - } else if (usersCount === 0) { + } else if (usersCount === 0 && channelType !== General.DM_CHANNEL) { title = intl.formatMessage({ id: 'persistent_notifications.error.no_mentions.title', defaultMessage: 'Recipients must be @mentioned',