summaryrefslogtreecommitdiffstats
path: root/api
diff options
context:
space:
mode:
authorCorey Hulen <corey@hulen.com>2017-02-22 10:48:47 -0500
committerGitHub <noreply@github.com>2017-02-22 10:48:47 -0500
commitc7bf42218e24a8c584b5c4ef2e9245004ee53938 (patch)
tree4b3ba9bd03b39f9784df529ffed0dbcd55529149 /api
parent4a0aba719b018a36d1029230d146e0b8b1168977 (diff)
downloadchat-c7bf42218e24a8c584b5c4ef2e9245004ee53938.tar.gz
chat-c7bf42218e24a8c584b5c4ef2e9245004ee53938.tar.bz2
chat-c7bf42218e24a8c584b5c4ef2e9245004ee53938.zip
Fixing emoji reactions and Aurora read replica issue for master (#5499)
Diffstat (limited to 'api')
-rw-r--r--api/reaction.go61
1 files changed, 22 insertions, 39 deletions
diff --git a/api/reaction.go b/api/reaction.go
index fd9a05779..cc1e61efd 100644
--- a/api/reaction.go
+++ b/api/reaction.go
@@ -52,26 +52,23 @@ func saveReaction(c *Context, w http.ResponseWriter, r *http.Request) {
return
}
- pchan := app.Srv.Store.Post().Get(reaction.PostId)
+ var post *model.Post
- var postHadReactions bool
- if result := <-pchan; result.Err != nil {
+ if result := <-app.Srv.Store.Post().Get(reaction.PostId); result.Err != nil {
c.Err = result.Err
return
- } else if post := result.Data.(*model.PostList).Posts[postId]; post.ChannelId != channelId {
+ } else if post = result.Data.(*model.PostList).Posts[postId]; post.ChannelId != channelId {
c.Err = model.NewLocAppError("saveReaction", "api.reaction.save_reaction.mismatched_channel_id.app_error",
nil, "channelId="+channelId+", post.ChannelId="+post.ChannelId+", postId="+postId)
c.Err.StatusCode = http.StatusBadRequest
return
- } else {
- postHadReactions = post.HasReactions
}
if result := <-app.Srv.Store.Reaction().Save(reaction); result.Err != nil {
c.Err = result.Err
return
} else {
- go sendReactionEvent(model.WEBSOCKET_EVENT_REACTION_ADDED, channelId, reaction, postHadReactions)
+ go sendReactionEvent(model.WEBSOCKET_EVENT_REACTION_ADDED, channelId, reaction, post)
reaction := result.Data.(*model.Reaction)
@@ -111,57 +108,43 @@ func deleteReaction(c *Context, w http.ResponseWriter, r *http.Request) {
return
}
- pchan := app.Srv.Store.Post().Get(reaction.PostId)
+ var post *model.Post
- var postHadReactions bool
- if result := <-pchan; result.Err != nil {
+ if result := <-app.Srv.Store.Post().Get(reaction.PostId); result.Err != nil {
c.Err = result.Err
return
- } else if post := result.Data.(*model.PostList).Posts[postId]; post.ChannelId != channelId {
+ } else if post = result.Data.(*model.PostList).Posts[postId]; post.ChannelId != channelId {
c.Err = model.NewLocAppError("deleteReaction", "api.reaction.delete_reaction.mismatched_channel_id.app_error",
nil, "channelId="+channelId+", post.ChannelId="+post.ChannelId+", postId="+postId)
c.Err.StatusCode = http.StatusBadRequest
return
- } else {
- postHadReactions = post.HasReactions
}
if result := <-app.Srv.Store.Reaction().Delete(reaction); result.Err != nil {
c.Err = result.Err
return
} else {
- go sendReactionEvent(model.WEBSOCKET_EVENT_REACTION_REMOVED, channelId, reaction, postHadReactions)
+ go sendReactionEvent(model.WEBSOCKET_EVENT_REACTION_REMOVED, channelId, reaction, post)
ReturnStatusOK(w)
}
}
-func sendReactionEvent(event string, channelId string, reaction *model.Reaction, postHadReactions bool) {
+func sendReactionEvent(event string, channelId string, reaction *model.Reaction, post *model.Post) {
// send out that a reaction has been added/removed
- go func() {
- message := model.NewWebSocketEvent(event, "", channelId, "", nil)
- message.Add("reaction", reaction.ToJson())
-
- app.Publish(message)
- }()
-
- // send out that a post was updated if post.HasReactions has changed
- go func() {
- var post *model.Post
- if result := <-app.Srv.Store.Post().Get(reaction.PostId); result.Err != nil {
- l4g.Warn(utils.T("api.reaction.send_reaction_event.post.app_error"))
- return
- } else {
- post = result.Data.(*model.PostList).Posts[reaction.PostId]
- }
-
- if post.HasReactions != postHadReactions {
- message := model.NewWebSocketEvent(model.WEBSOCKET_EVENT_POST_EDITED, "", channelId, "", nil)
- message.Add("post", post.ToJson())
-
- app.Publish(message)
- }
- }()
+
+ message := model.NewWebSocketEvent(event, "", channelId, "", nil)
+ message.Add("reaction", reaction.ToJson())
+ app.Publish(message)
+
+ // THe post is always modified since the UpdateAt always changes
+ app.InvalidateCacheForChannelPosts(post.ChannelId)
+ post.HasReactions = true
+ post.UpdateAt = model.GetMillis()
+ umessage := model.NewWebSocketEvent(model.WEBSOCKET_EVENT_POST_EDITED, "", channelId, "", nil)
+ umessage.Add("post", post.ToJson())
+ app.Publish(umessage)
+
}
func listReactions(c *Context, w http.ResponseWriter, r *http.Request) {