MM-61068 - send ws event on scheduled message job send (#29153)
Co-authored-by: Mattermost Build <build@mattermost.com>
Этот коммит содержится в:
@@ -1003,6 +1003,7 @@ type AppIface interface {
|
|||||||
ProcessScheduledPosts(rctx request.CTX)
|
ProcessScheduledPosts(rctx request.CTX)
|
||||||
ProcessSlackText(text string) string
|
ProcessSlackText(text string) string
|
||||||
Publish(message *model.WebSocketEvent)
|
Publish(message *model.WebSocketEvent)
|
||||||
|
PublishScheduledPostEvent(rctx request.CTX, eventType model.WebsocketEventType, scheduledPost *model.ScheduledPost, connectionId string)
|
||||||
PublishUserTyping(userID, channelID, parentId string) *model.AppError
|
PublishUserTyping(userID, channelID, parentId string) *model.AppError
|
||||||
PurgeBleveIndexes(c request.CTX) *model.AppError
|
PurgeBleveIndexes(c request.CTX) *model.AppError
|
||||||
PurgeElasticsearchIndexes(c request.CTX, indexes []string) *model.AppError
|
PurgeElasticsearchIndexes(c request.CTX, indexes []string) *model.AppError
|
||||||
|
|||||||
@@ -14064,6 +14064,21 @@ func (a *OpenTracingAppLayer) Publish(message *model.WebSocketEvent) {
|
|||||||
a.app.Publish(message)
|
a.app.Publish(message)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (a *OpenTracingAppLayer) PublishScheduledPostEvent(rctx request.CTX, eventType model.WebsocketEventType, scheduledPost *model.ScheduledPost, connectionId string) {
|
||||||
|
origCtx := a.ctx
|
||||||
|
span, newCtx := tracing.StartSpanWithParentByContext(a.ctx, "app.PublishScheduledPostEvent")
|
||||||
|
|
||||||
|
a.ctx = newCtx
|
||||||
|
a.app.Srv().Store().SetContext(newCtx)
|
||||||
|
defer func() {
|
||||||
|
a.app.Srv().Store().SetContext(origCtx)
|
||||||
|
a.ctx = origCtx
|
||||||
|
}()
|
||||||
|
|
||||||
|
defer span.Finish()
|
||||||
|
a.app.PublishScheduledPostEvent(rctx, eventType, scheduledPost, connectionId)
|
||||||
|
}
|
||||||
|
|
||||||
func (a *OpenTracingAppLayer) PublishUserTyping(userID string, channelID string, parentId string) *model.AppError {
|
func (a *OpenTracingAppLayer) PublishUserTyping(userID string, channelID string, parentId string) *model.AppError {
|
||||||
origCtx := a.ctx
|
origCtx := a.ctx
|
||||||
span, newCtx := tracing.StartSpanWithParentByContext(a.ctx, "app.PublishUserTyping")
|
span, newCtx := tracing.StartSpanWithParentByContext(a.ctx, "app.PublishUserTyping")
|
||||||
|
|||||||
@@ -34,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)
|
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)
|
||||||
}
|
}
|
||||||
|
|
||||||
publishScheduledPostEvent(a, rctx, model.WebsocketScheduledPostCreated, savedScheduledPost, connectionId)
|
a.PublishScheduledPostEvent(rctx, model.WebsocketScheduledPostCreated, savedScheduledPost, connectionId)
|
||||||
|
|
||||||
return savedScheduledPost, nil
|
return savedScheduledPost, nil
|
||||||
}
|
}
|
||||||
@@ -85,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)
|
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)
|
||||||
}
|
}
|
||||||
|
|
||||||
publishScheduledPostEvent(a, rctx, model.WebsocketScheduledPostUpdated, scheduledPost, connectionId)
|
a.PublishScheduledPostEvent(rctx, model.WebsocketScheduledPostUpdated, scheduledPost, connectionId)
|
||||||
|
|
||||||
return scheduledPost, nil
|
return scheduledPost, nil
|
||||||
}
|
}
|
||||||
@@ -108,12 +108,12 @@ 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)
|
return nil, model.NewAppError("app.DeleteScheduledPost", "app.delete_scheduled_post.delete_error", map[string]any{"user_id": userId, "scheduled_post_id": scheduledPostId}, "", http.StatusInternalServerError)
|
||||||
}
|
}
|
||||||
|
|
||||||
publishScheduledPostEvent(a, rctx, model.WebsocketScheduledPostDeleted, scheduledPost, connectionId)
|
a.PublishScheduledPostEvent(rctx, model.WebsocketScheduledPostDeleted, scheduledPost, connectionId)
|
||||||
|
|
||||||
return scheduledPost, nil
|
return scheduledPost, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func publishScheduledPostEvent(a *App, rctx request.CTX, eventType model.WebsocketEventType, scheduledPost *model.ScheduledPost, connectionId string) {
|
func (a *App) PublishScheduledPostEvent(rctx request.CTX, eventType model.WebsocketEventType, scheduledPost *model.ScheduledPost, connectionId string) {
|
||||||
if scheduledPost == nil {
|
if scheduledPost == nil {
|
||||||
rctx.Logger().Warn("publishScheduledPostEvent called with nil scheduledPost")
|
rctx.Logger().Warn("publishScheduledPostEvent called with nil scheduledPost")
|
||||||
return
|
return
|
||||||
|
|||||||
@@ -227,6 +227,9 @@ func (a *App) postScheduledPost(rctx request.CTX, scheduledPost *model.Scheduled
|
|||||||
return scheduledPost, appErr
|
return scheduledPost, appErr
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// send the WS event to delete the just posted scheduledPost from list
|
||||||
|
a.PublishScheduledPostEvent(rctx, model.WebsocketScheduledPostDeleted, scheduledPost, "")
|
||||||
|
|
||||||
return scheduledPost, nil
|
return scheduledPost, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -361,6 +364,8 @@ func (a *App) handleFailedScheduledPosts(rctx request.CTX, failedScheduledPosts
|
|||||||
mlog.Err(err),
|
mlog.Err(err),
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
// send WS event for updating the scheduled post with the error code
|
||||||
|
a.PublishScheduledPostEvent(rctx, model.WebsocketScheduledPostUpdated, failedScheduledPost, "")
|
||||||
}
|
}
|
||||||
|
|
||||||
if len(failedScheduledPosts) > 0 {
|
if len(failedScheduledPosts) > 0 {
|
||||||
|
|||||||
Ссылка в новой задаче
Block a user