From 748a416961923932e9b2969beb2730ee8c240ea7 Mon Sep 17 00:00:00 2001 From: enahum Date: Thu, 23 Feb 2017 11:08:48 -0300 Subject: =?UTF-8?q?PLT-3193=20Add=20channel=20notification=20preferences?= =?UTF-8?q?=20for=20push=20and=20email=20noti=E2=80=A6=20(#5500)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit * PLT-3193 Add channel notification preferences for push and email notifications * unit tests, model validation and localization * Feedback review * Adding back allowFromCache check * Setting push and email to use default settings * Move props as constants * address feedback --- app/notification.go | 31 ++++++++++++++++++++++++++----- 1 file changed, 26 insertions(+), 5 deletions(-) (limited to 'app/notification.go') diff --git a/app/notification.go b/app/notification.go index 1df194d2c..e9e76de45 100644 --- a/app/notification.go +++ b/app/notification.go @@ -26,6 +26,7 @@ import ( func SendNotifications(post *model.Post, team *model.Team, channel *model.Channel, sender *model.User) ([]string, *model.AppError) { pchan := Srv.Store.User().GetAllProfilesInChannel(channel.Id, true) + cmnchan := Srv.Store.Channel().GetAllChannelMembersNotifyPropsForChannel(channel.Id, true) var fchan store.StoreChannel if len(post.FileIds) != 0 { @@ -39,6 +40,13 @@ func SendNotifications(post *model.Post, team *model.Team, channel *model.Channe profileMap = result.Data.(map[string]*model.User) } + var channelMemberNotifyPropsMap map[string]model.StringMap + if result := <-cmnchan; result.Err != nil { + return nil, result.Err + } else { + channelMemberNotifyPropsMap = result.Data.(map[string]model.StringMap) + } + mentionedUserIds := make(map[string]bool) allActivityPushUserIds := []string{} hereNotification := false @@ -94,7 +102,7 @@ func SendNotifications(post *model.Post, team *model.Team, channel *model.Channe // find which users in the channel are set up to always receive mobile notifications for _, profile := range profileMap { - if profile.NotifyProps["push"] == model.USER_NOTIFY_ALL && + if profile.NotifyProps[model.PUSH_NOTIFY_PROP] == model.USER_NOTIFY_ALL && (post.UserId != profile.Id || post.Props["from_webhook"] == "true") && !post.IsSystemMessage() { allActivityPushUserIds = append(allActivityPushUserIds, profile.Id) @@ -137,7 +145,12 @@ func SendNotifications(post *model.Post, team *model.Team, channel *model.Channe if utils.Cfg.EmailSettings.SendEmailNotifications { for _, id := range mentionedUsersList { - userAllowsEmails := profileMap[id].NotifyProps["email"] != "false" + 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 { + userAllowsEmails = channelEmail != "false" + } + } var status *model.Status var err *model.AppError @@ -245,7 +258,7 @@ func SendNotifications(post *model.Post, team *model.Team, channel *model.Channe } if DoesStatusAllowPushNotification(profileMap[id], status, post.ChannelId) { - sendPushNotification(post, profileMap[id], channel, senderName[id], true) + sendPushNotification(post, profileMap[id], channel, senderName[id], channelMemberNotifyPropsMap[id], true) } } @@ -258,7 +271,7 @@ func SendNotifications(post *model.Post, team *model.Team, channel *model.Channe } if DoesStatusAllowPushNotification(profileMap[id], status, post.ChannelId) { - sendPushNotification(post, profileMap[id], channel, senderName[id], false) + sendPushNotification(post, profileMap[id], channel, senderName[id], channelMemberNotifyPropsMap[id], false) } } } @@ -442,7 +455,7 @@ func GetMessageForNotification(post *model.Post, translateFunc i18n.TranslateFun } } -func sendPushNotification(post *model.Post, user *model.User, channel *model.Channel, senderName string, wasMentioned bool) *model.AppError { +func sendPushNotification(post *model.Post, user *model.User, channel *model.Channel, senderName string, channelNotifyProps model.StringMap, wasMentioned bool) *model.AppError { sessions, err := getMobileAppSessions(user.Id) if err != nil { return err @@ -450,6 +463,14 @@ func sendPushNotification(post *model.Post, user *model.User, channel *model.Cha var channelName string + if channelNotify, ok := channelNotifyProps[model.PUSH_NOTIFY_PROP]; ok { + if channelNotify == model.USER_NOTIFY_NONE { + return nil + } else if channelNotify == model.USER_NOTIFY_MENTION && !wasMentioned { + return nil + } + } + if channel.Type == model.CHANNEL_DIRECT { channelName = senderName } else { -- cgit v1.2.3-1-g7c22