Skip to content

Commit

Permalink
Fix MM 56723 (#26643) (#26866)
Browse files Browse the repository at this point in the history
Automatic Merge
  • Loading branch information
larkox committed Apr 24, 2024
1 parent 1859303 commit f48ad12
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 1 deletion.
27 changes: 26 additions & 1 deletion server/channels/app/notification_push.go
Expand Up @@ -14,6 +14,7 @@ import (
"strings"
"sync"

"github.com/golang-jwt/jwt/v5"
"github.com/mattermost/mattermost/server/public/plugin"

"github.com/mattermost/mattermost/server/public/model"
Expand All @@ -27,6 +28,12 @@ type notificationType string
type notifyPropsReason string
type statusReason string

type pushJWTClaims struct {
AckId string `json:"ack_id"`
DeviceId string `json:"device_id"`
jwt.RegisteredClaims
}

const (
notificationTypeClear notificationType = "clear"
notificationTypeMessage notificationType = "message"
Expand Down Expand Up @@ -161,8 +168,26 @@ func (a *App) sendPushNotificationToAllSessions(msg *model.PushNotification, use
tmpMessage := msg.DeepCopy()
tmpMessage.SetDeviceIdAndPlatform(session.DeviceId)
tmpMessage.AckId = model.NewId()
signature, err := jwt.NewWithClaims(jwt.SigningMethodES256, pushJWTClaims{
AckId: tmpMessage.AckId,
DeviceId: tmpMessage.DeviceId,
}).SignedString(a.AsymmetricSigningKey())

if err != nil {
a.NotificationsLog().Error("Notification error",
mlog.String("ackId", tmpMessage.AckId),
mlog.String("type", tmpMessage.Type),
mlog.String("userId", session.UserId),
mlog.String("postId", tmpMessage.PostId),
mlog.String("channelId", tmpMessage.ChannelId),
mlog.String("deviceId", tmpMessage.DeviceId),
mlog.String("status", err.Error()),
)
continue
}
tmpMessage.Signature = signature

err := a.sendToPushProxy(tmpMessage, session)
err = a.sendToPushProxy(tmpMessage, session)
if err != nil {
a.NotificationsLog().Error("Failed to send to push proxy",
mlog.String("type", model.TypePush),
Expand Down
1 change: 1 addition & 0 deletions server/public/model/push_notification.go
Expand Up @@ -77,6 +77,7 @@ type PushNotification struct {
IsIdLoaded bool `json:"is_id_loaded"`
PostType string `json:"-"`
ChannelType ChannelType `json:"-"`
Signature string `json:"signature"`
}

func (pn *PushNotification) DeepCopy() *PushNotification {
Expand Down

0 comments on commit f48ad12

Please sign in to comment.