From 53cd54471044cff18d1a5b9e88b1e1d917684541 Mon Sep 17 00:00:00 2001 From: Carlos Tadeu Panato Junior Date: Thu, 8 Dec 2016 00:14:04 +0100 Subject: Push and Email Notifications should follow "Teammate Name Display" setting (#4660) * Push Notifications and Email Notifications should follow "Teammate Name Display" setting * get the display name notification from the receiver --- api/post.go | 42 +++++++++++++++++++++--------------------- 1 file changed, 21 insertions(+), 21 deletions(-) (limited to 'api/post.go') diff --git a/api/post.go b/api/post.go index 2dc574e9b..fcbafbbe5 100644 --- a/api/post.go +++ b/api/post.go @@ -657,18 +657,26 @@ func sendNotifications(c *Context, post *model.Post, team *model.Team, channel * updateMentionChans = append(updateMentionChans, Srv.Store.Channel().IncrementMentionCount(post.ChannelId, id)) } - senderName := "" - var sender *model.User - if post.IsSystemMessage() { - senderName = c.T("system.message.name") - } else if profile, ok := profileMap[post.UserId]; ok { - if value, ok := post.Props["override_username"]; ok && post.Props["from_webhook"] == "true" { - senderName = value.(string) - } else { - senderName = profile.Username + senderName := make(map[string]string) + for _, id := range mentionedUsersList { + senderName[id] = "" + if post.IsSystemMessage() { + senderName[id] = c.T("system.message.name") + } else if profile, ok := profileMap[post.UserId]; ok { + if value, ok := post.Props["override_username"]; ok && post.Props["from_webhook"] == "true" { + senderName[id] = value.(string) + } else { + //Get the Display name preference from the receiver + if result := <-Srv.Store.Preference().Get(id, model.PREFERENCE_CATEGORY_DISPLAY_SETTINGS, "name_format"); result.Err != nil { + // Show default sender's name if user doesn't set display settings. + senderName[id] = profile.Username + } else { + senderName[id] = profile.GetDisplayNameForPreference(result.Data.(model.Preference).Value) + } + } + sender = profile } - sender = profile } if utils.Cfg.EmailSettings.SendEmailNotifications { @@ -688,7 +696,7 @@ func sendNotifications(c *Context, post *model.Post, team *model.Team, channel * } if userAllowsEmails && status.Status != model.STATUS_ONLINE { - go sendNotificationEmail(c, post, profileMap[id], channel, team, senderName, sender) + go sendNotificationEmail(c, post, profileMap[id], channel, team, senderName[id], sender) } } } @@ -784,7 +792,7 @@ func sendNotifications(c *Context, post *model.Post, team *model.Team, channel * } if DoesStatusAllowPushNotification(profileMap[id], status, post.ChannelId) { - go sendPushNotification(post, profileMap[id], channel, senderName, true) + go sendPushNotification(post, profileMap[id], channel, senderName[id], true) } } @@ -797,7 +805,7 @@ func sendNotifications(c *Context, post *model.Post, team *model.Team, channel * } if DoesStatusAllowPushNotification(profileMap[id], status, post.ChannelId) { - go sendPushNotification(post, profileMap[id], channel, senderName, false) + go sendPushNotification(post, profileMap[id], channel, senderName[id], false) } } } @@ -908,14 +916,6 @@ func sendNotificationEmail(c *Context, post *model.Post, user *model.User, chann subjectText = userLocale("api.post.send_notifications_and_forget.message_subject") senderDisplayName := senderName - if sender != nil { - if result := <-Srv.Store.Preference().Get(user.Id, model.PREFERENCE_CATEGORY_DISPLAY_SETTINGS, "name_format"); result.Err != nil { - // Show default sender's name if user doesn't set display settings. - senderDisplayName = senderName - } else { - senderDisplayName = sender.GetDisplayNameForPreference(result.Data.(model.Preference).Value) - } - } mailTemplate = "api.templates.post_subject_in_direct_message" mailParameters = map[string]interface{}{"SubjectText": subjectText, "TeamDisplayName": team.DisplayName, -- cgit v1.2.3-1-g7c22