diff options
author | Pradeep Murugesan <pradeepmurugesan@outlook.com> | 2018-07-12 17:32:26 +0200 |
---|---|---|
committer | Harrison Healey <harrisonmhealey@gmail.com> | 2018-07-12 11:32:26 -0400 |
commit | 8cad7070acc537d070edd1029fe0c6ce422ab0ed (patch) | |
tree | 57f42bd3b75684e4b4e6727fbb72314010616f54 /app/reaction.go | |
parent | d0c6834e1d165ba8d970d2d37c46730155f96010 (diff) | |
download | chat-8cad7070acc537d070edd1029fe0c6ce422ab0ed.tar.gz chat-8cad7070acc537d070edd1029fe0c6ce422ab0ed.tar.bz2 chat-8cad7070acc537d070edd1029fe0c6ce422ab0ed.zip |
GH-6278 hasReactions flag is set to true only if the post contains reactions (#9053)
Diffstat (limited to 'app/reaction.go')
-rw-r--r-- | app/reaction.go | 13 |
1 files changed, 9 insertions, 4 deletions
diff --git a/app/reaction.go b/app/reaction.go index 062622f34..db00ce2ad 100644 --- a/app/reaction.go +++ b/app/reaction.go @@ -19,7 +19,7 @@ func (a *App) SaveReactionForPost(reaction *model.Reaction) (*model.Reaction, *m reaction = result.Data.(*model.Reaction) a.Go(func() { - a.sendReactionEvent(model.WEBSOCKET_EVENT_REACTION_ADDED, reaction, post) + a.sendReactionEvent(model.WEBSOCKET_EVENT_REACTION_ADDED, reaction, post, true) }) return reaction, nil @@ -40,18 +40,23 @@ func (a *App) DeleteReactionForPost(reaction *model.Reaction) *model.AppError { return err } + hasReactions := true + if reactions, _ := a.GetReactionsForPost(post.Id); len(reactions) <= 1 { + hasReactions = false + } + if result := <-a.Srv.Store.Reaction().Delete(reaction); result.Err != nil { return result.Err } else { a.Go(func() { - a.sendReactionEvent(model.WEBSOCKET_EVENT_REACTION_REMOVED, reaction, post) + a.sendReactionEvent(model.WEBSOCKET_EVENT_REACTION_REMOVED, reaction, post, hasReactions) }) } return nil } -func (a *App) sendReactionEvent(event string, reaction *model.Reaction, post *model.Post) { +func (a *App) sendReactionEvent(event string, reaction *model.Reaction, post *model.Post, hasReactions bool) { // send out that a reaction has been added/removed message := model.NewWebSocketEvent(event, "", post.ChannelId, "", nil) message.Add("reaction", reaction.ToJson()) @@ -59,7 +64,7 @@ func (a *App) sendReactionEvent(event string, reaction *model.Reaction, post *mo // The post is always modified since the UpdateAt always changes a.InvalidateCacheForChannelPosts(post.ChannelId) - post.HasReactions = true + post.HasReactions = hasReactions post.UpdateAt = model.GetMillis() umessage := model.NewWebSocketEvent(model.WEBSOCKET_EVENT_POST_EDITED, "", post.ChannelId, "", nil) umessage.Add("post", a.PostWithProxyAddedToImageURLs(post).ToJson()) |