MM-37934: supports channel override for CRT notifications (#18529)

* MM-37934: supports channel override for CRT notifications

Users with CRT 'ON' are enabled to override global CRT notification
settings per channel basis.

* Fixes brain freeze :o

* Fix push notification for CRT

* Some refactor and comments as per review comments

* Minor refactor

Co-authored-by: Mattermod <mattermod@users.noreply.github.com>
Этот коммит содержится в:
Kyriakos Z
2021-10-28 11:05:46 +03:00
коммит произвёл GitHub
родитель 685b311401
Коммит 4f2043bf97
2 изменённых файлов: 77 добавлений и 12 удалений

Просмотреть файл

@@ -1202,6 +1202,10 @@ func (a *App) UpdateChannelMemberNotifyProps(data map[string]string, channelID s
filteredProps[model.DesktopNotifyProp] = desktop
}
if desktop_threads, exists := data[model.DesktopThreadsNotifyProp]; exists {
filteredProps[model.DesktopThreadsNotifyProp] = desktop_threads
}
if email, exists := data[model.EmailNotifyProp]; exists {
filteredProps[model.EmailNotifyProp] = email
}
@@ -1210,6 +1214,10 @@ func (a *App) UpdateChannelMemberNotifyProps(data map[string]string, channelID s
filteredProps[model.PushNotifyProp] = push
}
if push_threads, exists := data[model.PushThreadsNotifyProp]; exists {
filteredProps[model.PushThreadsNotifyProp] = push_threads
}
if ignoreChannelMentions, exists := data[model.IgnoreChannelMentionsNotifyProp]; exists {
filteredProps[model.IgnoreChannelMentionsNotifyProp] = ignoreChannelMentions
}

Просмотреть файл

@@ -329,7 +329,7 @@ func (a *App) SendNotifications(post *model.Post, team *model.Team, channel *mod
}
// add user id to notificationsForCRT depending on threads notify props
notificationsForCRT.addUserToNotify(profile, mentions)
notificationsForCRT.addFollowerToNotify(profile, mentions, channelMemberNotifyPropsMap[profile.Id], channel)
}
}
@@ -1338,28 +1338,85 @@ type CRTNotifiers struct {
Push model.StringArray
}
func (c *CRTNotifiers) addUserToNotify(user *model.User, mentions *ExplicitMentions) {
// user notify props
func (c *CRTNotifiers) addFollowerToNotify(user *model.User, mentions *ExplicitMentions, channelMemberNotificationProps model.StringMap, channel *model.Channel) {
_, userWasMentioned := mentions.Mentions[user.Id]
notifyDesktop, notifyPush, notifyEmail := shouldUserNotifyCRT(user, userWasMentioned)
notifyChannelDesktop, notifyChannelPush := shouldChannelMemberNotifyCRT(channelMemberNotificationProps, userWasMentioned)
// respect the user global notify props when there are no channel specific ones (default)
// otherwise respect the channel member's notify props
if (channelMemberNotificationProps[model.DesktopNotifyProp] == model.ChannelNotifyDefault && notifyDesktop) || notifyChannelDesktop {
c.Desktop = append(c.Desktop, user.Id)
}
if notifyEmail {
c.Email = append(c.Email, user.Id)
}
// respect the user global notify props when there are no channel specific ones (default)
// otherwise respect the channel member's notify props
if (channelMemberNotificationProps[model.PushNotifyProp] == model.ChannelNotifyDefault && notifyPush) || notifyChannelPush {
c.Push = append(c.Push, user.Id)
}
}
// user global settings check for desktop, email, and push notifications
func shouldUserNotifyCRT(user *model.User, isMentioned bool) (notifyDesktop, notifyPush, notifyEmail bool) {
notifyDesktop = false
notifyPush = false
notifyEmail = false
desktop := user.NotifyProps[model.DesktopNotifyProp]
push := user.NotifyProps[model.PushNotifyProp]
shouldEmail := user.NotifyProps[model.EmailNotifyProp] == "true"
// user thread notify props
desktopThreads := user.NotifyProps[model.DesktopThreadsNotifyProp]
emailThreads := user.NotifyProps[model.EmailThreadsNotifyProp]
pushThreads := user.NotifyProps[model.PushThreadsNotifyProp]
_, userWasMentioned := mentions.Mentions[user.Id]
if desktop != model.UserNotifyNone && (userWasMentioned || desktopThreads == model.UserNotifyAll || desktop == model.UserNotifyAll) {
c.Desktop = append(c.Desktop, user.Id)
// user should be notified via desktop notification in the case the notify prop is not set as no notify
// and either the user was mentioned or the CRT notify prop for desktop is set to all
if desktop != model.UserNotifyNone && (isMentioned || desktopThreads == model.UserNotifyAll || desktop == model.UserNotifyAll) {
notifyDesktop = true
}
if shouldEmail && (userWasMentioned || emailThreads == model.UserNotifyAll) {
c.Email = append(c.Email, user.Id)
// user should be notified via email when emailing is enabled and
// either the user was mentioned, or the CRT notify prop for email is set to all
if shouldEmail && (isMentioned || emailThreads == model.UserNotifyAll) {
notifyEmail = true
}
if push != model.UserNotifyNone && (userWasMentioned || pushThreads == model.UserNotifyAll || push == model.UserNotifyAll) {
c.Push = append(c.Push, user.Id)
// user should be notified via push in the case the notify prop is not set as no notify
// and either the user was mentioned or the CRT push notify prop is set to all
if push != model.UserNotifyNone && (isMentioned || pushThreads == model.UserNotifyAll || push == model.UserNotifyAll) {
notifyPush = true
}
return
}
// channel specific settings check for desktop and push notifications
func shouldChannelMemberNotifyCRT(notifyProps model.StringMap, isMentioned bool) (notifyDesktop, notifyPush bool) {
notifyDesktop = false
notifyPush = false
desktop := notifyProps[model.DesktopNotifyProp]
push := notifyProps[model.PushNotifyProp]
desktopThreads := notifyProps[model.DesktopThreadsNotifyProp]
pushThreads := notifyProps[model.PushThreadsNotifyProp]
// user should be notified via desktop notification in the case the notify prop is not set as no notify or default
// and either the user was mentioned or the CRT notify prop for desktop is set to all
if desktop != model.ChannelNotifyDefault && desktop != model.ChannelNotifyNone && (isMentioned || desktopThreads == model.ChannelNotifyAll || desktop == model.ChannelNotifyAll) {
notifyDesktop = true
}
// user should be notified via push in the case the notify prop is not set as no notify or default
// and either the user was mentioned or the CRT push notify prop is set to all
if push != model.ChannelNotifyDefault && push != model.ChannelNotifyNone && (isMentioned || pushThreads == model.ChannelNotifyAll || push == model.ChannelNotifyAll) {
notifyPush = true
}
return
}