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
Этот коммит содержится в:
@@ -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 {
|
||||
|
||||
Ссылка в новой задаче
Block a user