Skip to content

Commit

Permalink
Respect send push proxy notification configuration on test notificati…
Browse files Browse the repository at this point in the history
…ons (#20063) (#20169)

Automatic Merge
  • Loading branch information
mattermost-build authored May 10, 2022
1 parent 03822b5 commit e84b3b1
Show file tree
Hide file tree
Showing 4 changed files with 22 additions and 19 deletions.
2 changes: 1 addition & 1 deletion app/channel.go
Original file line number Diff line number Diff line change
Expand Up @@ -2904,7 +2904,7 @@ func (a *App) SearchChannelsUserNotIn(teamID string, userID string, term string)
func (a *App) MarkChannelsAsViewed(channelIDs []string, userID string, currentSessionId string, collapsedThreadsSupported bool) (map[string]int64, *model.AppError) {
// I start looking for channels with notifications before I mark it as read, to clear the push notifications if needed
channelsToClearPushNotifications := []string{}
if *a.Config().EmailSettings.SendPushNotifications {
if a.canSendPushNotifications() {
for _, channelID := range channelIDs {
channel, errCh := a.Srv().Store.Channel().Get(channelID, true)
if errCh != nil {
Expand Down
8 changes: 2 additions & 6 deletions app/expirynotify.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,12 +17,8 @@ const (

// NotifySessionsExpired is called periodically from the job server to notify any mobile sessions that have expired.
func (a *App) NotifySessionsExpired() error {
if *a.Config().EmailSettings.SendPushNotifications {
pushServer := *a.Config().EmailSettings.PushNotificationServer
if license := a.ch.srv.License(); pushServer == model.MHPNS && (license == nil || !*license.Features.MHPNS) {
mlog.Warn("Push notifications are disabled. Go to System Console > Notifications > Mobile Push to enable them.")
return nil
}
if !a.canSendPushNotifications() {
return nil
}

// Get all mobile sessions that expired within the last hour.
Expand Down
27 changes: 15 additions & 12 deletions app/notification.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,20 @@ import (
"github.com/mattermost/mattermost-server/v6/store"
)

func (a *App) canSendPushNotifications() bool {
if !*a.Config().EmailSettings.SendPushNotifications {
return false
}

pushServer := *a.Config().EmailSettings.PushNotificationServer
if license := a.Srv().License(); pushServer == model.MHPNS && (license == nil || !*license.Features.MHPNS) {
mlog.Warn("Push notifications have been disabled. Update your license or go to System Console > Environment > Push Notification Server to use a different server")
return false
}

return true
}

func (a *App) SendNotifications(post *model.Post, team *model.Team, channel *model.Channel, sender *model.User, parentPostList *model.PostList, setOnline bool) ([]string, error) {
// Do not send notifications in archived channels
if channel.DeleteAt > 0 {
Expand Down Expand Up @@ -401,18 +415,7 @@ func (a *App) SendNotifications(post *model.Post, team *model.Team, channel *mod
}
}

sendPushNotifications := false
if *a.Config().EmailSettings.SendPushNotifications {
pushServer := *a.Config().EmailSettings.PushNotificationServer
if license := a.Srv().License(); pushServer == model.MHPNS && (license == nil || !*license.Features.MHPNS) {
mlog.Warn("Push notifications are disabled. Go to System Console > Notifications > Mobile Push to enable them.")
sendPushNotifications = false
} else {
sendPushNotifications = true
}
}

if sendPushNotifications {
if a.canSendPushNotifications() {
for _, id := range mentionedUsersList {
if profileMap[id] == nil || notificationsForCRT.Push.Contains(id) {
continue
Expand Down
4 changes: 4 additions & 0 deletions app/notification_push.go
Original file line number Diff line number Diff line change
Expand Up @@ -578,6 +578,10 @@ func (a *App) BuildPushNotificationMessage(contentsConfig string, post *model.Po
}

func (a *App) SendTestPushNotification(deviceID string) string {
if !a.canSendPushNotifications() {
return "false"
}

msg := &model.PushNotification{
Version: "2",
Type: model.PushTypeTest,
Expand Down

0 comments on commit e84b3b1

Please sign in to comment.