From 97558f6a6ec4c53fa69035fb430ead209d9c222d Mon Sep 17 00:00:00 2001 From: Joram Wilander Date: Fri, 13 Jan 2017 13:53:37 -0500 Subject: PLT-4938 Add app package and move logic over from api package (#4931) * Add app package and move logic over from api package * Change app package functions to return errors * Move non-api tests into app package * Fix merge --- api/reaction.go | 19 ++++++++++--------- 1 file changed, 10 insertions(+), 9 deletions(-) (limited to 'api/reaction.go') diff --git a/api/reaction.go b/api/reaction.go index 5acf09f9e..ac5df4516 100644 --- a/api/reaction.go +++ b/api/reaction.go @@ -6,6 +6,7 @@ package api import ( l4g "github.com/alecthomas/log4go" "github.com/gorilla/mux" + "github.com/mattermost/platform/app" "github.com/mattermost/platform/model" "github.com/mattermost/platform/utils" "net/http" @@ -50,7 +51,7 @@ func saveReaction(c *Context, w http.ResponseWriter, r *http.Request) { return } - pchan := Srv.Store.Post().Get(reaction.PostId) + pchan := app.Srv.Store.Post().Get(reaction.PostId) var postHadReactions bool if result := <-pchan; result.Err != nil { @@ -65,7 +66,7 @@ func saveReaction(c *Context, w http.ResponseWriter, r *http.Request) { postHadReactions = post.HasReactions } - if result := <-Srv.Store.Reaction().Save(reaction); result.Err != nil { + if result := <-app.Srv.Store.Reaction().Save(reaction); result.Err != nil { c.Err = result.Err return } else { @@ -108,7 +109,7 @@ func deleteReaction(c *Context, w http.ResponseWriter, r *http.Request) { return } - pchan := Srv.Store.Post().Get(reaction.PostId) + pchan := app.Srv.Store.Post().Get(reaction.PostId) var postHadReactions bool if result := <-pchan; result.Err != nil { @@ -123,7 +124,7 @@ func deleteReaction(c *Context, w http.ResponseWriter, r *http.Request) { postHadReactions = post.HasReactions } - if result := <-Srv.Store.Reaction().Delete(reaction); result.Err != nil { + if result := <-app.Srv.Store.Reaction().Delete(reaction); result.Err != nil { c.Err = result.Err return } else { @@ -139,13 +140,13 @@ func sendReactionEvent(event string, channelId string, reaction *model.Reaction, message := model.NewWebSocketEvent(event, "", channelId, "", nil) message.Add("reaction", reaction.ToJson()) - Publish(message) + app.Publish(message) }() // send out that a post was updated if post.HasReactions has changed go func() { var post *model.Post - if result := <-Srv.Store.Post().Get(reaction.PostId); result.Err != nil { + 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 { @@ -156,7 +157,7 @@ func sendReactionEvent(event string, channelId string, reaction *model.Reaction, message := model.NewWebSocketEvent(model.WEBSOCKET_EVENT_POST_EDITED, "", channelId, "", nil) message.Add("post", post.ToJson()) - Publish(message) + app.Publish(message) } }() } @@ -176,7 +177,7 @@ func listReactions(c *Context, w http.ResponseWriter, r *http.Request) { return } - pchan := Srv.Store.Post().Get(postId) + pchan := app.Srv.Store.Post().Get(postId) if !HasPermissionToChannelContext(c, channelId, model.PERMISSION_READ_CHANNEL) { return @@ -192,7 +193,7 @@ func listReactions(c *Context, w http.ResponseWriter, r *http.Request) { return } - if result := <-Srv.Store.Reaction().GetForPost(postId); result.Err != nil { + if result := <-app.Srv.Store.Reaction().GetForPost(postId); result.Err != nil { c.Err = result.Err return } else { -- cgit v1.2.3-1-g7c22