From 514033f14c16f0634ffb36584b866c153943a692 Mon Sep 17 00:00:00 2001 From: Joram Wilander Date: Thu, 19 Apr 2018 10:21:33 -0400 Subject: Fix panics caused by race in notification code (#8652) --- app/notification.go | 12 ++++++++++++ app/notification_test.go | 2 ++ 2 files changed, 14 insertions(+) (limited to 'app') diff --git a/app/notification.go b/app/notification.go index d69bb4e2e..d1f6225b3 100644 --- a/app/notification.go +++ b/app/notification.go @@ -179,6 +179,10 @@ func (a *App) SendNotifications(post *model.Post, team *model.Team, channel *mod if a.Config().EmailSettings.SendEmailNotifications { for _, id := range mentionedUsersList { + if profileMap[id] == nil { + continue + } + userAllowsEmails := profileMap[id].NotifyProps[model.EMAIL_NOTIFY_PROP] != "false" if channelEmail, ok := channelMemberNotifyPropsMap[id][model.EMAIL_NOTIFY_PROP]; ok { if channelEmail != model.CHANNEL_NOTIFY_DEFAULT { @@ -279,6 +283,10 @@ func (a *App) SendNotifications(post *model.Post, team *model.Team, channel *mod if sendPushNotifications { for _, id := range mentionedUsersList { + if profileMap[id] == nil { + continue + } + var status *model.Status var err *model.AppError if status, err = a.GetStatus(id); err != nil { @@ -291,6 +299,10 @@ func (a *App) SendNotifications(post *model.Post, team *model.Team, channel *mod } for _, id := range allActivityPushUserIds { + if profileMap[id] == nil { + continue + } + if _, ok := mentionedUserIds[id]; !ok { var status *model.Status var err *model.AppError diff --git a/app/notification_test.go b/app/notification_test.go index 8df19e2bf..24784940e 100644 --- a/app/notification_test.go +++ b/app/notification_test.go @@ -23,6 +23,8 @@ func TestSendNotifications(t *testing.T) { UserId: th.BasicUser.Id, ChannelId: th.BasicChannel.Id, Message: "@" + th.BasicUser2.Username, + Type: model.POST_ADD_TO_CHANNEL, + Props: map[string]interface{}{model.POST_PROPS_ADDED_USER_ID: "junk"}, }, true) if err != nil { -- cgit v1.2.3-1-g7c22