mirror of
https://github.com/mattermost/mattermost.git
synced 2025-02-25 18:55:24 -06:00
PLT-7 adding loc db calls for posts table
This commit is contained in:
@@ -159,7 +159,7 @@ func getAnalytics(c *Context, w http.ResponseWriter, r *http.Request) {
|
||||
rows[2] = &model.AnalyticsRow{"post_count", 0}
|
||||
openChan := Srv.Store.Channel().AnalyticsTypeCount(c.T, teamId, model.CHANNEL_OPEN)
|
||||
privateChan := Srv.Store.Channel().AnalyticsTypeCount(c.T, teamId, model.CHANNEL_PRIVATE)
|
||||
postChan := Srv.Store.Post().AnalyticsPostCount(teamId)
|
||||
postChan := Srv.Store.Post().AnalyticsPostCount(c.T, teamId)
|
||||
|
||||
if r := <-openChan; r.Err != nil {
|
||||
c.Err = r.Err
|
||||
@@ -184,14 +184,14 @@ func getAnalytics(c *Context, w http.ResponseWriter, r *http.Request) {
|
||||
|
||||
w.Write([]byte(rows.ToJson()))
|
||||
} else if name == "post_counts_day" {
|
||||
if r := <-Srv.Store.Post().AnalyticsPostCountsByDay(teamId); r.Err != nil {
|
||||
if r := <-Srv.Store.Post().AnalyticsPostCountsByDay(c.T, teamId); r.Err != nil {
|
||||
c.Err = r.Err
|
||||
return
|
||||
} else {
|
||||
w.Write([]byte(r.Data.(model.AnalyticsRows).ToJson()))
|
||||
}
|
||||
} else if name == "user_counts_with_posts_day" {
|
||||
if r := <-Srv.Store.Post().AnalyticsUserCountsWithPostsByDay(teamId); r.Err != nil {
|
||||
if r := <-Srv.Store.Post().AnalyticsUserCountsWithPostsByDay(c.T, teamId); r.Err != nil {
|
||||
c.Err = r.Err
|
||||
return
|
||||
} else {
|
||||
|
||||
@@ -192,7 +192,7 @@ func ExportChannels(T goi18n.TranslateFunc, writer ExportWriter, options *Export
|
||||
}
|
||||
|
||||
for _, channel := range channels {
|
||||
if err := ExportPosts(writer, options, channel.Id); err != nil {
|
||||
if err := ExportPosts(T, writer, options, channel.Id); err != nil {
|
||||
return err
|
||||
}
|
||||
}
|
||||
@@ -200,10 +200,10 @@ func ExportChannels(T goi18n.TranslateFunc, writer ExportWriter, options *Export
|
||||
return nil
|
||||
}
|
||||
|
||||
func ExportPosts(writer ExportWriter, options *ExportOptions, channelId string) *model.AppError {
|
||||
func ExportPosts(T goi18n.TranslateFunc, writer ExportWriter, options *ExportOptions, channelId string) *model.AppError {
|
||||
// Get the posts
|
||||
var posts []*model.Post
|
||||
if result := <-Srv.Store.Post().GetForExport(channelId); result.Err != nil {
|
||||
if result := <-Srv.Store.Post().GetForExport(T, channelId); result.Err != nil {
|
||||
return result.Err
|
||||
} else {
|
||||
posts = result.Data.([]*model.Post)
|
||||
|
||||
@@ -14,10 +14,10 @@ import (
|
||||
// some of the usual checks. (IsValid is still run)
|
||||
//
|
||||
|
||||
func ImportPost(post *model.Post) {
|
||||
func ImportPost(T goi18n.TranslateFunc, post *model.Post) {
|
||||
post.Hashtags, _ = model.ParseHashtags(post.Message)
|
||||
|
||||
if result := <-Srv.Store.Post().Save(post); result.Err != nil {
|
||||
if result := <-Srv.Store.Post().Save(T, post); result.Err != nil {
|
||||
l4g.Debug("Error saving post. user=" + post.UserId + ", message=" + post.Message)
|
||||
}
|
||||
}
|
||||
|
||||
30
api/post.go
30
api/post.go
@@ -72,7 +72,7 @@ func createPost(c *Context, w http.ResponseWriter, r *http.Request) {
|
||||
func CreatePost(c *Context, post *model.Post, triggerWebhooks bool) (*model.Post, *model.AppError) {
|
||||
var pchan store.StoreChannel
|
||||
if len(post.RootId) > 0 {
|
||||
pchan = Srv.Store.Post().Get(post.RootId)
|
||||
pchan = Srv.Store.Post().Get(c.T, post.RootId)
|
||||
}
|
||||
|
||||
// Verify the parent/child relationships are correct
|
||||
@@ -138,7 +138,7 @@ func CreatePost(c *Context, post *model.Post, triggerWebhooks bool) (*model.Post
|
||||
}
|
||||
|
||||
var rpost *model.Post
|
||||
if result := <-Srv.Store.Post().Save(post); result.Err != nil {
|
||||
if result := <-Srv.Store.Post().Save(c.T, post); result.Err != nil {
|
||||
return nil, result.Err
|
||||
} else {
|
||||
rpost = result.Data.(*model.Post)
|
||||
@@ -711,7 +711,7 @@ func updatePost(c *Context, w http.ResponseWriter, r *http.Request) {
|
||||
}
|
||||
|
||||
cchan := Srv.Store.Channel().CheckPermissionsTo(c.T, c.Session.TeamId, post.ChannelId, c.Session.UserId)
|
||||
pchan := Srv.Store.Post().Get(post.Id)
|
||||
pchan := Srv.Store.Post().Get(c.T, post.Id)
|
||||
|
||||
if !c.HasPermissionsToChannel(cchan, "updatePost") {
|
||||
return
|
||||
@@ -745,7 +745,7 @@ func updatePost(c *Context, w http.ResponseWriter, r *http.Request) {
|
||||
|
||||
hashtags, _ := model.ParseHashtags(post.Message)
|
||||
|
||||
if result := <-Srv.Store.Post().Update(oldPost, post.Message, hashtags); result.Err != nil {
|
||||
if result := <-Srv.Store.Post().Update(c.T, oldPost, post.Message, hashtags); result.Err != nil {
|
||||
c.Err = result.Err
|
||||
return
|
||||
} else {
|
||||
@@ -782,7 +782,7 @@ func getPosts(c *Context, w http.ResponseWriter, r *http.Request) {
|
||||
}
|
||||
|
||||
cchan := Srv.Store.Channel().CheckPermissionsTo(c.T, c.Session.TeamId, id, c.Session.UserId)
|
||||
etagChan := Srv.Store.Post().GetEtag(id)
|
||||
etagChan := Srv.Store.Post().GetEtag(c.T, id)
|
||||
|
||||
if !c.HasPermissionsToChannel(cchan, "getPosts") {
|
||||
return
|
||||
@@ -794,7 +794,7 @@ func getPosts(c *Context, w http.ResponseWriter, r *http.Request) {
|
||||
return
|
||||
}
|
||||
|
||||
pchan := Srv.Store.Post().GetPosts(id, offset, limit)
|
||||
pchan := Srv.Store.Post().GetPosts(c.T, id, offset, limit)
|
||||
|
||||
if result := <-pchan; result.Err != nil {
|
||||
c.Err = result.Err
|
||||
@@ -824,7 +824,7 @@ func getPostsSince(c *Context, w http.ResponseWriter, r *http.Request) {
|
||||
}
|
||||
|
||||
cchan := Srv.Store.Channel().CheckPermissionsTo(c.T, c.Session.TeamId, id, c.Session.UserId)
|
||||
pchan := Srv.Store.Post().GetPostsSince(id, time)
|
||||
pchan := Srv.Store.Post().GetPostsSince(c.T, id, time)
|
||||
|
||||
if !c.HasPermissionsToChannel(cchan, "getPostsSince") {
|
||||
return
|
||||
@@ -857,7 +857,7 @@ func getPost(c *Context, w http.ResponseWriter, r *http.Request) {
|
||||
}
|
||||
|
||||
cchan := Srv.Store.Channel().CheckPermissionsTo(c.T, c.Session.TeamId, channelId, c.Session.UserId)
|
||||
pchan := Srv.Store.Post().Get(postId)
|
||||
pchan := Srv.Store.Post().Get(c.T, postId)
|
||||
|
||||
if !c.HasPermissionsToChannel(cchan, "getPost") {
|
||||
return
|
||||
@@ -891,7 +891,7 @@ func getPostById(c *Context, w http.ResponseWriter, r *http.Request) {
|
||||
return
|
||||
}
|
||||
|
||||
if result := <-Srv.Store.Post().Get(postId); result.Err != nil {
|
||||
if result := <-Srv.Store.Post().Get(c.T, postId); result.Err != nil {
|
||||
c.Err = result.Err
|
||||
return
|
||||
} else {
|
||||
@@ -933,7 +933,7 @@ func deletePost(c *Context, w http.ResponseWriter, r *http.Request) {
|
||||
}
|
||||
|
||||
cchan := Srv.Store.Channel().CheckPermissionsTo(c.T, c.Session.TeamId, channelId, c.Session.UserId)
|
||||
pchan := Srv.Store.Post().Get(postId)
|
||||
pchan := Srv.Store.Post().Get(c.T, postId)
|
||||
|
||||
if result := <-pchan; result.Err != nil {
|
||||
c.Err = result.Err
|
||||
@@ -963,7 +963,7 @@ func deletePost(c *Context, w http.ResponseWriter, r *http.Request) {
|
||||
return
|
||||
}
|
||||
|
||||
if dresult := <-Srv.Store.Post().Delete(postId, model.GetMillis()); dresult.Err != nil {
|
||||
if dresult := <-Srv.Store.Post().Delete(c.T, postId, model.GetMillis()); dresult.Err != nil {
|
||||
c.Err = dresult.Err
|
||||
return
|
||||
}
|
||||
@@ -1014,7 +1014,7 @@ func getPostsBeforeOrAfter(c *Context, w http.ResponseWriter, r *http.Request, b
|
||||
|
||||
cchan := Srv.Store.Channel().CheckPermissionsTo(c.T, c.Session.TeamId, id, c.Session.UserId)
|
||||
// We can do better than this etag in this situation
|
||||
etagChan := Srv.Store.Post().GetEtag(id)
|
||||
etagChan := Srv.Store.Post().GetEtag(c.T, id)
|
||||
|
||||
if !c.HasPermissionsToChannel(cchan, "getPostsBeforeOrAfter") {
|
||||
return
|
||||
@@ -1027,9 +1027,9 @@ func getPostsBeforeOrAfter(c *Context, w http.ResponseWriter, r *http.Request, b
|
||||
|
||||
var pchan store.StoreChannel
|
||||
if before {
|
||||
pchan = Srv.Store.Post().GetPostsBefore(id, postId, numPosts, offset)
|
||||
pchan = Srv.Store.Post().GetPostsBefore(c.T, id, postId, numPosts, offset)
|
||||
} else {
|
||||
pchan = Srv.Store.Post().GetPostsAfter(id, postId, numPosts, offset)
|
||||
pchan = Srv.Store.Post().GetPostsAfter(c.T, id, postId, numPosts, offset)
|
||||
}
|
||||
|
||||
if result := <-pchan; result.Err != nil {
|
||||
@@ -1057,7 +1057,7 @@ func searchPosts(c *Context, w http.ResponseWriter, r *http.Request) {
|
||||
for _, params := range paramsList {
|
||||
// don't allow users to search for everything
|
||||
if params.Terms != "*" {
|
||||
channels = append(channels, Srv.Store.Post().Search(c.Session.TeamId, c.Session.UserId, params))
|
||||
channels = append(channels, Srv.Store.Post().Search(c.T, c.Session.TeamId, c.Session.UserId, params))
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -129,7 +129,7 @@ func SlackAddUsers(T goi18n.TranslateFunc, teamId string, slackusers []SlackUser
|
||||
return addedUsers
|
||||
}
|
||||
|
||||
func SlackAddPosts(channel *model.Channel, posts []SlackPost, users map[string]*model.User) {
|
||||
func SlackAddPosts(T goi18n.TranslateFunc, channel *model.Channel, posts []SlackPost, users map[string]*model.User) {
|
||||
for _, sPost := range posts {
|
||||
switch {
|
||||
case sPost.Type == "message" && (sPost.SubType == "" || sPost.SubType == "file_share"):
|
||||
@@ -146,7 +146,7 @@ func SlackAddPosts(channel *model.Channel, posts []SlackPost, users map[string]*
|
||||
Message: sPost.Text,
|
||||
CreateAt: SlackConvertTimeStamp(sPost.TimeStamp),
|
||||
}
|
||||
ImportPost(&newPost)
|
||||
ImportPost(T, &newPost)
|
||||
case sPost.Type == "message" && sPost.SubType == "file_comment":
|
||||
if sPost.Comment["user"] == "" {
|
||||
l4g.Debug("Message without user")
|
||||
@@ -161,7 +161,7 @@ func SlackAddPosts(channel *model.Channel, posts []SlackPost, users map[string]*
|
||||
Message: sPost.Comment["comment"],
|
||||
CreateAt: SlackConvertTimeStamp(sPost.TimeStamp),
|
||||
}
|
||||
ImportPost(&newPost)
|
||||
ImportPost(T, &newPost)
|
||||
case sPost.Type == "message" && sPost.SubType == "bot_message":
|
||||
// In the future this will use the "Action Post" spec to post
|
||||
// a message without using a username. For now we just warn that we don't handle this case
|
||||
@@ -200,7 +200,7 @@ func SlackAddChannels(T goi18n.TranslateFunc, teamId string, slackchannels []Sla
|
||||
}
|
||||
log.WriteString(newChannel.DisplayName + "\r\n")
|
||||
addedChannels[sChannel.Id] = mChannel
|
||||
SlackAddPosts(mChannel, posts[sChannel.Name], users)
|
||||
SlackAddPosts(T, mChannel, posts[sChannel.Name], users)
|
||||
}
|
||||
|
||||
return addedChannels
|
||||
|
||||
@@ -1460,7 +1460,7 @@ func PermanentDeleteUser(c *Context, user *model.User) *model.AppError {
|
||||
return result.Err
|
||||
}
|
||||
|
||||
if result := <-Srv.Store.Post().PermanentDeleteByUser(user.Id); result.Err != nil {
|
||||
if result := <-Srv.Store.Post().PermanentDeleteByUser(c.T, user.Id); result.Err != nil {
|
||||
return result.Err
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user