Fixing emoji reactions and Aurora read replica issue for master (#5499)
Этот коммит содержится в:
@@ -52,26 +52,23 @@ func saveReaction(c *Context, w http.ResponseWriter, r *http.Request) {
|
|||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
pchan := app.Srv.Store.Post().Get(reaction.PostId)
|
var post *model.Post
|
||||||
|
|
||||||
var postHadReactions bool
|
if result := <-app.Srv.Store.Post().Get(reaction.PostId); result.Err != nil {
|
||||||
if result := <-pchan; result.Err != nil {
|
|
||||||
c.Err = result.Err
|
c.Err = result.Err
|
||||||
return
|
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",
|
c.Err = model.NewLocAppError("saveReaction", "api.reaction.save_reaction.mismatched_channel_id.app_error",
|
||||||
nil, "channelId="+channelId+", post.ChannelId="+post.ChannelId+", postId="+postId)
|
nil, "channelId="+channelId+", post.ChannelId="+post.ChannelId+", postId="+postId)
|
||||||
c.Err.StatusCode = http.StatusBadRequest
|
c.Err.StatusCode = http.StatusBadRequest
|
||||||
return
|
return
|
||||||
} else {
|
|
||||||
postHadReactions = post.HasReactions
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if result := <-app.Srv.Store.Reaction().Save(reaction); result.Err != nil {
|
if result := <-app.Srv.Store.Reaction().Save(reaction); result.Err != nil {
|
||||||
c.Err = result.Err
|
c.Err = result.Err
|
||||||
return
|
return
|
||||||
} else {
|
} 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)
|
reaction := result.Data.(*model.Reaction)
|
||||||
|
|
||||||
@@ -111,57 +108,43 @@ func deleteReaction(c *Context, w http.ResponseWriter, r *http.Request) {
|
|||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
pchan := app.Srv.Store.Post().Get(reaction.PostId)
|
var post *model.Post
|
||||||
|
|
||||||
var postHadReactions bool
|
if result := <-app.Srv.Store.Post().Get(reaction.PostId); result.Err != nil {
|
||||||
if result := <-pchan; result.Err != nil {
|
|
||||||
c.Err = result.Err
|
c.Err = result.Err
|
||||||
return
|
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",
|
c.Err = model.NewLocAppError("deleteReaction", "api.reaction.delete_reaction.mismatched_channel_id.app_error",
|
||||||
nil, "channelId="+channelId+", post.ChannelId="+post.ChannelId+", postId="+postId)
|
nil, "channelId="+channelId+", post.ChannelId="+post.ChannelId+", postId="+postId)
|
||||||
c.Err.StatusCode = http.StatusBadRequest
|
c.Err.StatusCode = http.StatusBadRequest
|
||||||
return
|
return
|
||||||
} else {
|
|
||||||
postHadReactions = post.HasReactions
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if result := <-app.Srv.Store.Reaction().Delete(reaction); result.Err != nil {
|
if result := <-app.Srv.Store.Reaction().Delete(reaction); result.Err != nil {
|
||||||
c.Err = result.Err
|
c.Err = result.Err
|
||||||
return
|
return
|
||||||
} else {
|
} else {
|
||||||
go sendReactionEvent(model.WEBSOCKET_EVENT_REACTION_REMOVED, channelId, reaction, postHadReactions)
|
go sendReactionEvent(model.WEBSOCKET_EVENT_REACTION_REMOVED, channelId, reaction, post)
|
||||||
|
|
||||||
ReturnStatusOK(w)
|
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
|
// send out that a reaction has been added/removed
|
||||||
go func() {
|
|
||||||
message := model.NewWebSocketEvent(event, "", channelId, "", nil)
|
message := model.NewWebSocketEvent(event, "", channelId, "", nil)
|
||||||
message.Add("reaction", reaction.ToJson())
|
message.Add("reaction", reaction.ToJson())
|
||||||
|
|
||||||
app.Publish(message)
|
app.Publish(message)
|
||||||
}()
|
|
||||||
|
|
||||||
// send out that a post was updated if post.HasReactions has changed
|
// THe post is always modified since the UpdateAt always changes
|
||||||
go func() {
|
app.InvalidateCacheForChannelPosts(post.ChannelId)
|
||||||
var post *model.Post
|
post.HasReactions = true
|
||||||
if result := <-app.Srv.Store.Post().Get(reaction.PostId); result.Err != nil {
|
post.UpdateAt = model.GetMillis()
|
||||||
l4g.Warn(utils.T("api.reaction.send_reaction_event.post.app_error"))
|
umessage := model.NewWebSocketEvent(model.WEBSOCKET_EVENT_POST_EDITED, "", channelId, "", nil)
|
||||||
return
|
umessage.Add("post", post.ToJson())
|
||||||
} else {
|
app.Publish(umessage)
|
||||||
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)
|
|
||||||
}
|
|
||||||
}()
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func listReactions(c *Context, w http.ResponseWriter, r *http.Request) {
|
func listReactions(c *Context, w http.ResponseWriter, r *http.Request) {
|
||||||
|
|||||||
Ссылка в новой задаче
Block a user