diff options
author | Martin Kraft <mkraft@users.noreply.github.com> | 2018-06-01 12:45:46 -0400 |
---|---|---|
committer | GitHub <noreply@github.com> | 2018-06-01 12:45:46 -0400 |
commit | 260d7a0f850a6f772b14b011022f1f65213a08a1 (patch) | |
tree | 1090ef2c0c1447be9e64baecd0d7336514922927 /store/sqlstore/post_store.go | |
parent | 5992a729c50989b7a39e42a0aaed42bc3914fb13 (diff) | |
download | chat-260d7a0f850a6f772b14b011022f1f65213a08a1.tar.gz chat-260d7a0f850a6f772b14b011022f1f65213a08a1.tar.bz2 chat-260d7a0f850a6f772b14b011022f1f65213a08a1.zip |
MM-10412: Adds deleteBy prop to posts. (#8896)
Diffstat (limited to 'store/sqlstore/post_store.go')
-rw-r--r-- | store/sqlstore/post_store.go | 19 |
1 files changed, 16 insertions, 3 deletions
diff --git a/store/sqlstore/post_store.go b/store/sqlstore/post_store.go index e4872fe11..229005b73 100644 --- a/store/sqlstore/post_store.go +++ b/store/sqlstore/post_store.go @@ -398,11 +398,24 @@ func (s *SqlPostStore) GetEtag(channelId string, allowFromCache bool) store.Stor }) } -func (s *SqlPostStore) Delete(postId string, time int64) store.StoreChannel { +func (s *SqlPostStore) Delete(postId string, time int64, deleteByID string) store.StoreChannel { return store.Do(func(result *store.StoreResult) { - _, err := s.GetMaster().Exec("Update Posts SET DeleteAt = :DeleteAt, UpdateAt = :UpdateAt WHERE Id = :Id OR RootId = :RootId", map[string]interface{}{"DeleteAt": time, "UpdateAt": time, "Id": postId, "RootId": postId}) + + appErr := func(errMsg string) *model.AppError { + return model.NewAppError("SqlPostStore.Delete", "store.sql_post.delete.app_error", nil, "id="+postId+", err="+errMsg, http.StatusInternalServerError) + } + + var post model.Post + err := s.GetReplica().SelectOne(&post, "SELECT * FROM Posts WHERE Id = :Id AND DeleteAt = 0", map[string]interface{}{"Id": postId}) + if err != nil { + result.Err = appErr(err.Error()) + } + + post.Props[model.POST_PROPS_DELETE_BY] = deleteByID + + _, err = s.GetMaster().Exec("UPDATE Posts SET DeleteAt = :DeleteAt, UpdateAt = :UpdateAt, Props = :Props WHERE Id = :Id OR RootId = :RootId", map[string]interface{}{"DeleteAt": time, "UpdateAt": time, "Id": postId, "RootId": postId, "Props": model.StringInterfaceToJson(post.Props)}) if err != nil { - result.Err = model.NewAppError("SqlPostStore.Delete", "store.sql_post.delete.app_error", nil, "id="+postId+", err="+err.Error(), http.StatusInternalServerError) + result.Err = appErr(err.Error()) } }) } |