MM-45317: global drafts endpoints and ws events (#20614)
* MM-23881: global drafts endpoints and ws events Adds endpoints: - create/update drafts - delete draft - get drafts Adds WS events: - draft_updated - draft_created - draft_deleted * Ordering and WS event name fixes * Adds PostID to the drafts table In the future the drafts will include edited posts, this commit adds the post id in the combined pkey of the table. * Fixes route for deleting a thread draft * Fixes failed checks * Fixes migrations * Fixes migration * Extract translation strings * Removes PostID since we won't sync editing posts * Fixes tests * Fixes i18n * Update migrations for global drafts * update branch with latest master changes * Add feature flag for global drafts * Set global drafts feature flag default to true * Added support for files in drafts * Fix failing i18n check * Added support for deleting files in drafts * Revert "Added support for deleting files in drafts" This reverts commit 45dfd04a760359de2e8814d652c9ef46daf994f6. * Triggering new test server * Add config setting 'AllowSyncedDrafts' for syncing drafts with server * Triggering new test server * Triggering new test server * Add guard for config setting and add initial tests * Fix i18n and lint errors * Triggering new test server * Add tests for drafts * fix lint issues * Add tests for model/draft * Triggering new test server * Triggering new test server * Trigger new test server * Address PR comments * Change left join to regular join in GetDraftsForUser * Fix broken test Maybe consider adding an inclDeleted field if we want to get deleted drafts in the future * fix translations * Add store tests for drafts * fix test naming * remove comment * update migrations * set feature flag default to false * update migrations Co-authored-by: Mylon Suren <mylonsuren@gmail.com> Co-authored-by: Mattermod <mattermod@users.noreply.github.com>
Этот коммит содержится в:
@@ -42,6 +42,7 @@ const (
|
||||
StatusFail = "FAIL"
|
||||
StatusUnhealthy = "UNHEALTHY"
|
||||
StatusRemove = "REMOVE"
|
||||
ConnectionId = "Connection-Id"
|
||||
|
||||
ClientDir = "client"
|
||||
|
||||
@@ -433,6 +434,10 @@ func (c *Client4) commandMoveRoute(commandId string) string {
|
||||
return fmt.Sprintf(c.commandsRoute()+"/%v/move", commandId)
|
||||
}
|
||||
|
||||
func (c *Client4) draftsRoute() string {
|
||||
return "/drafts"
|
||||
}
|
||||
|
||||
func (c *Client4) emojisRoute() string {
|
||||
return "/emoji"
|
||||
}
|
||||
@@ -6229,6 +6234,59 @@ func (c *Client4) GetChannelPoliciesForUser(userID string, offset, limit int) (*
|
||||
return &channels, BuildResponse(r), nil
|
||||
}
|
||||
|
||||
// Drafts Sections
|
||||
|
||||
// UpsertDraft will create a new draft or update a draft if it already exists
|
||||
func (c *Client4) UpsertDraft(draft *Draft) (*Draft, *Response, error) {
|
||||
buf, err := json.Marshal(draft)
|
||||
if err != nil {
|
||||
return nil, nil, NewAppError("UpsertDraft", "api.marshal_error", nil, "", http.StatusInternalServerError).Wrap(err)
|
||||
}
|
||||
|
||||
r, err := c.DoAPIPostBytes(c.draftsRoute(), buf)
|
||||
if err != nil {
|
||||
return nil, BuildResponse(r), err
|
||||
}
|
||||
defer closeBody(r)
|
||||
|
||||
var df Draft
|
||||
err = json.NewDecoder(r.Body).Decode(&df)
|
||||
if err != nil {
|
||||
return nil, nil, NewAppError("UpsertDraft", "api.unmarshal_error", nil, "", http.StatusInternalServerError).Wrap(err)
|
||||
}
|
||||
return &df, BuildResponse(r), err
|
||||
}
|
||||
|
||||
// GetDrafts will get all drafts for a user
|
||||
func (c *Client4) GetDrafts(userId, teamId string) ([]*Draft, *Response, error) {
|
||||
r, err := c.DoAPIGet(c.userRoute(userId)+c.teamRoute(teamId)+"/drafts", "")
|
||||
if err != nil {
|
||||
return nil, BuildResponse(r), err
|
||||
}
|
||||
defer closeBody(r)
|
||||
var drafts []*Draft
|
||||
err = json.NewDecoder(r.Body).Decode(&drafts)
|
||||
if err != nil {
|
||||
return nil, nil, NewAppError("GetDrafts", "api.unmarshal_error", nil, "", http.StatusInternalServerError).Wrap(err)
|
||||
}
|
||||
return drafts, BuildResponse(r), nil
|
||||
}
|
||||
|
||||
func (c *Client4) DeleteDraft(userId, channelId, rootId string) (*Draft, *Response, error) {
|
||||
r, err := c.DoAPIDelete(c.userRoute(userId) + c.channelRoute(channelId) + "/drafts")
|
||||
if err != nil {
|
||||
return nil, BuildResponse(r), err
|
||||
}
|
||||
defer closeBody(r)
|
||||
|
||||
var df *Draft
|
||||
err = json.NewDecoder(r.Body).Decode(&df)
|
||||
if err != nil {
|
||||
return nil, BuildResponse(r), NewAppError("DeleteDraft", "api.marshal_error", nil, "", http.StatusInternalServerError).Wrap(err)
|
||||
}
|
||||
return df, BuildResponse(r), nil
|
||||
}
|
||||
|
||||
// Commands Section
|
||||
|
||||
// CreateCommand will create a new command if the user have the right permissions.
|
||||
|
||||
Ссылка в новой задаче
Block a user