summaryrefslogtreecommitdiffstats
path: root/app
diff options
context:
space:
mode:
authorJoram Wilander <jwawilander@gmail.com>2017-02-13 10:52:50 -0500
committerCorey Hulen <corey@hulen.com>2017-02-13 10:52:50 -0500
commite4effd0c15a188eeec7a11f281e529afd6a54f80 (patch)
tree2c9b0f451366c54e163ac6f4743adf9e1cbd9a26 /app
parent260f1111e8988b177550d2621fbf99df178ca57a (diff)
downloadchat-e4effd0c15a188eeec7a11f281e529afd6a54f80.tar.gz
chat-e4effd0c15a188eeec7a11f281e529afd6a54f80.tar.bz2
chat-e4effd0c15a188eeec7a11f281e529afd6a54f80.zip
Implement some post endpoints for APIv4 (#5353)
* Implement POST /posts endpoint for APIv4 * Implement GET /channels/{channel_id}/posts endpoint for APIv4 * Implement GET /posts/{post_id} endpoint for APIv4 * Implement GET /posts/{post_id}/thread endpoint for APIv4 * Skip team get if it's a DM channel in handlePostEvents
Diffstat (limited to 'app')
-rw-r--r--app/post.go32
1 files changed, 24 insertions, 8 deletions
diff --git a/app/post.go b/app/post.go
index 5fddd3e78..dd8712e85 100644
--- a/app/post.go
+++ b/app/post.go
@@ -15,7 +15,7 @@ import (
"github.com/mattermost/platform/utils"
)
-func CreatePostAsUser(post *model.Post, teamId string) (*model.Post, *model.AppError) {
+func CreatePostAsUser(post *model.Post) (*model.Post, *model.AppError) {
// Check that channel has not been deleted
var channel *model.Channel
if result := <-Srv.Store.Channel().Get(post.ChannelId, true); result.Err != nil {
@@ -32,7 +32,7 @@ func CreatePostAsUser(post *model.Post, teamId string) (*model.Post, *model.AppE
return nil, err
}
- if rp, err := CreatePost(post, teamId, true); err != nil {
+ if rp, err := CreatePost(post, channel.TeamId, true); err != nil {
if err.Id == "api.post.create_post.root_id.app_error" ||
err.Id == "api.post.create_post.channel_root_id.app_error" ||
err.Id == "api.post.create_post.parent_id.app_error" {
@@ -118,15 +118,23 @@ func CreatePost(post *model.Post, teamId string, triggerWebhooks bool) (*model.P
}
func handlePostEvents(post *model.Post, teamId string, triggerWebhooks bool) *model.AppError {
- tchan := Srv.Store.Team().Get(teamId)
+ var tchan store.StoreChannel
+ if len(teamId) > 0 {
+ tchan = Srv.Store.Team().Get(teamId)
+ }
cchan := Srv.Store.Channel().Get(post.ChannelId, true)
uchan := Srv.Store.User().Get(post.UserId)
var team *model.Team
- if result := <-tchan; result.Err != nil {
- return result.Err
+ if tchan != nil {
+ if result := <-tchan; result.Err != nil {
+ return result.Err
+ } else {
+ team = result.Data.(*model.Team)
+ }
} else {
- team = result.Data.(*model.Team)
+ // Blank team for DMs
+ team = &model.Team{}
}
var channel *model.Channel
@@ -306,6 +314,14 @@ func UpdatePost(post *model.Post) (*model.Post, *model.AppError) {
}
}
+func GetPostsPage(channelId string, page int, perPage int) (*model.PostList, *model.AppError) {
+ if result := <-Srv.Store.Post().GetPosts(channelId, page*perPage, perPage, true); result.Err != nil {
+ return nil, result.Err
+ } else {
+ return result.Data.(*model.PostList), nil
+ }
+}
+
func GetPosts(channelId string, offset int, limit int) (*model.PostList, *model.AppError) {
if result := <-Srv.Store.Post().GetPosts(channelId, offset, limit, true); result.Err != nil {
return nil, result.Err
@@ -456,7 +472,7 @@ func SearchPostsInTeam(terms string, userId string, teamId string, isOrSearch bo
}
func GetFileInfosForPost(postId string) ([]*model.FileInfo, *model.AppError) {
- pchan := Srv.Store.Post().Get(postId)
+ pchan := Srv.Store.Post().GetSingle(postId)
fchan := Srv.Store.FileInfo().GetForPost(postId, true)
var infos []*model.FileInfo
@@ -472,7 +488,7 @@ func GetFileInfosForPost(postId string) ([]*model.FileInfo, *model.AppError) {
if result := <-pchan; result.Err != nil {
return nil, result.Err
} else {
- post = result.Data.(*model.PostList).Posts[postId]
+ post = result.Data.(*model.Post)
}
if len(post.Filenames) > 0 {