summaryrefslogtreecommitdiffstats
path: root/app/notification.go
diff options
context:
space:
mode:
Diffstat (limited to 'app/notification.go')
-rw-r--r--app/notification.go31
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 {