GH-9688: Migrate to idiomatic error handling in app/post.go (#9697)

* Migrate to idiomatic error handling in app/post.go

* Revert import changes
Этот коммит содержится в:
Hanzei
2018-10-19 17:29:39 +02:00
коммит произвёл George Goldberg
родитель 2c849c7998
Коммит 6c6638f05e

Просмотреть файл

@@ -28,13 +28,12 @@ import (
func (a *App) CreatePostAsUser(post *model.Post, clearPushNotifications bool) (*model.Post, *model.AppError) { func (a *App) CreatePostAsUser(post *model.Post, clearPushNotifications bool) (*model.Post, *model.AppError) {
// Check that channel has not been deleted // Check that channel has not been deleted
var channel *model.Channel result := <-a.Srv.Store.Channel().Get(post.ChannelId, true)
if result := <-a.Srv.Store.Channel().Get(post.ChannelId, true); result.Err != nil { if result.Err != nil {
err := model.NewAppError("CreatePostAsUser", "api.context.invalid_param.app_error", map[string]interface{}{"Name": "post.channel_id"}, result.Err.Error(), http.StatusBadRequest) err := model.NewAppError("CreatePostAsUser", "api.context.invalid_param.app_error", map[string]interface{}{"Name": "post.channel_id"}, result.Err.Error(), http.StatusBadRequest)
return nil, err return nil, err
} else {
channel = result.Data.(*model.Channel)
} }
channel := result.Data.(*model.Channel)
if strings.HasPrefix(post.Type, model.POST_SYSTEM_MESSAGE_PREFIX) { if strings.HasPrefix(post.Type, model.POST_SYSTEM_MESSAGE_PREFIX) {
err := model.NewAppError("CreatePostAsUser", "api.context.invalid_param.app_error", map[string]interface{}{"Name": "post.type"}, "", http.StatusBadRequest) err := model.NewAppError("CreatePostAsUser", "api.context.invalid_param.app_error", map[string]interface{}{"Name": "post.type"}, "", http.StatusBadRequest)
@@ -46,7 +45,8 @@ func (a *App) CreatePostAsUser(post *model.Post, clearPushNotifications bool) (*
return nil, err return nil, err
} }
if rp, err := a.CreatePost(post, channel, true); err != nil { rp, err := a.CreatePost(post, channel, true)
if err != nil {
if err.Id == "api.post.create_post.root_id.app_error" || 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.channel_root_id.app_error" ||
err.Id == "api.post.create_post.parent_id.app_error" { err.Id == "api.post.create_post.parent_id.app_error" {
@@ -54,13 +54,11 @@ func (a *App) CreatePostAsUser(post *model.Post, clearPushNotifications bool) (*
} }
if err.Id == "api.post.create_post.town_square_read_only" { if err.Id == "api.post.create_post.town_square_read_only" {
uchan := a.Srv.Store.User().Get(post.UserId) result := <-a.Srv.Store.User().Get(post.UserId)
var user *model.User if result.Err != nil {
if result := <-uchan; result.Err != nil {
return nil, result.Err return nil, result.Err
} else {
user = result.Data.(*model.User)
} }
user := result.Data.(*model.User)
T := utils.GetUserTranslations(user.Locale) T := utils.GetUserTranslations(user.Locale)
a.SendEphemeralPost( a.SendEphemeralPost(
@@ -75,9 +73,9 @@ func (a *App) CreatePostAsUser(post *model.Post, clearPushNotifications bool) (*
}, },
) )
} }
return nil, err return nil, err
} else { }
// Update the LastViewAt only if the post does not have from_webhook prop set (eg. Zapier app) // Update the LastViewAt only if the post does not have from_webhook prop set (eg. Zapier app)
if _, ok := post.Props["from_webhook"]; !ok { if _, ok := post.Props["from_webhook"]; !ok {
if _, err := a.MarkChannelsAsViewed([]string{post.ChannelId}, post.UserId, clearPushNotifications); err != nil { if _, err := a.MarkChannelsAsViewed([]string{post.ChannelId}, post.UserId, clearPushNotifications); err != nil {
@@ -86,18 +84,14 @@ func (a *App) CreatePostAsUser(post *model.Post, clearPushNotifications bool) (*
} }
return rp, nil return rp, nil
}
} }
func (a *App) CreatePostMissingChannel(post *model.Post, triggerWebhooks bool) (*model.Post, *model.AppError) { func (a *App) CreatePostMissingChannel(post *model.Post, triggerWebhooks bool) (*model.Post, *model.AppError) {
var channel *model.Channel result := <-a.Srv.Store.Channel().Get(post.ChannelId, true)
cchan := a.Srv.Store.Channel().Get(post.ChannelId, true) if result.Err != nil {
if result := <-cchan; result.Err != nil {
return nil, result.Err return nil, result.Err
} else {
channel = result.Data.(*model.Channel)
} }
channel := result.Data.(*model.Channel)
return a.CreatePost(post, channel, triggerWebhooks) return a.CreatePost(post, channel, triggerWebhooks)
} }
@@ -110,13 +104,11 @@ func (a *App) CreatePost(post *model.Post, channel *model.Channel, triggerWebhoo
pchan = a.Srv.Store.Post().Get(post.RootId) pchan = a.Srv.Store.Post().Get(post.RootId)
} }
uchan := a.Srv.Store.User().Get(post.UserId) result := <-a.Srv.Store.User().Get(post.UserId)
var user *model.User if result.Err != nil {
if result := <-uchan; result.Err != nil {
return nil, result.Err return nil, result.Err
} else {
user = result.Data.(*model.User)
} }
user := result.Data.(*model.User)
if a.License() != nil && *a.Config().TeamSettings.ExperimentalTownSquareIsReadOnly && if a.License() != nil && *a.Config().TeamSettings.ExperimentalTownSquareIsReadOnly &&
!post.IsSystemMessage() && !post.IsSystemMessage() &&
@@ -128,10 +120,11 @@ func (a *App) CreatePost(post *model.Post, channel *model.Channel, triggerWebhoo
// Verify the parent/child relationships are correct // Verify the parent/child relationships are correct
var parentPostList *model.PostList var parentPostList *model.PostList
if pchan != nil { if pchan != nil {
if presult := <-pchan; presult.Err != nil { result = <-pchan
if result.Err != nil {
return nil, model.NewAppError("createPost", "api.post.create_post.root_id.app_error", nil, "", http.StatusBadRequest) return nil, model.NewAppError("createPost", "api.post.create_post.root_id.app_error", nil, "", http.StatusBadRequest)
} else { }
parentPostList = presult.Data.(*model.PostList) parentPostList = result.Data.(*model.PostList)
if len(parentPostList.Posts) == 0 || !parentPostList.IsChannelId(post.ChannelId) { if len(parentPostList.Posts) == 0 || !parentPostList.IsChannelId(post.ChannelId) {
return nil, model.NewAppError("createPost", "api.post.create_post.channel_root_id.app_error", nil, "", http.StatusInternalServerError) return nil, model.NewAppError("createPost", "api.post.create_post.channel_root_id.app_error", nil, "", http.StatusInternalServerError)
} }
@@ -147,7 +140,6 @@ func (a *App) CreatePost(post *model.Post, channel *model.Channel, triggerWebhoo
} }
} }
} }
}
post.Hashtags, _ = model.ParseHashtags(post.Message) post.Hashtags, _ = model.ParseHashtags(post.Message)
@@ -175,12 +167,11 @@ func (a *App) CreatePost(post *model.Post, channel *model.Channel, triggerWebhoo
} }
} }
var rpost *model.Post result = <-a.Srv.Store.Post().Save(post)
if result := <-a.Srv.Store.Post().Save(post); result.Err != nil { if result.Err != nil {
return nil, result.Err return nil, result.Err
} else {
rpost = result.Data.(*model.Post)
} }
rpost := result.Data.(*model.Post)
if a.PluginsReady() { if a.PluginsReady() {
a.Go(func() { a.Go(func() {
@@ -266,18 +257,13 @@ func (a *App) FillInPostProps(post *model.Post, channel *model.Channel) *model.A
} }
func (a *App) handlePostEvents(post *model.Post, user *model.User, channel *model.Channel, triggerWebhooks bool, parentPostList *model.PostList) *model.AppError { func (a *App) handlePostEvents(post *model.Post, user *model.User, channel *model.Channel, triggerWebhooks bool, parentPostList *model.PostList) *model.AppError {
var tchan store.StoreChannel
if len(channel.TeamId) > 0 {
tchan = a.Srv.Store.Team().Get(channel.TeamId)
}
var team *model.Team var team *model.Team
if tchan != nil { if len(channel.TeamId) > 0 {
if result := <-tchan; result.Err != nil { result := <-a.Srv.Store.Team().Get(channel.TeamId)
if result.Err != nil {
return result.Err return result.Err
} else {
team = result.Data.(*model.Team)
} }
team = result.Data.(*model.Team)
} else { } else {
// Blank team for DMs // Blank team for DMs
team = &model.Team{} team = &model.Team{}
@@ -325,11 +311,11 @@ func (a *App) SendEphemeralPost(userId string, post *model.Post) *model.Post {
func (a *App) UpdatePost(post *model.Post, safeUpdate bool) (*model.Post, *model.AppError) { func (a *App) UpdatePost(post *model.Post, safeUpdate bool) (*model.Post, *model.AppError) {
post.SanitizeProps() post.SanitizeProps()
var oldPost *model.Post result := <-a.Srv.Store.Post().Get(post.Id)
if result := <-a.Srv.Store.Post().Get(post.Id); result.Err != nil { if result.Err != nil {
return nil, result.Err return nil, result.Err
} else { }
oldPost = result.Data.(*model.PostList).Posts[post.Id] oldPost := result.Data.(*model.PostList).Posts[post.Id]
if oldPost == nil { if oldPost == nil {
err := model.NewAppError("UpdatePost", "api.post.update_post.find.app_error", nil, "id="+post.Id, http.StatusBadRequest) err := model.NewAppError("UpdatePost", "api.post.update_post.find.app_error", nil, "id="+post.Id, http.StatusBadRequest)
@@ -352,7 +338,6 @@ func (a *App) UpdatePost(post *model.Post, safeUpdate bool) (*model.Post, *model
return nil, err return nil, err
} }
} }
}
newPost := &model.Post{} newPost := &model.Post{}
*newPost = *oldPost *newPost = *oldPost
@@ -386,9 +371,10 @@ func (a *App) UpdatePost(post *model.Post, safeUpdate bool) (*model.Post, *model
} }
} }
if result := <-a.Srv.Store.Post().Update(newPost, oldPost); result.Err != nil { result = <-a.Srv.Store.Post().Update(newPost, oldPost)
if result.Err != nil {
return nil, result.Err return nil, result.Err
} else { }
rpost := result.Data.(*model.Post) rpost := result.Data.(*model.Post)
if a.PluginsReady() { if a.PluginsReady() {
@@ -404,11 +390,12 @@ func (a *App) UpdatePost(post *model.Post, safeUpdate bool) (*model.Post, *model
esInterface := a.Elasticsearch esInterface := a.Elasticsearch
if esInterface != nil && *a.Config().ElasticsearchSettings.EnableIndexing { if esInterface != nil && *a.Config().ElasticsearchSettings.EnableIndexing {
a.Go(func() { a.Go(func() {
if rchannel := <-a.Srv.Store.Channel().GetForPost(rpost.Id); rchannel.Err != nil { rchannel := <-a.Srv.Store.Channel().GetForPost(rpost.Id)
if rchannel.Err != nil {
mlog.Error(fmt.Sprintf("Couldn't get channel %v for post %v for Elasticsearch indexing.", rpost.ChannelId, rpost.Id)) mlog.Error(fmt.Sprintf("Couldn't get channel %v for post %v for Elasticsearch indexing.", rpost.ChannelId, rpost.Id))
} else { return
esInterface.IndexPost(rpost, rchannel.Data.(*model.Channel).TeamId)
} }
esInterface.IndexPost(rpost, rchannel.Data.(*model.Channel).TeamId)
}) })
} }
@@ -417,7 +404,6 @@ func (a *App) UpdatePost(post *model.Post, safeUpdate bool) (*model.Post, *model
a.InvalidateCacheForChannelPosts(rpost.ChannelId) a.InvalidateCacheForChannelPosts(rpost.ChannelId)
return rpost, nil return rpost, nil
}
} }
func (a *App) PatchPost(postId string, patch *model.PostPatch) (*model.Post, *model.AppError) { func (a *App) PatchPost(postId string, patch *model.PostPatch) (*model.Post, *model.AppError) {
@@ -443,19 +429,19 @@ func (a *App) sendUpdatedPostEvent(post *model.Post) {
} }
func (a *App) GetPostsPage(channelId string, page int, perPage int) (*model.PostList, *model.AppError) { func (a *App) GetPostsPage(channelId string, page int, perPage int) (*model.PostList, *model.AppError) {
if result := <-a.Srv.Store.Post().GetPosts(channelId, page*perPage, perPage, true); result.Err != nil { result := <-a.Srv.Store.Post().GetPosts(channelId, page*perPage, perPage, true)
if result.Err != nil {
return nil, result.Err return nil, result.Err
} else {
return result.Data.(*model.PostList), nil
} }
return result.Data.(*model.PostList), nil
} }
func (a *App) GetPosts(channelId string, offset int, limit int) (*model.PostList, *model.AppError) { func (a *App) GetPosts(channelId string, offset int, limit int) (*model.PostList, *model.AppError) {
if result := <-a.Srv.Store.Post().GetPosts(channelId, offset, limit, true); result.Err != nil { result := <-a.Srv.Store.Post().GetPosts(channelId, offset, limit, true)
if result.Err != nil {
return nil, result.Err return nil, result.Err
} else {
return result.Data.(*model.PostList), nil
} }
return result.Data.(*model.PostList), nil
} }
func (a *App) GetPostsEtag(channelId string) string { func (a *App) GetPostsEtag(channelId string) string {
@@ -463,57 +449,58 @@ func (a *App) GetPostsEtag(channelId string) string {
} }
func (a *App) GetPostsSince(channelId string, time int64) (*model.PostList, *model.AppError) { func (a *App) GetPostsSince(channelId string, time int64) (*model.PostList, *model.AppError) {
if result := <-a.Srv.Store.Post().GetPostsSince(channelId, time, true); result.Err != nil { result := <-a.Srv.Store.Post().GetPostsSince(channelId, time, true)
if result.Err != nil {
return nil, result.Err return nil, result.Err
} else {
return result.Data.(*model.PostList), nil
} }
return result.Data.(*model.PostList), nil
} }
func (a *App) GetSinglePost(postId string) (*model.Post, *model.AppError) { func (a *App) GetSinglePost(postId string) (*model.Post, *model.AppError) {
if result := <-a.Srv.Store.Post().GetSingle(postId); result.Err != nil { result := <-a.Srv.Store.Post().GetSingle(postId)
if result.Err != nil {
return nil, result.Err return nil, result.Err
} else {
return result.Data.(*model.Post), nil
} }
return result.Data.(*model.Post), nil
} }
func (a *App) GetPostThread(postId string) (*model.PostList, *model.AppError) { func (a *App) GetPostThread(postId string) (*model.PostList, *model.AppError) {
if result := <-a.Srv.Store.Post().Get(postId); result.Err != nil { result := <-a.Srv.Store.Post().Get(postId)
if result.Err != nil {
return nil, result.Err return nil, result.Err
} else {
return result.Data.(*model.PostList), nil
} }
return result.Data.(*model.PostList), nil
} }
func (a *App) GetFlaggedPosts(userId string, offset int, limit int) (*model.PostList, *model.AppError) { func (a *App) GetFlaggedPosts(userId string, offset int, limit int) (*model.PostList, *model.AppError) {
if result := <-a.Srv.Store.Post().GetFlaggedPosts(userId, offset, limit); result.Err != nil { result := <-a.Srv.Store.Post().GetFlaggedPosts(userId, offset, limit)
if result.Err != nil {
return nil, result.Err return nil, result.Err
} else {
return result.Data.(*model.PostList), nil
} }
return result.Data.(*model.PostList), nil
} }
func (a *App) GetFlaggedPostsForTeam(userId, teamId string, offset int, limit int) (*model.PostList, *model.AppError) { func (a *App) GetFlaggedPostsForTeam(userId, teamId string, offset int, limit int) (*model.PostList, *model.AppError) {
if result := <-a.Srv.Store.Post().GetFlaggedPostsForTeam(userId, teamId, offset, limit); result.Err != nil { result := <-a.Srv.Store.Post().GetFlaggedPostsForTeam(userId, teamId, offset, limit)
if result.Err != nil {
return nil, result.Err return nil, result.Err
} else {
return result.Data.(*model.PostList), nil
} }
return result.Data.(*model.PostList), nil
} }
func (a *App) GetFlaggedPostsForChannel(userId, channelId string, offset int, limit int) (*model.PostList, *model.AppError) { func (a *App) GetFlaggedPostsForChannel(userId, channelId string, offset int, limit int) (*model.PostList, *model.AppError) {
if result := <-a.Srv.Store.Post().GetFlaggedPostsForChannel(userId, channelId, offset, limit); result.Err != nil { result := <-a.Srv.Store.Post().GetFlaggedPostsForChannel(userId, channelId, offset, limit)
if result.Err != nil {
return nil, result.Err return nil, result.Err
} else {
return result.Data.(*model.PostList), nil
} }
return result.Data.(*model.PostList), nil
} }
func (a *App) GetPermalinkPost(postId string, userId string) (*model.PostList, *model.AppError) { func (a *App) GetPermalinkPost(postId string, userId string) (*model.PostList, *model.AppError) {
if result := <-a.Srv.Store.Post().Get(postId); result.Err != nil { result := <-a.Srv.Store.Post().Get(postId)
if result.Err != nil {
return nil, result.Err return nil, result.Err
} else { }
list := result.Data.(*model.PostList) list := result.Data.(*model.PostList)
if len(list.Order) != 1 { if len(list.Order) != 1 {
@@ -521,9 +508,8 @@ func (a *App) GetPermalinkPost(postId string, userId string) (*model.PostList, *
} }
post := list.Posts[list.Order[0]] post := list.Posts[list.Order[0]]
var channel *model.Channel channel, err := a.GetChannel(post.ChannelId)
var err *model.AppError if err != nil {
if channel, err = a.GetChannel(post.ChannelId); err != nil {
return nil, err return nil, err
} }
@@ -532,23 +518,22 @@ func (a *App) GetPermalinkPost(postId string, userId string) (*model.PostList, *
} }
return list, nil return list, nil
}
} }
func (a *App) GetPostsBeforePost(channelId, postId string, page, perPage int) (*model.PostList, *model.AppError) { func (a *App) GetPostsBeforePost(channelId, postId string, page, perPage int) (*model.PostList, *model.AppError) {
if result := <-a.Srv.Store.Post().GetPostsBefore(channelId, postId, perPage, page*perPage); result.Err != nil { result := <-a.Srv.Store.Post().GetPostsBefore(channelId, postId, perPage, page*perPage)
if result.Err != nil {
return nil, result.Err return nil, result.Err
} else {
return result.Data.(*model.PostList), nil
} }
return result.Data.(*model.PostList), nil
} }
func (a *App) GetPostsAfterPost(channelId, postId string, page, perPage int) (*model.PostList, *model.AppError) { func (a *App) GetPostsAfterPost(channelId, postId string, page, perPage int) (*model.PostList, *model.AppError) {
if result := <-a.Srv.Store.Post().GetPostsAfter(channelId, postId, perPage, page*perPage); result.Err != nil { result := <-a.Srv.Store.Post().GetPostsAfter(channelId, postId, perPage, page*perPage)
if result.Err != nil {
return nil, result.Err return nil, result.Err
} else {
return result.Data.(*model.PostList), nil
} }
return result.Data.(*model.PostList), nil
} }
func (a *App) GetPostsAroundPost(postId, channelId string, offset, limit int, before bool) (*model.PostList, *model.AppError) { func (a *App) GetPostsAroundPost(postId, channelId string, offset, limit int, before bool) (*model.PostList, *model.AppError) {
@@ -559,18 +544,19 @@ func (a *App) GetPostsAroundPost(postId, channelId string, offset, limit int, be
pchan = a.Srv.Store.Post().GetPostsAfter(channelId, postId, limit, offset) pchan = a.Srv.Store.Post().GetPostsAfter(channelId, postId, limit, offset)
} }
if result := <-pchan; result.Err != nil { result := <-pchan
if result.Err != nil {
return nil, result.Err return nil, result.Err
} else {
return result.Data.(*model.PostList), nil
} }
return result.Data.(*model.PostList), nil
} }
func (a *App) DeletePost(postId, deleteByID string) (*model.Post, *model.AppError) { func (a *App) DeletePost(postId, deleteByID string) (*model.Post, *model.AppError) {
if result := <-a.Srv.Store.Post().GetSingle(postId); result.Err != nil { result := <-a.Srv.Store.Post().GetSingle(postId)
if result.Err != nil {
result.Err.StatusCode = http.StatusBadRequest result.Err.StatusCode = http.StatusBadRequest
return nil, result.Err return nil, result.Err
} else { }
post := result.Data.(*model.Post) post := result.Data.(*model.Post)
if result := <-a.Srv.Store.Post().Delete(postId, model.GetMillis(), deleteByID); result.Err != nil { if result := <-a.Srv.Store.Post().Delete(postId, model.GetMillis(), deleteByID); result.Err != nil {
@@ -598,7 +584,6 @@ func (a *App) DeletePost(postId, deleteByID string) (*model.Post, *model.AppErro
a.InvalidateCacheForChannelPosts(post.ChannelId) a.InvalidateCacheForChannelPosts(post.ChannelId)
return post, nil return post, nil
}
} }
func (a *App) DeleteFlaggedPosts(postId string) { func (a *App) DeleteFlaggedPosts(postId string) {
@@ -660,7 +645,8 @@ func (a *App) SearchPostsInTeam(terms string, userId string, teamId string, isOr
includeDeleted := includeDeletedChannels && *a.Config().TeamSettings.ExperimentalViewArchivedChannels includeDeleted := includeDeletedChannels && *a.Config().TeamSettings.ExperimentalViewArchivedChannels
esInterface := a.Elasticsearch esInterface := a.Elasticsearch
if license := a.License(); esInterface != nil && *a.Config().ElasticsearchSettings.EnableSearching && license != nil && *license.Features.Elasticsearch { license := a.License()
if esInterface != nil && *a.Config().ElasticsearchSettings.EnableSearching && license != nil && *license.Features.Elasticsearch {
finalParamsList := []*model.SearchParams{} finalParamsList := []*model.SearchParams{}
for _, params := range paramsList { for _, params := range paramsList {
@@ -710,9 +696,10 @@ func (a *App) SearchPostsInTeam(terms string, userId string, teamId string, isOr
// Get the posts // Get the posts
postList := model.NewPostList() postList := model.NewPostList()
if len(postIds) > 0 { if len(postIds) > 0 {
if presult := <-a.Srv.Store.Post().GetPostsByIds(postIds); presult.Err != nil { presult := <-a.Srv.Store.Post().GetPostsByIds(postIds)
if presult.Err != nil {
return nil, presult.Err return nil, presult.Err
} else { }
for _, p := range presult.Data.([]*model.Post) { for _, p := range presult.Data.([]*model.Post) {
if p.DeleteAt == 0 { if p.DeleteAt == 0 {
postList.AddPost(p) postList.AddPost(p)
@@ -720,10 +707,10 @@ func (a *App) SearchPostsInTeam(terms string, userId string, teamId string, isOr
} }
} }
} }
}
return model.MakePostSearchResults(postList, matches), nil return model.MakePostSearchResults(postList, matches), nil
} else { }
if !*a.Config().ServiceSettings.EnablePostSearch { if !*a.Config().ServiceSettings.EnablePostSearch {
return nil, model.NewAppError("SearchPostsInTeam", "store.sql_post.search.disabled", nil, fmt.Sprintf("teamId=%v userId=%v", teamId, userId), http.StatusNotImplemented) return nil, model.NewAppError("SearchPostsInTeam", "store.sql_post.search.disabled", nil, fmt.Sprintf("teamId=%v userId=%v", teamId, userId), http.StatusNotImplemented)
} }
@@ -756,39 +743,35 @@ func (a *App) SearchPostsInTeam(terms string, userId string, teamId string, isOr
posts := model.NewPostList() posts := model.NewPostList()
for _, channel := range channels { for _, channel := range channels {
if result := <-channel; result.Err != nil { result := <-channel
if result.Err != nil {
return nil, result.Err return nil, result.Err
} else { }
data := result.Data.(*model.PostList) data := result.Data.(*model.PostList)
posts.Extend(data) posts.Extend(data)
} }
}
posts.SortByCreateAt() posts.SortByCreateAt()
return model.MakePostSearchResults(posts, nil), nil return model.MakePostSearchResults(posts, nil), nil
}
} }
func (a *App) GetFileInfosForPost(postId string, readFromMaster bool) ([]*model.FileInfo, *model.AppError) { func (a *App) GetFileInfosForPost(postId string, readFromMaster bool) ([]*model.FileInfo, *model.AppError) {
pchan := a.Srv.Store.Post().GetSingle(postId) pchan := a.Srv.Store.Post().GetSingle(postId)
fchan := a.Srv.Store.FileInfo().GetForPost(postId, readFromMaster, true)
var infos []*model.FileInfo result := <-a.Srv.Store.FileInfo().GetForPost(postId, readFromMaster, true)
if result := <-fchan; result.Err != nil { if result.Err != nil {
return nil, result.Err return nil, result.Err
} else {
infos = result.Data.([]*model.FileInfo)
} }
infos := result.Data.([]*model.FileInfo)
if len(infos) == 0 { if len(infos) == 0 {
// No FileInfos were returned so check if they need to be created for this post // No FileInfos were returned so check if they need to be created for this post
var post *model.Post result := <-pchan
if result := <-pchan; result.Err != nil { if result.Err != nil {
return nil, result.Err return nil, result.Err
} else {
post = result.Data.(*model.Post)
} }
post := result.Data.(*model.Post)
if len(post.Filenames) > 0 { if len(post.Filenames) > 0 {
a.Srv.Store.FileInfo().InvalidateFileInfosForPostCache(postId) a.Srv.Store.FileInfo().InvalidateFileInfosForPostCache(postId)
@@ -881,21 +864,19 @@ func makeOpenGraphURLsAbsolute(og *opengraph.OpenGraph, requestURL string) {
func (a *App) DoPostAction(postId, actionId, userId, selectedOption string) *model.AppError { func (a *App) DoPostAction(postId, actionId, userId, selectedOption string) *model.AppError {
pchan := a.Srv.Store.Post().GetSingle(postId) pchan := a.Srv.Store.Post().GetSingle(postId)
var post *model.Post
if result := <-pchan; result.Err != nil {
return result.Err
} else {
post = result.Data.(*model.Post)
}
cchan := a.Srv.Store.Channel().GetForPost(postId) cchan := a.Srv.Store.Channel().GetForPost(postId)
var channel *model.Channel
if result := <-cchan; result.Err != nil { result := <-pchan
if result.Err != nil {
return result.Err return result.Err
} else {
channel = result.Data.(*model.Channel)
} }
post := result.Data.(*model.Post)
result = <-cchan
if result.Err != nil {
return result.Err
}
channel := result.Data.(*model.Channel)
action := post.GetAction(actionId) action := post.GetAction(actionId)
if action == nil || action.Integration == nil { if action == nil || action.Integration == nil {
@@ -1090,12 +1071,10 @@ func (a *App) ImageProxyRemover() (f func(string) string) {
} }
func (a *App) MaxPostSize() int { func (a *App) MaxPostSize() int {
maxPostSize := model.POST_MESSAGE_MAX_RUNES_V1 result := <-a.Srv.Store.Post().GetMaxPostSize()
if result := <-a.Srv.Store.Post().GetMaxPostSize(); result.Err != nil { if result.Err != nil {
mlog.Error(fmt.Sprint(result.Err)) mlog.Error(fmt.Sprint(result.Err))
} else { return model.POST_MESSAGE_MAX_RUNES_V1
maxPostSize = result.Data.(int)
} }
return result.Data.(int)
return maxPostSize
} }