diff --git a/app/email/email_batching.go b/app/email/email_batching.go index 43e929929a..35332428fc 100644 --- a/app/email/email_batching.go +++ b/app/email/email_batching.go @@ -225,6 +225,16 @@ func (es *Service) sendBatchedEmailNotification(userID string, notifications []* emailNotificationContentsType = *es.config().EmailSettings.EmailNotificationContentsType } + // check if user has CRT set to ON + threadsEnabled := false + if *es.config().ServiceSettings.CollapsedThreads != model.CollapsedThreadsDisabled { + threadsEnabled = *es.config().ServiceSettings.CollapsedThreads == model.CollapsedThreadsDefaultOn + // check if a participant has overridden collapsed threads settings + if preference, errCrt := es.store.Preference().Get(userID, model.PreferenceCategoryDisplaySettings, model.PreferenceNameCollapsedThreadsEnabled); errCrt == nil { + threadsEnabled = preference.Value == "on" + } + } + if emailNotificationContentsType == model.EmailNotificationContentsFull { for i, notification := range notifications { sender, errSender := es.userService.GetUser(notification.post.UserId) @@ -261,11 +271,20 @@ func (es *Service) sendBatchedEmailNotification(userID string, notifications []* MessageURL := siteURL + "/" + notification.teamName + "/pl/" + notification.post.Id + channelName := channel.DisplayName + if threadsEnabled && notification.post.RootId != "" { + props := map[string]interface{}{"channelName": channelName} + channelName = translateFunc("api.push_notification.title.collapsed_threads", props) + if channel.Type == model.ChannelTypeDirect { + channelName = translateFunc("api.push_notification.title.collapsed_threads_dm") + } + } + postsData = append(postsData, &postData{ SenderPhoto: senderPhoto, SenderName: sender.GetDisplayName(displayNameFormat), Time: t, - ChannelName: channel.DisplayName, + ChannelName: channelName, Message: template.HTML(es.GetMessageForNotification(notification.post, translateFunc)), MessageURL: MessageURL, }) diff --git a/app/notification.go b/app/notification.go index 89fb598cbc..57f472ce88 100644 --- a/app/notification.go +++ b/app/notification.go @@ -505,9 +505,9 @@ func (a *App) SendNotifications(post *model.Post, team *model.Team, channel *mod a.sendPushNotification( notification, profileMap[id], - profileMap[id].NotifyProps[model.PushThreadsNotifyProp] == model.UserNotifyMention, false, - model.UserNotifyAll, + false, + model.CommentsNotifyCRT, ) } else { // register that a notification was not sent diff --git a/app/notification_email.go b/app/notification_email.go index b32d0f669f..8c99f213bd 100644 --- a/app/notification_email.go +++ b/app/notification_email.go @@ -243,10 +243,7 @@ func (a *App) getNotificationEmailBody(recipient *model.User, post *model.Post, data.Props["NotificationFooterInfoLogin"] = translateFunc("app.notification.footer.infoLogin") data.Props["NotificationFooterInfo"] = translateFunc("app.notification.footer.info") - if a.isCRTEnabledForUser(recipient.Id) && post.RootId != "" { - data.Props["Title"] = translateFunc("app.notification.body.thread.title", map[string]interface{}{"SenderName": senderName}) - data.Props["SubTitle"] = translateFunc("app.notification.body.thread.subTitle", map[string]interface{}{"SenderName": senderName}) - } else if channel.Type == model.ChannelTypeDirect { + if channel.Type == model.ChannelTypeDirect { // Direct Messages data.Props["Title"] = translateFunc("app.notification.body.dm.title", map[string]interface{}{"SenderName": senderName}) data.Props["SubTitle"] = translateFunc("app.notification.body.dm.subTitle", map[string]interface{}{"SenderName": senderName}) @@ -261,6 +258,26 @@ func (a *App) getNotificationEmailBody(recipient *model.User, post *model.Post, pData.ChannelName = channelName } + // Override title and subtile for replies with CRT enabled + if a.isCRTEnabledForUser(recipient.Id) && post.RootId != "" { + // Title is the same in all cases + data.Props["Title"] = translateFunc("app.notification.body.thread.title", map[string]interface{}{"SenderName": senderName}) + + if channel.Type == model.ChannelTypeDirect { + // Direct Reply + data.Props["SubTitle"] = translateFunc("app.notification.body.thread_dm.subTitle", map[string]interface{}{"SenderName": senderName}) + } else if channel.Type == model.ChannelTypeGroup { + // Group Reply + data.Props["SubTitle"] = translateFunc("app.notification.body.thread_gm.subTitle", map[string]interface{}{"SenderName": senderName}) + } else if emailNotificationContentsType == model.EmailNotificationContentsFull { + // Channel Reply with full content + data.Props["SubTitle"] = translateFunc("app.notification.body.thread_channel_full.subTitle", map[string]interface{}{"SenderName": senderName, "ChannelName": channelName}) + } else { + // Channel Reply with generic content + data.Props["SubTitle"] = translateFunc("app.notification.body.thread_channel.subTitle", map[string]interface{}{"SenderName": senderName}) + } + } + // only include posts in notification email if email notification contents type is set to full if emailNotificationContentsType == model.EmailNotificationContentsFull { data.Props["Posts"] = []postData{pData} diff --git a/app/notification_push.go b/app/notification_push.go index cd80f2b815..fa4c962c05 100644 --- a/app/notification_push.go +++ b/app/notification_push.go @@ -181,9 +181,19 @@ func (a *App) getPushNotificationMessage(contentsConfig, postMessage string, exp } if channelType == model.ChannelTypeDirect { + if replyToThreadType == model.CommentsNotifyCRT { + if contentsConfig == model.GenericNoChannelNotification { + return senderName + userLocale("api.post.send_notification_and_forget.push_comment_on_crt_thread") + } + return senderName + userLocale("api.post.send_notification_and_forget.push_comment_on_crt_thread_dm") + } return userLocale("api.post.send_notifications_and_forget.push_message") } + if replyToThreadType == model.CommentsNotifyCRT { + return senderName + userLocale("api.post.send_notification_and_forget.push_comment_on_crt_thread") + } + if channelWideMention { return senderName + userLocale("api.post.send_notification_and_forget.push_channel_mention") } @@ -582,8 +592,16 @@ func (a *App) buildFullPushNotificationMessage(contentsConfig string, post *mode cfg := a.Config() if contentsConfig != model.GenericNoChannelNotification || channel.Type == model.ChannelTypeDirect { msg.ChannelName = channelName - if a.isCRTEnabledForUser(user.Id) && post.RootId != "" { - msg.ChannelName = userLocale("api.push_notification.title.collapsed_threads") + } + + if a.isCRTEnabledForUser(user.Id) && post.RootId != "" { + if contentsConfig != model.GenericNoChannelNotification { + props := map[string]interface{}{"channelName": channelName} + msg.ChannelName = userLocale("api.push_notification.title.collapsed_threads", props) + + if channel.Type == model.ChannelTypeDirect { + msg.ChannelName = userLocale("api.push_notification.title.collapsed_threads_dm") + } } } diff --git a/i18n/en.json b/i18n/en.json index a22f3380e6..48acbb5519 100644 --- a/i18n/en.json +++ b/i18n/en.json @@ -2236,7 +2236,11 @@ }, { "id": "api.post.send_notification_and_forget.push_comment_on_crt_thread", - "translation": " commented on a thread you are following." + "translation": " replied to a thread you're following." + }, + { + "id": "api.post.send_notification_and_forget.push_comment_on_crt_thread_dm", + "translation": " replied to a thread." }, { "id": "api.post.send_notification_and_forget.push_comment_on_post", @@ -2320,7 +2324,11 @@ }, { "id": "api.push_notification.title.collapsed_threads", - "translation": "Reply to Thread" + "translation": "Reply in {{.channelName}}" + }, + { + "id": "api.push_notification.title.collapsed_threads_dm", + "translation": "Reply in Direct Message" }, { "id": "api.push_notifications.message.parse.app_error", @@ -5487,12 +5495,24 @@ "translation": "{{.SenderName}} mentioned you in a message" }, { - "id": "app.notification.body.thread.subTitle", + "id": "app.notification.body.thread.title", + "translation": "{{.SenderName}} replied to a thread" + }, + { + "id": "app.notification.body.thread_channel.subTitle", "translation": "While you were away, {{.SenderName}} replied to a thread you're following." }, { - "id": "app.notification.body.thread.title", - "translation": "{{.SenderName}} replied to a thread" + "id": "app.notification.body.thread_channel_full.subTitle", + "translation": "While you were away, {{.SenderName}} replied to a thread you're following in {{.ChannelName}}." + }, + { + "id": "app.notification.body.thread_dm.subTitle", + "translation": "While you were away, {{.SenderName}} replied to a thread in your Direct Message." + }, + { + "id": "app.notification.body.thread_gm.subTitle", + "translation": "While you were away, {{.SenderName}} replied to a thread in your group." }, { "id": "app.notification.footer.info", diff --git a/model/user.go b/model/user.go index ba0a8e934d..2e843ea135 100644 --- a/model/user.go +++ b/model/user.go @@ -38,6 +38,7 @@ const ( CommentsNotifyNever = "never" CommentsNotifyRoot = "root" CommentsNotifyAny = "any" + CommentsNotifyCRT = "crt" FirstNameNotifyProp = "first_name" AutoResponderActiveNotifyProp = "auto_responder_active" AutoResponderMessageNotifyProp = "auto_responder_message"