Example #1
0
func sendReactionEvent(event string, channelId string, reaction *model.Reaction, postHadReactions bool) {
	// 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)
		}
	}()
}