[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
This commit is contained in:
parent
1fc0611f04
commit
7c747c28b6
2 changed files with 9 additions and 9 deletions
|
|
@ -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;
|
||||
|
||||
|
|
|
|||
|
|
@ -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',
|
||||
|
|
|
|||
Loading…
Reference in a new issue