MM-60124-emit and read create scheduled post WS event (#28844)
* MM-60124-emit and read create scheduled post WS event * fix unit test; reorder get team id logic; use userid for ws events * MM-60145 - ws events on update scheduled posts (#28871) * MM-60145 - ws events on update scheduled posts * MM-60147 - ws events on delete scheduled posts (#28872) * MM-60147 - ws events on delete scheduled posts * remove unnecessary channelID * remove unnecesary memoization
Этот коммит содержится в:
@@ -4,13 +4,15 @@
|
||||
package app
|
||||
|
||||
import (
|
||||
"encoding/json"
|
||||
"net/http"
|
||||
|
||||
"github.com/mattermost/mattermost/server/public/model"
|
||||
"github.com/mattermost/mattermost/server/public/shared/mlog"
|
||||
"github.com/mattermost/mattermost/server/public/shared/request"
|
||||
)
|
||||
|
||||
func (a *App) SaveScheduledPost(rctx request.CTX, scheduledPost *model.ScheduledPost) (*model.ScheduledPost, *model.AppError) {
|
||||
func (a *App) SaveScheduledPost(rctx request.CTX, scheduledPost *model.ScheduledPost, connectionId string) (*model.ScheduledPost, *model.AppError) {
|
||||
maxMessageLength := a.Srv().Store().ScheduledPost().GetMaxMessageSize()
|
||||
scheduledPost.PreSave()
|
||||
if validationErr := scheduledPost.IsValid(maxMessageLength); validationErr != nil {
|
||||
@@ -32,7 +34,7 @@ func (a *App) SaveScheduledPost(rctx request.CTX, scheduledPost *model.Scheduled
|
||||
return nil, model.NewAppError("App.ScheduledPost", "app.save_scheduled_post.save.app_error", map[string]any{"user_id": scheduledPost.UserId, "channel_id": scheduledPost.ChannelId}, "", http.StatusBadRequest)
|
||||
}
|
||||
|
||||
// TODO: add WebSocket event broadcast here
|
||||
publishScheduledPostEvent(a, rctx, model.WebsocketScheduledPostCreated, savedScheduledPost, connectionId)
|
||||
|
||||
return savedScheduledPost, nil
|
||||
}
|
||||
@@ -54,7 +56,7 @@ func (a *App) GetUserTeamScheduledPosts(rctx request.CTX, userId, teamId string)
|
||||
return scheduledPosts, nil
|
||||
}
|
||||
|
||||
func (a *App) UpdateScheduledPost(rctx request.CTX, userId string, scheduledPost *model.ScheduledPost) (*model.ScheduledPost, *model.AppError) {
|
||||
func (a *App) UpdateScheduledPost(rctx request.CTX, userId string, scheduledPost *model.ScheduledPost, connectionId string) (*model.ScheduledPost, *model.AppError) {
|
||||
maxMessageLength := a.Srv().Store().ScheduledPost().GetMaxMessageSize()
|
||||
scheduledPost.PreUpdate()
|
||||
if validationErr := scheduledPost.IsValid(maxMessageLength); validationErr != nil {
|
||||
@@ -83,7 +85,7 @@ func (a *App) UpdateScheduledPost(rctx request.CTX, userId string, scheduledPost
|
||||
return nil, model.NewAppError("app.UpdateScheduledPost", "app.update_scheduled_post.update.error", map[string]any{"user_id": userId, "scheduled_post_id": scheduledPost.Id}, "", http.StatusInternalServerError)
|
||||
}
|
||||
|
||||
// TODO: add WebSocket event broadcast here. This will be done in a later PR
|
||||
publishScheduledPostEvent(a, rctx, model.WebsocketScheduledPostUpdated, scheduledPost, connectionId)
|
||||
|
||||
return scheduledPost, nil
|
||||
}
|
||||
@@ -106,7 +108,22 @@ func (a *App) DeleteScheduledPost(rctx request.CTX, userId, scheduledPostId, con
|
||||
return nil, model.NewAppError("app.DeleteScheduledPost", "app.delete_scheduled_post.delete_error", map[string]any{"user_id": userId, "scheduled_post_id": scheduledPostId}, "", http.StatusInternalServerError)
|
||||
}
|
||||
|
||||
// TODO: add WebSocket event broadcast here. This will be done in a later PR
|
||||
publishScheduledPostEvent(a, rctx, model.WebsocketScheduledPostDeleted, scheduledPost, connectionId)
|
||||
|
||||
return scheduledPost, nil
|
||||
}
|
||||
|
||||
func publishScheduledPostEvent(a *App, rctx request.CTX, eventType model.WebsocketEventType, scheduledPost *model.ScheduledPost, connectionId string) {
|
||||
if scheduledPost == nil {
|
||||
rctx.Logger().Warn("publishScheduledPostEvent called with nil scheduledPost")
|
||||
return
|
||||
}
|
||||
message := model.NewWebSocketEvent(eventType, "", "", scheduledPost.UserId, nil, connectionId)
|
||||
scheduledPostJSON, jsonErr := json.Marshal(scheduledPost)
|
||||
if jsonErr != nil {
|
||||
rctx.Logger().Warn("publishScheduledPostEvent - Failed to Marshal", mlog.Err(jsonErr))
|
||||
return
|
||||
}
|
||||
message.Add("scheduledPost", string(scheduledPostJSON))
|
||||
a.Publish(message)
|
||||
}
|
||||
|
||||
Ссылка в новой задаче
Block a user