diff --git a/app/components/post_draft/draft_input/index.tsx b/app/components/post_draft/draft_input/index.tsx index fdabc65f1..4a2e4e7b4 100644 --- a/app/components/post_draft/draft_input/index.tsx +++ b/app/components/post_draft/draft_input/index.tsx @@ -28,6 +28,7 @@ type Props = { testID?: string; channelId: string; channelType?: ChannelType; + channelName?: string; rootId?: string; currentUserId: string; canShowPostPriority?: boolean; @@ -108,6 +109,7 @@ export default function DraftInput({ testID, channelId, channelType, + channelName, currentUserId, canShowPostPriority, files, @@ -164,7 +166,7 @@ export default function DraftInput({ const handleSendMessage = useCallback(async () => { if (persistentNotificationsEnabled) { - persistentNotificationsConfirmation(serverUrl, value, mentionsList, intl, sendMessage, persistentNotificationMaxRecipients, persistentNotificationInterval, channelType); + persistentNotificationsConfirmation(serverUrl, value, mentionsList, intl, sendMessage, persistentNotificationMaxRecipients, persistentNotificationInterval, currentUserId, channelName, channelType); } else { sendMessage(); } diff --git a/app/components/post_draft/send_handler/index.ts b/app/components/post_draft/send_handler/index.ts index bcbd82b33..40117521b 100644 --- a/app/components/post_draft/send_handler/index.ts +++ b/app/components/post_draft/send_handler/index.ts @@ -55,7 +55,7 @@ const enhanced = withObservables([], (ownProps: WithDatabaseArgs & OwnProps) => const enableConfirmNotificationsToChannel = observeConfigBooleanValue(database, 'EnableConfirmNotificationsToChannel'); const maxMessageLength = observeConfigIntValue(database, 'MaxPostSize', MAX_MESSAGE_LENGTH_FALLBACK); - const persistentNotificationInterval = observeConfigIntValue(database, 'PersistentNotificationInterval'); + const persistentNotificationInterval = observeConfigIntValue(database, 'PersistentNotificationIntervalMinutes'); const persistentNotificationMaxRecipients = observeConfigIntValue(database, 'PersistentNotificationMaxRecipients'); const useChannelMentions = combineLatest([channel, currentUser]).pipe( @@ -70,6 +70,7 @@ const enhanced = withObservables([], (ownProps: WithDatabaseArgs & OwnProps) => const channelInfo = channel.pipe(switchMap((c) => (c ? observeChannelInfo(database, c.id) : of$(undefined)))); const channelType = channel.pipe(switchMap((c) => of$(c?.type))); + const channelName = channel.pipe(switchMap((c) => of$(c?.name))); const membersCount = channelInfo.pipe( switchMap((i) => (i ? of$(i.memberCount) : of$(0))), ); @@ -78,6 +79,7 @@ const enhanced = withObservables([], (ownProps: WithDatabaseArgs & OwnProps) => return { channelType, + channelName, currentUserId, enableConfirmNotificationsToChannel, maxMessageLength, diff --git a/app/components/post_draft/send_handler/send_handler.tsx b/app/components/post_draft/send_handler/send_handler.tsx index bd207742c..e9aa0d71f 100644 --- a/app/components/post_draft/send_handler/send_handler.tsx +++ b/app/components/post_draft/send_handler/send_handler.tsx @@ -31,6 +31,7 @@ type Props = { testID?: string; channelId: string; channelType?: ChannelType; + channelName?: string; rootId: string; canShowPostPriority?: boolean; setIsFocused: (isFocused: boolean) => void; @@ -69,6 +70,7 @@ export default function SendHandler({ testID, channelId, channelType, + channelName, currentUserId, enableConfirmNotificationsToChannel, files, @@ -270,6 +272,7 @@ export default function SendHandler({ testID={testID} channelId={channelId} channelType={channelType} + channelName={channelName} currentUserId={currentUserId} rootId={rootId} canShowPostPriority={canShowPostPriority} diff --git a/app/utils/post/index.ts b/app/utils/post/index.ts index a155ea174..7cceeed5f 100644 --- a/app/utils/post/index.ts +++ b/app/utils/post/index.ts @@ -7,9 +7,11 @@ import {getUsersCountFromMentions} from '@actions/local/post'; import {General, Post} from '@constants'; import {SPECIAL_MENTIONS_REGEX} from '@constants/autocomplete'; import {POST_TIME_TO_FAIL} from '@constants/post'; +import DatabaseManager from '@database/manager'; import {DEFAULT_LOCALE} from '@i18n'; +import {getUserById} from '@queries/servers/user'; import {toMilliseconds} from '@utils/datetime'; -import {displayUsername} from '@utils/user'; +import {displayUsername, getUserIdFromChannelName} from '@utils/user'; import type PostModel from '@typings/database/models/servers/post'; import type UserModel from '@typings/database/models/servers/user'; @@ -104,7 +106,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, channelType?: ChannelType) { +export async function persistentNotificationsConfirmation(serverUrl: string, value: string, mentionsList: string[], intl: IntlShape, sendMessage: () => void, persistentNotificationMaxRecipients: number, persistentNotificationInterval: number, currentUserId: string, channelName?: string, channelType?: ChannelType) { let title = ''; let description = ''; let buttons: AlertButton[] = [{ @@ -115,7 +117,37 @@ export async function persistentNotificationsConfirmation(serverUrl: string, val style: 'cancel', }]; - if (hasSpecialMentions(value)) { + if (channelType === General.DM_CHANNEL) { + const {database} = DatabaseManager.getServerDatabaseAndOperator(serverUrl); + const teammateId = getUserIdFromChannelName(currentUserId, channelName!); + const user = await getUserById(database, teammateId); + + title = intl.formatMessage({ + id: 'persistent_notifications.confirm.title', + defaultMessage: 'Send persistent notifications', + }); + description = intl.formatMessage({ + id: 'persistent_notifications.dm_channel.description', + defaultMessage: '@{username} will be notified every {interval, plural, one {minute} other {{interval} minutes}} until they’ve acknowledged or replied to the message.', + }, { + interval: persistentNotificationInterval, + username: user?.username, + }); + buttons = [{ + text: intl.formatMessage({ + id: 'persistent_notifications.confirm.cancel', + defaultMessage: 'Cancel', + }), + style: 'cancel', + }, + { + text: intl.formatMessage({ + id: 'persistent_notifications.confirm.send', + defaultMessage: 'Send', + }), + onPress: sendMessage, + }]; + } else if (hasSpecialMentions(value)) { description = intl.formatMessage({ id: 'persistent_notifications.error.special_mentions', defaultMessage: 'Cannot use @channel, @all or @here to mention recipients of persistent notifications.', @@ -124,7 +156,16 @@ export async function persistentNotificationsConfirmation(serverUrl: string, val // removes the @ from the mention const formattedMentionsList = mentionsList.map((mention) => mention.slice(1)); const usersCount = await getUsersCountFromMentions(serverUrl, formattedMentionsList); - if (usersCount > persistentNotificationMaxRecipients) { + if (usersCount === 0) { + title = intl.formatMessage({ + id: 'persistent_notifications.error.no_mentions.title', + defaultMessage: 'Recipients must be @mentioned', + }); + description = intl.formatMessage({ + id: 'persistent_notifications.error.no_mentions.description', + defaultMessage: 'There are no recipients mentioned in your message. You’ll need add mentions to be able to send persistent notifications.', + }); + } else if (usersCount > persistentNotificationMaxRecipients) { title = intl.formatMessage({ id: 'persistent_notifications.error.max_recipients.title', defaultMessage: 'Too many recipients', @@ -136,15 +177,6 @@ export async function persistentNotificationsConfirmation(serverUrl: string, val max: persistentNotificationMaxRecipients, count: mentionsList.length, }); - } else if (usersCount === 0 && channelType !== General.DM_CHANNEL) { - title = intl.formatMessage({ - id: 'persistent_notifications.error.no_mentions.title', - defaultMessage: 'Recipients must be @mentioned', - }); - description = intl.formatMessage({ - id: 'persistent_notifications.error.no_mentions.description', - defaultMessage: 'There are no recipients mentioned in your message. You’ll need add mentions to be able to send persistent notifications.', - }); } else { title = intl.formatMessage({ id: 'persistent_notifications.confirm.title', @@ -152,7 +184,7 @@ export async function persistentNotificationsConfirmation(serverUrl: string, val }); description = intl.formatMessage({ id: 'persistent_notifications.confirm.description', - defaultMessage: '@mentioned recipients will be notified every {interval, plural, one {minute} other {{interval} minutes}} until they’ve acknowledged or replied to the message.', + defaultMessage: 'Mentioned recipients will be notified every {interval, plural, one {minute} other {{interval} minutes}} until they’ve acknowledged or replied to the message.', }, { interval: persistentNotificationInterval, }); diff --git a/assets/base/i18n/en.json b/assets/base/i18n/en.json index e159d7c22..7db1a64a3 100644 --- a/assets/base/i18n/en.json +++ b/assets/base/i18n/en.json @@ -113,7 +113,6 @@ "channel_info.archive_failed": "An error occurred trying to archive the channel {displayName}", "channel_info.archive_title": "Archive {term}", "channel_info.channel_auto_follow_threads": "Follow all threads in this channel", - "channel_info.channel_auto_follow_threads_failed": "An error occurred trying to auto follow all threads in channel {displayName}", "channel_info.channel_files": "Files", "channel_info.close": "Close", "channel_info.close_dm": "Close direct message", @@ -845,9 +844,10 @@ "permalink.show_dialog_warn.join": "Join", "permalink.show_dialog_warn.title": "Join private channel", "persistent_notifications.confirm.cancel": "Cancel", - "persistent_notifications.confirm.description": "@mentioned recipients will be notified every {interval, plural, one {minute} other {{interval} minutes}} until they’ve acknowledged or replied to the message.", + "persistent_notifications.confirm.description": "Mentioned recipients will be notified every {interval, plural, one {minute} other {{interval} minutes}} until they’ve acknowledged or replied to the message.", "persistent_notifications.confirm.send": "Send", "persistent_notifications.confirm.title": "Send persistent notifications", + "persistent_notifications.dm_channel.description": "{username} will be notified every {interval, plural, one {minute} other {{interval} minutes}} until they’ve acknowledged or replied to the message.", "persistent_notifications.error.max_recipients.description": "You can send persistent notifications to a maximum of {max} recipients. There are {count} recipients mentioned in your message. You’ll need to change who you’ve mentioned before you can send.", "persistent_notifications.error.max_recipients.title": "Too many recipients", "persistent_notifications.error.no_mentions.description": "There are no recipients mentioned in your message. You’ll need add mentions to be able to send persistent notifications.",