diff options
author | Harrison Healey <harrisonmhealey@gmail.com> | 2016-08-18 09:41:31 -0400 |
---|---|---|
committer | enahum <nahumhbl@gmail.com> | 2016-08-18 08:41:31 -0500 |
commit | 2b277729fd0516b0cac9ec464e6a33749ceae4dd (patch) | |
tree | 28eba46817d93e966482ed34792a078d17125262 | |
parent | 1dc0996b895eaa861e4ddbc029c3db0751855c00 (diff) | |
download | chat-2b277729fd0516b0cac9ec464e6a33749ceae4dd.tar.gz chat-2b277729fd0516b0cac9ec464e6a33749ceae4dd.tar.bz2 chat-2b277729fd0516b0cac9ec464e6a33749ceae4dd.zip |
PLT-3955/PLT-3956 Fixing issues with mentions (#3820)
* PLT-3955 Fixed @here sending push notifications to people not in the channel
* PLT-3956 Fixed mention numbers not being incremented
-rw-r--r-- | api/post.go | 30 |
1 files changed, 16 insertions, 14 deletions
diff --git a/api/post.go b/api/post.go index 93b88a432..dde85a8c8 100644 --- a/api/post.go +++ b/api/post.go @@ -551,6 +551,7 @@ func sendNotifications(c *Context, post *model.Post, team *model.Team, channel * // get profiles for all users we could be mentioning pchan := Srv.Store.User().GetProfiles(c.TeamId) dpchan := Srv.Store.User().GetDirectProfiles(c.Session.UserId) + mchan := Srv.Store.Channel().GetMembers(post.ChannelId) var profileMap map[string]*model.User if result := <-pchan; result.Err != nil { @@ -574,9 +575,19 @@ func sendNotifications(c *Context, post *model.Post, team *model.Team, channel * l4g.Error(utils.T("api.post.send_notifications_and_forget.user_id.error"), post.UserId) return } + // using a map as a pseudo-set since we're checking for containment a lot + members := make(map[string]string) + if result := <-mchan; result.Err != nil { + l4g.Error(utils.T("api.post.handle_post_events_and_forget.members.error"), post.ChannelId, result.Err) + return + } else { + for _, member := range result.Data.([]model.ChannelMember) { + members[member.UserId] = member.UserId + } + } mentionedUserIds := make(map[string]bool) - alwaysNotifyUserIds := []string{} // ??? + alwaysNotifyUserIds := []string{} hereNotification := false updateMentionChans := []store.StoreChannel{} @@ -590,17 +601,6 @@ func sendNotifications(c *Context, post *model.Post, team *model.Team, channel * mentionedUserIds[otherUserId] = true } else { - // using a map as a pseudo-set since we're checking for containment a lot - members := make(map[string]string) - if result := <-Srv.Store.Channel().GetMembers(post.ChannelId); result.Err != nil { - l4g.Error(utils.T("api.post.handle_post_events_and_forget.members.error"), post.ChannelId, result.Err) - return - } else { - for _, member := range result.Data.([]model.ChannelMember) { - members[member.UserId] = member.UserId - } - } - keywords := getMentionKeywords(profileMap, members) // get users that are explicitly mentioned @@ -667,6 +667,7 @@ func sendNotifications(c *Context, post *model.Post, team *model.Team, channel * for id := range mentionedUserIds { mentionedUsersList = append(mentionedUsersList, id) + updateMentionChans = append(updateMentionChans, Srv.Store.Channel().IncrementMentionCount(post.ChannelId, id)) } if utils.Cfg.EmailSettings.SendEmailNotifications { @@ -697,9 +698,10 @@ func sendNotifications(c *Context, post *model.Post, team *model.Team, channel * } _, profileFound := profileMap[status.UserId] - _, alreadyAdded := mentionedUserIds[status.UserId] + _, isChannelMember := members[status.UserId] + _, alreadyMentioned := mentionedUserIds[status.UserId] - if status.Status == model.STATUS_ONLINE && profileFound && !alreadyAdded { + if status.Status == model.STATUS_ONLINE && profileFound && isChannelMember && !alreadyMentioned { mentionedUsersList = append(mentionedUsersList, status.UserId) updateMentionChans = append(updateMentionChans, Srv.Store.Channel().IncrementMentionCount(post.ChannelId, status.UserId)) } |