diff options
author | enahum <nahumhbl@gmail.com> | 2017-02-23 11:08:48 -0300 |
---|---|---|
committer | GitHub <noreply@github.com> | 2017-02-23 11:08:48 -0300 |
commit | 748a416961923932e9b2969beb2730ee8c240ea7 (patch) | |
tree | f6ab74d35fc1be8b9015f8a89e7ac6058ec1d4fe /app/notification.go | |
parent | ca7d3b6e7bc2e52cf40180a462492313f298e760 (diff) | |
download | chat-748a416961923932e9b2969beb2730ee8c240ea7.tar.gz chat-748a416961923932e9b2969beb2730ee8c240ea7.tar.bz2 chat-748a416961923932e9b2969beb2730ee8c240ea7.zip |
PLT-3193 Add channel notification preferences for push and email notiā¦ (#5500)
* 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
Diffstat (limited to 'app/notification.go')
-rw-r--r-- | app/notification.go | 31 |
1 files changed, 26 insertions, 5 deletions
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 { |