diff --git a/app/email/email_batching.go b/app/email/email_batching.go index 35332428fc..bb0cf7d284 100644 --- a/app/email/email_batching.go +++ b/app/email/email_batching.go @@ -10,6 +10,7 @@ import ( "io" "net/http" "strconv" + "strings" "sync" "time" @@ -23,13 +24,15 @@ const ( ) type postData struct { - SenderName string - ChannelName string - Message template.HTML - MessageURL string - SenderPhoto string - PostPhoto string - Time string + SenderName string + ChannelName string + Message template.HTML + MessageURL string + SenderPhoto string + PostPhoto string + Time string + ShowChannelIcon bool + OtherChannelMembersCount int } func (es *Service) InitEmailBatching() { @@ -206,6 +209,18 @@ func (job *EmailBatchingJob) checkPendingNotifications(now time.Time, handler fu } } +/** +* If the name is longer than i characters, replace remaining characters with ... + */ +func truncateUserNames(name string, i int) string { + runes := []rune(name) + if len(runes) > i { + newString := string(runes[:i]) + return newString + "..." + } + return name +} + func (es *Service) sendBatchedEmailNotification(userID string, notifications []*batchedNotification) { user, err := es.userService.GetUser(userID) if err != nil { @@ -266,27 +281,38 @@ func (es *Service) sendBatchedEmailNotification(userID string, notifications []* "Month": translateFunc(tm.Month().String()), "Day": tm.Day(), "Year": tm.Year(), - "Timezone": timezone, + "TimeZone": timezone, }) MessageURL := siteURL + "/" + notification.teamName + "/pl/" + notification.post.Id - channelName := channel.DisplayName + channelDisplayName := channel.DisplayName + showChannelIcon := true + otherChannelMembersCount := 0 + if threadsEnabled && notification.post.RootId != "" { - props := map[string]interface{}{"channelName": channelName} - channelName = translateFunc("api.push_notification.title.collapsed_threads", props) + props := map[string]interface{}{"channelName": channelDisplayName} + channelDisplayName = translateFunc("api.push_notification.title.collapsed_threads", props) if channel.Type == model.ChannelTypeDirect { - channelName = translateFunc("api.push_notification.title.collapsed_threads_dm") + channelDisplayName = translateFunc("api.push_notification.title.collapsed_threads_dm") } } + if channel.Type == model.ChannelTypeGroup { + otherChannelMembersCount = len(strings.Split(channelDisplayName, ",")) - 1 + showChannelIcon = false + channelDisplayName = truncateUserNames(channel.DisplayName, 11) + } + postsData = append(postsData, &postData{ - SenderPhoto: senderPhoto, - SenderName: sender.GetDisplayName(displayNameFormat), - Time: t, - ChannelName: channelName, - Message: template.HTML(es.GetMessageForNotification(notification.post, translateFunc)), - MessageURL: MessageURL, + SenderPhoto: senderPhoto, + SenderName: truncateUserNames(sender.GetDisplayName(displayNameFormat), 22), + Time: t, + ChannelName: channelDisplayName, + Message: template.HTML(es.GetMessageForNotification(notification.post, translateFunc)), + MessageURL: MessageURL, + ShowChannelIcon: showChannelIcon, + OtherChannelMembersCount: otherChannelMembersCount, }) } } @@ -300,16 +326,9 @@ func (es *Service) sendBatchedEmailNotification(userID string, notifications []* "Day": tm.Day(), }) - firstSender, err := es.userService.GetUser(notifications[0].post.UserId) - if err != nil { - mlog.Warn("Unable to find sender of post for batched email notification") - } - data := es.NewEmailTemplateData(user.Locale) data.Props["SiteURL"] = siteURL - data.Props["Title"] = translateFunc("api.email_batching.send_batched_email_notification.title", len(notifications)-1, map[string]interface{}{ - "SenderName": firstSender.GetDisplayName(displayNameFormat), - }) + data.Props["Title"] = translateFunc("api.email_batching.send_batched_email_notification.title") data.Props["SubTitle"] = translateFunc("api.email_batching.send_batched_email_notification.subTitle") data.Props["Button"] = translateFunc("api.email_batching.send_batched_email_notification.button") data.Props["ButtonURL"] = siteURL @@ -324,7 +343,7 @@ func (es *Service) sendBatchedEmailNotification(userID string, notifications []* mlog.Error("Unable to render email", mlog.Err(renderErr)) } - if nErr := es.SendNotificationMail(user.Email, subject, renderedPage); nErr != nil { + if nErr := es.SendMailWithEmbeddedFiles(user.Email, subject, renderedPage, embeddedFiles); nErr != nil { mlog.Warn("Unable to send batched email notification", mlog.String("email", user.Email), mlog.Err(nErr)) } } diff --git a/app/notification_email.go b/app/notification_email.go index 8c99f213bd..31e527b4b6 100644 --- a/app/notification_email.go +++ b/app/notification_email.go @@ -186,13 +186,15 @@ func truncateUserNames(name string, i int) string { } type postData struct { - SenderName string - ChannelName string - Message template.HTML - MessageURL string - SenderPhoto string - PostPhoto string - Time string + SenderName string + ChannelName string + Message template.HTML + MessageURL string + SenderPhoto string + PostPhoto string + Time string + ShowChannelIcon bool + OtherChannelMembersCount int } /** diff --git a/i18n/en.json b/i18n/en.json index 48acbb5519..79c1de4031 100644 --- a/i18n/en.json +++ b/i18n/en.json @@ -1611,10 +1611,7 @@ }, { "id": "api.email_batching.send_batched_email_notification.title", - "translation": { - "one": "{{ .SenderName }} sent you new message", - "other": "{{ .SenderName }} and {{.Count}} others sent you new messages" - } + "translation": "You have new messages" }, { "id": "api.emoji.create.duplicate.app_error", diff --git a/templates/messages_notification.html b/templates/messages_notification.html index 6ba585bdbc..25dc34dc62 100644 --- a/templates/messages_notification.html +++ b/templates/messages_notification.html @@ -71,9 +71,9 @@ max-width: 100%; } - .mj-column-per-50 { - width: 50% !important; - max-width: 50%; + .mj-column-per-33-333333333333336 { + width: 33.333333333333336% !important; + max-width: 33.333333333333336%; } .mj-column-per-90 { @@ -88,9 +88,9 @@ max-width: 100%; } - .moz-text-html .mj-column-per-50 { - width: 50% !important; - max-width: 50%; + .moz-text-html .mj-column-per-33-333333333333336 { + width: 33.333333333333336% !important; + max-width: 33.333333333333336%; } .moz-text-html .mj-column-per-90 { @@ -255,6 +255,7 @@ background: rgba(63, 67, 80, 0.08); border-radius: 4px; display: flex; + padding-left: 4px; } .channelLogo { @@ -275,6 +276,13 @@ padding: 2px 6px 2px 0px; } + .gmChannelCount { + background-color: rgba(63, 67, 80, 0.2); + padding: 0 5px; + border-radius: 2px; + margin-right: 2px; + } + .senderMessage div { text-align: left !important; font-size: 14px !important; @@ -427,8 +435,8 @@