Properly unset active channel in the server (#26846)
* Properly unset active channel in the server * Address feedback --------- Co-authored-by: Mattermost Build <build@mattermost.com>
Этот коммит содержится в:
коммит произвёл
GitHub
родитель
69fe5c06e4
Коммит
c22509eca2
@@ -618,7 +618,7 @@ func (a *App) SendNotifications(c request.CTX, post *model.Post, team *model.Tea
|
||||
status = &model.Status{UserId: id, Status: model.StatusOffline, Manual: false, LastActivityAt: 0, ActiveChannel: ""}
|
||||
}
|
||||
|
||||
if statusReason := DoesStatusAllowPushNotification(profileMap[id].NotifyProps, status, post.ChannelId); statusReason == "" {
|
||||
if statusReason := DoesStatusAllowPushNotification(profileMap[id].NotifyProps, status, post.ChannelId, true); statusReason == "" {
|
||||
a.sendPushNotification(
|
||||
notification,
|
||||
profileMap[id],
|
||||
|
||||
@@ -590,7 +590,7 @@ func (a *App) ShouldSendPushNotification(user *model.User, channelNotifyProps mo
|
||||
return false
|
||||
}
|
||||
|
||||
if statusAllowedReason := DoesStatusAllowPushNotification(user.NotifyProps, status, post.ChannelId); statusAllowedReason != "" {
|
||||
if statusAllowedReason := DoesStatusAllowPushNotification(user.NotifyProps, status, post.ChannelId, false); statusAllowedReason != "" {
|
||||
a.CountNotificationReason(model.NotificationStatusNotSent, model.NotificationTypePush, statusAllowedReason)
|
||||
a.NotificationsLog().Debug("Notification not sent - status",
|
||||
mlog.String("type", model.NotificationTypePush),
|
||||
@@ -648,14 +648,18 @@ func DoesNotifyPropsAllowPushNotification(user *model.User, channelNotifyProps m
|
||||
return ""
|
||||
}
|
||||
|
||||
func DoesStatusAllowPushNotification(userNotifyProps model.StringMap, status *model.Status, channelID string) model.NotificationReason {
|
||||
func DoesStatusAllowPushNotification(userNotifyProps model.StringMap, status *model.Status, channelID string, isCRT bool) model.NotificationReason {
|
||||
// If User status is DND or OOO return false right away
|
||||
if status.Status == model.StatusDnd || status.Status == model.StatusOutOfOffice {
|
||||
return model.NotificationReasonUserStatus
|
||||
}
|
||||
|
||||
pushStatus, ok := userNotifyProps[model.PushStatusNotifyProp]
|
||||
if (pushStatus == model.StatusOnline || !ok) && (status.ActiveChannel != channelID || model.GetMillis()-status.LastActivityAt > model.StatusChannelTimeout) {
|
||||
sendOnlineNotification := status.ActiveChannel != channelID || //We are in a different channel
|
||||
model.GetMillis()-status.LastActivityAt > model.StatusChannelTimeout || //It has been a while since we were last active on this channel
|
||||
isCRT //Is CRT, so being active in a channel doesn't mean you are seeing thread activity
|
||||
|
||||
if (pushStatus == model.StatusOnline || !ok) && sendOnlineNotification {
|
||||
return ""
|
||||
}
|
||||
|
||||
|
||||
@@ -441,12 +441,14 @@ func TestDoesStatusAllowPushNotification(t *testing.T) {
|
||||
away := &model.Status{UserId: userID, Status: model.StatusAway, Manual: false, LastActivityAt: 0, ActiveChannel: ""}
|
||||
online := &model.Status{UserId: userID, Status: model.StatusOnline, Manual: false, LastActivityAt: model.GetMillis(), ActiveChannel: ""}
|
||||
dnd := &model.Status{UserId: userID, Status: model.StatusDnd, Manual: true, LastActivityAt: model.GetMillis(), ActiveChannel: ""}
|
||||
activeOnChannel := &model.Status{UserId: userID, Status: model.StatusOnline, Manual: false, LastActivityAt: model.GetMillis(), ActiveChannel: channelID}
|
||||
|
||||
tt := []struct {
|
||||
name string
|
||||
userNotifySetting string
|
||||
status *model.Status
|
||||
channelID string
|
||||
isCRT bool
|
||||
expected model.NotificationReason
|
||||
}{
|
||||
{
|
||||
@@ -491,6 +493,21 @@ func TestDoesStatusAllowPushNotification(t *testing.T) {
|
||||
channelID: "",
|
||||
expected: model.NotificationReasonUserIsActive,
|
||||
},
|
||||
{
|
||||
name: "WHEN props is ONLINE and user is online and active within the channel",
|
||||
userNotifySetting: model.StatusOnline,
|
||||
status: activeOnChannel,
|
||||
channelID: channelID,
|
||||
expected: model.NotificationReasonUserIsActive,
|
||||
},
|
||||
{
|
||||
name: "WHEN props is ONLINE and user is online and active within a thread in the channel",
|
||||
userNotifySetting: model.StatusOnline,
|
||||
status: activeOnChannel,
|
||||
channelID: channelID,
|
||||
expected: "",
|
||||
isCRT: true,
|
||||
},
|
||||
{
|
||||
name: "WHEN props is ONLINE and user is dnd with channel",
|
||||
userNotifySetting: model.StatusOnline,
|
||||
@@ -623,7 +640,7 @@ func TestDoesStatusAllowPushNotification(t *testing.T) {
|
||||
t.Run(tc.name, func(t *testing.T) {
|
||||
userNotifyProps := make(map[string]string)
|
||||
userNotifyProps["push_status"] = tc.userNotifySetting
|
||||
assert.Equal(t, tc.expected, DoesStatusAllowPushNotification(userNotifyProps, tc.status, tc.channelID))
|
||||
assert.Equal(t, tc.expected, DoesStatusAllowPushNotification(userNotifyProps, tc.status, tc.channelID, tc.isCRT))
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
Ссылка в новой задаче
Block a user