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
Этот коммит содержится в:
коммит произвёл
GitHub
родитель
07bad4d6d5
Коммит
97558f6a6e
@@ -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 {
|
||||
|
||||
Ссылка в новой задаче
Block a user