summaryrefslogtreecommitdiffstats
path: root/store
diff options
context:
space:
mode:
authorGeorge Goldberg <george@gberg.me>2018-02-19 11:19:39 +0000
committerGeorge Goldberg <george@gberg.me>2018-02-19 11:19:39 +0000
commitf8289eb286d00c29859a8df495b957c7b46cb249 (patch)
tree1bc18d6a3a795482c7229786f7ab427fabbcd007 /store
parent8891fa2a5e9e08eb9fa99ec163c47a6e9761a816 (diff)
parent30197584d5a215a3b25bffa79a034ed9e360cf52 (diff)
downloadchat-f8289eb286d00c29859a8df495b957c7b46cb249.tar.gz
chat-f8289eb286d00c29859a8df495b957c7b46cb249.tar.bz2
chat-f8289eb286d00c29859a8df495b957c7b46cb249.zip
Merge branch 'master' into advanced-permissions-phase-1
Diffstat (limited to 'store')
-rw-r--r--store/sqlstore/supplier_reactions.go26
1 files changed, 20 insertions, 6 deletions
diff --git a/store/sqlstore/supplier_reactions.go b/store/sqlstore/supplier_reactions.go
index 052472bf9..aa3b078ea 100644
--- a/store/sqlstore/supplier_reactions.go
+++ b/store/sqlstore/supplier_reactions.go
@@ -134,7 +134,7 @@ func (s *SqlSupplier) ReactionDeleteAllWithEmojiName(ctx context.Context, emojiN
}
for _, reaction := range reactions {
- if _, err := s.GetMaster().Exec(UPDATE_POST_HAS_REACTIONS_QUERY,
+ if _, err := s.GetMaster().Exec(UPDATE_POST_HAS_REACTIONS_ON_DELETE_QUERY,
map[string]interface{}{"PostId": reaction.PostId, "UpdateAt": model.GetMillis()}); err != nil {
l4g.Warn(utils.T("store.sql_reaction.delete_all_with_emoji_name.update_post.warn"), reaction.PostId, err.Error())
}
@@ -174,7 +174,7 @@ func saveReactionAndUpdatePost(transaction *gorp.Transaction, reaction *model.Re
return err
}
- return updatePostForReactions(transaction, reaction.PostId)
+ return updatePostForReactionsOnInsert(transaction, reaction.PostId)
}
func deleteReactionAndUpdatePost(transaction *gorp.Transaction, reaction *model.Reaction) error {
@@ -189,12 +189,12 @@ func deleteReactionAndUpdatePost(transaction *gorp.Transaction, reaction *model.
return err
}
- return updatePostForReactions(transaction, reaction.PostId)
+ return updatePostForReactionsOnDelete(transaction, reaction.PostId)
}
const (
// Set HasReactions = true if and only if the post has reactions, update UpdateAt only if HasReactions changes
- UPDATE_POST_HAS_REACTIONS_QUERY = `UPDATE
+ UPDATE_POST_HAS_REACTIONS_ON_DELETE_QUERY = `UPDATE
Posts
SET
UpdateAt = (CASE
@@ -206,8 +206,22 @@ const (
Id = :PostId`
)
-func updatePostForReactions(transaction *gorp.Transaction, postId string) error {
- _, err := transaction.Exec(UPDATE_POST_HAS_REACTIONS_QUERY, map[string]interface{}{"PostId": postId, "UpdateAt": model.GetMillis()})
+func updatePostForReactionsOnDelete(transaction *gorp.Transaction, postId string) error {
+ _, err := transaction.Exec(UPDATE_POST_HAS_REACTIONS_ON_DELETE_QUERY, map[string]interface{}{"PostId": postId, "UpdateAt": model.GetMillis()})
+
+ return err
+}
+
+func updatePostForReactionsOnInsert(transaction *gorp.Transaction, postId string) error {
+ _, err := transaction.Exec(
+ `UPDATE
+ Posts
+ SET
+ HasReactions = True,
+ UpdateAt = :UpdateAt
+ WHERE
+ Id = :PostId AND HasReactions = False`,
+ map[string]interface{}{"PostId": postId, "UpdateAt": model.GetMillis()})
return err
}