From 385461acfcedb0c71d300f1dd6307fb05b29a668 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Daniel=20Espino=20Garc=C3=ADa?= Date: Tue, 3 Oct 2023 11:03:55 +0200 Subject: [PATCH] Make GM Intro message to change based on the notification preferences (#7563) --- .../intro/direct_channel/direct_channel.tsx | 67 ++++++++++++++++--- .../intro/direct_channel/index.ts | 12 +++- assets/base/i18n/en.json | 6 +- 3 files changed, 71 insertions(+), 14 deletions(-) diff --git a/app/screens/channel/channel_post_list/intro/direct_channel/direct_channel.tsx b/app/screens/channel/channel_post_list/intro/direct_channel/direct_channel.tsx index 6c5dfe246..a2c8d4df2 100644 --- a/app/screens/channel/channel_post_list/intro/direct_channel/direct_channel.tsx +++ b/app/screens/channel/channel_post_list/intro/direct_channel/direct_channel.tsx @@ -2,12 +2,13 @@ // See LICENSE.txt for license information. import React, {useEffect, useMemo} from 'react'; -import {Text, View} from 'react-native'; +import {defineMessages} from 'react-intl'; +import {Text, View, type TextStyle} from 'react-native'; import {fetchProfilesInChannel} from '@actions/remote/user'; import FormattedText from '@components/formatted_text'; import {BotTag} from '@components/tag'; -import {General} from '@constants'; +import {General, NotificationLevel} from '@constants'; import {useServerUrl} from '@context/server'; import {makeStyleSheetFromTheme} from '@utils/theme'; import {typography} from '@utils/typography'; @@ -28,6 +29,8 @@ type Props = { members?: ChannelMembershipModel[]; theme: Theme; hasGMasDMFeature: boolean; + channelNotifyProps?: Partial; + userNotifyProps?: Partial | null; } const getStyleSheet = makeStyleSheetFromTheme((theme: Theme) => ({ @@ -71,6 +74,46 @@ const getStyleSheet = makeStyleSheetFromTheme((theme: Theme) => ({ }, })); +const gmIntroMessages = defineMessages({ + muted: {id: 'intro.group_message.muted', defaultMessage: 'This group message is currently muted, so you will not be notified.'}, + [NotificationLevel.ALL]: {id: 'intro.group_message.all', defaultMessage: 'You\'ll be notified for all activity in this group message.'}, + [NotificationLevel.DEFAULT]: {id: 'intro.group_message.all', defaultMessage: 'You\'ll be notified for all activity in this group message.'}, + [NotificationLevel.MENTION]: {id: 'intro.group_message.mention', defaultMessage: 'You have selected to be notified only when mentioned in this group message.'}, + [NotificationLevel.NONE]: {id: 'intro.group_message.none', defaultMessage: 'You have selected to never be notified in this group message.'}, +}); + +const getGMIntroMessageSpecificPart = (userNotifyProps: Partial | undefined | null, channelNotifyProps: Partial | undefined, boldStyle: TextStyle) => { + const isMuted = channelNotifyProps?.mark_unread === 'mention'; + if (isMuted) { + return ( + {chunk}, + }} + /> + ); + } + const channelNotifyProp = channelNotifyProps?.push || NotificationLevel.DEFAULT; + const userNotifyProp = userNotifyProps?.push || NotificationLevel.MENTION; + let notifyLevelToUse = channelNotifyProp; + if (notifyLevelToUse === NotificationLevel.DEFAULT) { + notifyLevelToUse = userNotifyProp; + } + if (channelNotifyProp === NotificationLevel.DEFAULT && userNotifyProp === NotificationLevel.MENTION) { + notifyLevelToUse = NotificationLevel.ALL; + } + + return ( + {chunk}, + }} + /> + ); +}; + const DirectChannel = ({ channel, currentUserId, @@ -78,6 +121,8 @@ const DirectChannel = ({ members, theme, hasGMasDMFeature, + channelNotifyProps, + userNotifyProps, }: Props) => { const serverUrl = useServerUrl(); const styles = getStyleSheet(theme); @@ -110,16 +155,16 @@ const DirectChannel = ({ ); } return ( - all activity in this group message.'} - id='intro.group_message' - style={styles.message} - values={{ - b: (chunk: string) => {chunk}, - }} - /> + + + + {getGMIntroMessageSpecificPart(userNotifyProps, channelNotifyProps, styles.boldText)} + ); - }, [channel.displayName, theme]); + }, [channel.displayName, theme, channelNotifyProps, userNotifyProps]); const profiles = useMemo(() => { if (channel.type === General.DM_CHANNEL) { diff --git a/app/screens/channel/channel_post_list/intro/direct_channel/index.ts b/app/screens/channel/channel_post_list/intro/direct_channel/index.ts index e598cfb2e..52910a7d4 100644 --- a/app/screens/channel/channel_post_list/intro/direct_channel/index.ts +++ b/app/screens/channel/channel_post_list/intro/direct_channel/index.ts @@ -7,10 +7,10 @@ import {of as of$} from 'rxjs'; import {switchMap} from 'rxjs/operators'; import {General} from '@constants'; -import {observeChannelMembers} from '@queries/servers/channel'; +import {observeChannelMembers, observeNotifyPropsByChannels} from '@queries/servers/channel'; import {observeHasGMasDMFeature} from '@queries/servers/features'; import {observeCurrentUserId} from '@queries/servers/system'; -import {observeUser} from '@queries/servers/user'; +import {observeCurrentUser, observeUser} from '@queries/servers/user'; import {getUserIdFromChannelName} from '@utils/user'; import DirectChannel from './direct_channel'; @@ -25,6 +25,12 @@ const enhanced = withObservables([], ({channel, database}: {channel: ChannelMode const currentUserId = observeCurrentUserId(database); const members = observeChannelMembers(database, channel.id); const hasGMasDMFeature = observeHasGMasDMFeature(database); + const channelNotifyProps = observeNotifyPropsByChannels(database, [channel]).pipe( + switchMap((v) => of$(v[channel.id])), + ); + const userNotifyProps = observeCurrentUser(database).pipe( + switchMap((v) => of$(v?.notifyProps)), + ); let isBot = of$(false); if (channel.type === General.DM_CHANNEL) { @@ -43,6 +49,8 @@ const enhanced = withObservables([], ({channel, database}: {channel: ChannelMode isBot, members, hasGMasDMFeature, + channelNotifyProps, + userNotifyProps, }; }); diff --git a/assets/base/i18n/en.json b/assets/base/i18n/en.json index ed13d1cdb..eb879a5e3 100644 --- a/assets/base/i18n/en.json +++ b/assets/base/i18n/en.json @@ -340,8 +340,12 @@ "intro.channel_info": "Info", "intro.created_by": "created by {creator} on {date}.", "intro.direct_message": "This is the start of your conversation with {teammate}. Messages and files shared here are not shown to anyone else.", - "intro.group_message": "This is the start of your conversation with this group. Messages and files shared here are not shown to anyone else outside of the group.", "intro.group_message.after_gm_as_dm": "This is the start of your conversation with this group. Messages and files shared here are not shown to anyone else outside of the group.", + "intro.group_message.all": "You'll be notified for all activity in this group message.", + "intro.group_message.common": "This is the start of your conversation with this group.", + "intro.group_message.mention": "You have selected to be notified only when mentioned in this group message.", + "intro.group_message.muted": "This group message is currently muted, so you will not be notified.", + "intro.group_message.none": "You have selected to never be notified in this group message.", "intro.private_channel": "Private Channel", "intro.public_channel": "Public Channel", "intro.townsquare": "Welcome to {name}. Everyone automatically becomes a member of this channel when they join the team.",