2019-11-29 06:59:40 -05:00
|
|
|
// Copyright (c) 2015-present Mattermost, Inc. All Rights Reserved.
|
|
|
|
|
// See LICENSE.txt for license information.
|
2017-03-28 04:58:19 -04:00
|
|
|
|
|
|
|
|
package wsapi
|
|
|
|
|
|
|
|
|
|
import (
|
2023-06-11 01:24:35 -04:00
|
|
|
"github.com/mattermost/mattermost/server/public/model"
|
2024-04-11 16:18:14 -04:00
|
|
|
"github.com/mattermost/mattermost/server/public/shared/mlog"
|
2017-03-28 04:58:19 -04:00
|
|
|
)
|
|
|
|
|
|
2017-09-27 12:52:34 -04:00
|
|
|
func (api *API) InitSystem() {
|
2021-08-16 13:46:44 -04:00
|
|
|
api.Router.Handle("ping", api.APIWebSocketHandler(ping))
|
2024-04-22 05:06:58 -04:00
|
|
|
api.Router.Handle(string(model.WebsocketPostedNotifyAck), api.APIWebSocketHandler(api.websocketNotificationAck))
|
2017-03-28 04:58:19 -04:00
|
|
|
}
|
|
|
|
|
|
2022-07-05 02:46:50 -04:00
|
|
|
func ping(req *model.WebSocketRequest) (map[string]any, *model.AppError) {
|
|
|
|
|
data := map[string]any{}
|
2017-03-28 04:58:19 -04:00
|
|
|
data["text"] = "pong"
|
|
|
|
|
data["version"] = model.CurrentVersion
|
|
|
|
|
data["server_time"] = model.GetMillis()
|
|
|
|
|
data["node_id"] = ""
|
|
|
|
|
|
|
|
|
|
return data, nil
|
|
|
|
|
}
|
2024-04-11 16:18:14 -04:00
|
|
|
|
|
|
|
|
func (api *API) websocketNotificationAck(req *model.WebSocketRequest) (map[string]any, *model.AppError) {
|
|
|
|
|
// Log the ACKs if necessary
|
2025-08-20 04:17:45 -04:00
|
|
|
api.App.Log().LogM(mlog.MlvlNotificationDebug, "Websocket notification acknowledgment",
|
2024-04-18 10:30:08 -04:00
|
|
|
mlog.String("type", model.NotificationTypeWebsocket),
|
2024-04-11 16:18:14 -04:00
|
|
|
mlog.String("user_id", req.Session.UserId),
|
|
|
|
|
mlog.Any("user_agent", req.Data["user_agent"]),
|
|
|
|
|
mlog.Any("post_id", req.Data["post_id"]),
|
2024-04-18 10:30:08 -04:00
|
|
|
mlog.Any("status", req.Data["status"]),
|
2024-04-11 16:18:14 -04:00
|
|
|
mlog.Any("reason", req.Data["reason"]),
|
|
|
|
|
mlog.Any("data", req.Data["data"]),
|
|
|
|
|
)
|
|
|
|
|
|
2024-04-18 10:30:08 -04:00
|
|
|
// Count metrics for websocket acks
|
2024-07-05 03:34:01 -04:00
|
|
|
api.App.CountNotificationAck(model.NotificationTypeWebsocket, model.NotificationNoPlatform)
|
2024-04-18 10:30:08 -04:00
|
|
|
|
|
|
|
|
status := req.Data["status"]
|
|
|
|
|
reason := req.Data["reason"]
|
|
|
|
|
if status == nil {
|
|
|
|
|
return nil, nil
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
notificationStatus := model.NotificationStatus(status.(string))
|
|
|
|
|
if reason == nil && notificationStatus != model.NotificationStatusSuccess {
|
|
|
|
|
return nil, nil
|
|
|
|
|
}
|
|
|
|
|
var notificationReason model.NotificationReason
|
|
|
|
|
if reason != nil {
|
|
|
|
|
notificationReason = model.NotificationReason(reason.(string))
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
api.App.CountNotificationReason(
|
|
|
|
|
notificationStatus,
|
|
|
|
|
model.NotificationTypeWebsocket,
|
|
|
|
|
notificationReason,
|
2024-07-05 03:34:01 -04:00
|
|
|
model.NotificationNoPlatform,
|
2024-04-18 10:30:08 -04:00
|
|
|
)
|
|
|
|
|
|
2024-04-11 16:18:14 -04:00
|
|
|
return nil, nil
|
|
|
|
|
}
|