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>
Этот коммит содержится в:
@@ -26,6 +26,7 @@ type TimerLayer struct {
|
||||
CommandStore store.CommandStore
|
||||
CommandWebhookStore store.CommandWebhookStore
|
||||
ComplianceStore store.ComplianceStore
|
||||
DraftStore store.DraftStore
|
||||
EmojiStore store.EmojiStore
|
||||
FileInfoStore store.FileInfoStore
|
||||
GroupStore store.GroupStore
|
||||
@@ -92,6 +93,10 @@ func (s *TimerLayer) Compliance() store.ComplianceStore {
|
||||
return s.ComplianceStore
|
||||
}
|
||||
|
||||
func (s *TimerLayer) Draft() store.DraftStore {
|
||||
return s.DraftStore
|
||||
}
|
||||
|
||||
func (s *TimerLayer) Emoji() store.EmojiStore {
|
||||
return s.EmojiStore
|
||||
}
|
||||
@@ -260,6 +265,11 @@ type TimerLayerComplianceStore struct {
|
||||
Root *TimerLayer
|
||||
}
|
||||
|
||||
type TimerLayerDraftStore struct {
|
||||
store.DraftStore
|
||||
Root *TimerLayer
|
||||
}
|
||||
|
||||
type TimerLayerEmojiStore struct {
|
||||
store.EmojiStore
|
||||
Root *TimerLayer
|
||||
@@ -2955,6 +2965,86 @@ func (s *TimerLayerComplianceStore) Update(compliance *model.Compliance) (*model
|
||||
return result, err
|
||||
}
|
||||
|
||||
func (s *TimerLayerDraftStore) Delete(userID string, channelID string, rootID string) error {
|
||||
start := time.Now()
|
||||
|
||||
err := s.DraftStore.Delete(userID, channelID, rootID)
|
||||
|
||||
elapsed := float64(time.Since(start)) / float64(time.Second)
|
||||
if s.Root.Metrics != nil {
|
||||
success := "false"
|
||||
if err == nil {
|
||||
success = "true"
|
||||
}
|
||||
s.Root.Metrics.ObserveStoreMethodDuration("DraftStore.Delete", success, elapsed)
|
||||
}
|
||||
return err
|
||||
}
|
||||
|
||||
func (s *TimerLayerDraftStore) Get(userID string, channelID string, rootID string) (*model.Draft, error) {
|
||||
start := time.Now()
|
||||
|
||||
result, err := s.DraftStore.Get(userID, channelID, rootID)
|
||||
|
||||
elapsed := float64(time.Since(start)) / float64(time.Second)
|
||||
if s.Root.Metrics != nil {
|
||||
success := "false"
|
||||
if err == nil {
|
||||
success = "true"
|
||||
}
|
||||
s.Root.Metrics.ObserveStoreMethodDuration("DraftStore.Get", success, elapsed)
|
||||
}
|
||||
return result, err
|
||||
}
|
||||
|
||||
func (s *TimerLayerDraftStore) GetDraftsForUser(userID string, teamID string) ([]*model.Draft, error) {
|
||||
start := time.Now()
|
||||
|
||||
result, err := s.DraftStore.GetDraftsForUser(userID, teamID)
|
||||
|
||||
elapsed := float64(time.Since(start)) / float64(time.Second)
|
||||
if s.Root.Metrics != nil {
|
||||
success := "false"
|
||||
if err == nil {
|
||||
success = "true"
|
||||
}
|
||||
s.Root.Metrics.ObserveStoreMethodDuration("DraftStore.GetDraftsForUser", success, elapsed)
|
||||
}
|
||||
return result, err
|
||||
}
|
||||
|
||||
func (s *TimerLayerDraftStore) Save(d *model.Draft) (*model.Draft, error) {
|
||||
start := time.Now()
|
||||
|
||||
result, err := s.DraftStore.Save(d)
|
||||
|
||||
elapsed := float64(time.Since(start)) / float64(time.Second)
|
||||
if s.Root.Metrics != nil {
|
||||
success := "false"
|
||||
if err == nil {
|
||||
success = "true"
|
||||
}
|
||||
s.Root.Metrics.ObserveStoreMethodDuration("DraftStore.Save", success, elapsed)
|
||||
}
|
||||
return result, err
|
||||
}
|
||||
|
||||
func (s *TimerLayerDraftStore) Update(d *model.Draft) (*model.Draft, error) {
|
||||
start := time.Now()
|
||||
|
||||
result, err := s.DraftStore.Update(d)
|
||||
|
||||
elapsed := float64(time.Since(start)) / float64(time.Second)
|
||||
if s.Root.Metrics != nil {
|
||||
success := "false"
|
||||
if err == nil {
|
||||
success = "true"
|
||||
}
|
||||
s.Root.Metrics.ObserveStoreMethodDuration("DraftStore.Update", success, elapsed)
|
||||
}
|
||||
return result, err
|
||||
}
|
||||
|
||||
func (s *TimerLayerEmojiStore) Delete(emoji *model.Emoji, timestamp int64) error {
|
||||
start := time.Now()
|
||||
|
||||
@@ -11424,6 +11514,7 @@ func New(childStore store.Store, metrics einterfaces.MetricsInterface) *TimerLay
|
||||
newStore.CommandStore = &TimerLayerCommandStore{CommandStore: childStore.Command(), Root: &newStore}
|
||||
newStore.CommandWebhookStore = &TimerLayerCommandWebhookStore{CommandWebhookStore: childStore.CommandWebhook(), Root: &newStore}
|
||||
newStore.ComplianceStore = &TimerLayerComplianceStore{ComplianceStore: childStore.Compliance(), Root: &newStore}
|
||||
newStore.DraftStore = &TimerLayerDraftStore{DraftStore: childStore.Draft(), Root: &newStore}
|
||||
newStore.EmojiStore = &TimerLayerEmojiStore{EmojiStore: childStore.Emoji(), Root: &newStore}
|
||||
newStore.FileInfoStore = &TimerLayerFileInfoStore{FileInfoStore: childStore.FileInfo(), Root: &newStore}
|
||||
newStore.GroupStore = &TimerLayerGroupStore{GroupStore: childStore.Group(), Root: &newStore}
|
||||
|
||||
Ссылка в новой задаче
Block a user