MM-11272 Added initial post metadata (#9175)

* MM-11272 Added app.PreparePostForClient

* MM-11272 Added app.PreparePostListForClient

* MM-11272 Added EmojiStore.GetMultipleByName

* MM-11272 Added emojis to PreparePostForClient

* MM-11272 Added unit tests for getting reaction counts

* MM-11272 Added unit tests for TestPreparePostForClient

* MM-11272 Added emojis from reactions to Post.Emojis

* MM-11272 Always update post.UpdateAt when reactions change to bust cache

* Fixed merge conflicts

* Moved post metadata-related code into its own file

* Update store mocks

* Fixed typo

* Add missing license headers

* Updated post metadata tests when custom emojis are disabled

* Fix unreliable unit tests

* Fix inconsistent casing in SQL statements

* Fix blank line

* Invalidate store cache after making changes

* Clear post cache synchronously with reactions
Этот коммит содержится в:
Harrison Healey
2018-08-07 16:24:56 -04:00
родитель 2e945e287d
Коммит 48f16b6401
27 изменённых файлов: 902 добавлений и 87 удалений

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

@@ -488,8 +488,13 @@ func getPinnedPosts(c *Context, w http.ResponseWriter, r *http.Request) {
return
}
w.Header().Set(model.HEADER_ETAG_SERVER, posts.Etag())
w.Write([]byte(c.App.PostListWithProxyAddedToImageURLs(posts).ToJson()))
clientPostList, err := c.App.PreparePostListForClient(posts)
if err != nil {
mlog.Error("Failed to prepare posts for getFlaggedPostsForUser response", mlog.Any("err", err))
}
w.Header().Set(model.HEADER_ETAG_SERVER, clientPostList.Etag())
w.Write([]byte(clientPostList.ToJson()))
}
func getPublicChannelsForTeam(c *Context, w http.ResponseWriter, r *http.Request) {

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

@@ -9,6 +9,7 @@ import (
"strconv"
"time"
"github.com/mattermost/mattermost-server/mlog"
"github.com/mattermost/mattermost-server/model"
)
@@ -67,8 +68,13 @@ func createPost(c *Context, w http.ResponseWriter, r *http.Request) {
c.App.SetStatusOnline(c.Session.UserId, false)
c.App.UpdateLastActivityAtIfNeeded(c.Session)
clientPost, err := c.App.PreparePostForClient(rp)
if err != nil {
mlog.Error("Failed to prepare post for createPost response", mlog.Any("err", err))
}
w.WriteHeader(http.StatusCreated)
w.Write([]byte(c.App.PostWithProxyAddedToImageURLs(rp).ToJson()))
w.Write([]byte(clientPost.ToJson()))
}
func createEphemeralPost(c *Context, w http.ResponseWriter, r *http.Request) {
@@ -95,8 +101,13 @@ func createEphemeralPost(c *Context, w http.ResponseWriter, r *http.Request) {
rp := c.App.SendEphemeralPost(ephRequest.UserID, c.App.PostWithProxyRemovedFromImageURLs(ephRequest.Post))
clientPost, err := c.App.PreparePostForClient(rp)
if err != nil {
mlog.Error("Failed to prepare post for createEphemeralPost response", mlog.Any("err", err))
}
w.WriteHeader(http.StatusCreated)
w.Write([]byte(c.App.PostWithProxyAddedToImageURLs(rp).ToJson()))
w.Write([]byte(clientPost.ToJson()))
}
func getPostsForChannel(c *Context, w http.ResponseWriter, r *http.Request) {
@@ -165,7 +176,13 @@ func getPostsForChannel(c *Context, w http.ResponseWriter, r *http.Request) {
if len(etag) > 0 {
w.Header().Set(model.HEADER_ETAG_SERVER, etag)
}
w.Write([]byte(c.App.PostListWithProxyAddedToImageURLs(list).ToJson()))
clientPostList, err := c.App.PreparePostListForClient(list)
if err != nil {
mlog.Error("Failed to prepare posts for getPostsForChannel response", mlog.Any("err", err))
}
w.Write([]byte(clientPostList.ToJson()))
}
func getFlaggedPostsForUser(c *Context, w http.ResponseWriter, r *http.Request) {
@@ -198,7 +215,12 @@ func getFlaggedPostsForUser(c *Context, w http.ResponseWriter, r *http.Request)
return
}
w.Write([]byte(c.App.PostListWithProxyAddedToImageURLs(posts).ToJson()))
clientPostList, err := c.App.PreparePostListForClient(posts)
if err != nil {
mlog.Error("Failed to prepare posts for getFlaggedPostsForUser response", mlog.Any("err", err))
}
w.Write([]byte(clientPostList.ToJson()))
}
func getPost(c *Context, w http.ResponseWriter, r *http.Request) {
@@ -232,12 +254,17 @@ func getPost(c *Context, w http.ResponseWriter, r *http.Request) {
}
}
post, err = c.App.PreparePostForClient(post)
if err != nil {
mlog.Error("Failed to prepare post for getPost response", mlog.Any("err", err))
}
if c.HandleEtag(post.Etag(), "Get Post", w, r) {
return
}
w.Header().Set(model.HEADER_ETAG_SERVER, post.Etag())
w.Write([]byte(c.App.PostWithProxyAddedToImageURLs(post).ToJson()))
w.Write([]byte(post.ToJson()))
}
func deletePost(c *Context, w http.ResponseWriter, r *http.Request) {
@@ -315,8 +342,14 @@ func getPostThread(c *Context, w http.ResponseWriter, r *http.Request) {
return
}
w.Header().Set(model.HEADER_ETAG_SERVER, list.Etag())
w.Write([]byte(c.App.PostListWithProxyAddedToImageURLs(list).ToJson()))
clientPostList, err := c.App.PreparePostListForClient(list)
if err != nil {
mlog.Error("Failed to prepare posts for getFlaggedPostsForUser response", mlog.Any("err", err))
}
w.Header().Set(model.HEADER_ETAG_SERVER, clientPostList.Etag())
w.Write([]byte(clientPostList.ToJson()))
}
func searchPosts(c *Context, w http.ResponseWriter, r *http.Request) {
@@ -379,7 +412,12 @@ func searchPosts(c *Context, w http.ResponseWriter, r *http.Request) {
return
}
results = model.MakePostSearchResults(c.App.PostListWithProxyAddedToImageURLs(results.PostList), results.Matches)
clientPostList, err := c.App.PreparePostListForClient(results.PostList)
if err != nil {
mlog.Error("Failed to prepare posts for searchPosts response", mlog.Any("err", err))
}
results = model.MakePostSearchResults(clientPostList, results.Matches)
w.Header().Set("Cache-Control", "no-cache, no-store, must-revalidate")
w.Write([]byte(results.ToJson()))
@@ -430,7 +468,12 @@ func updatePost(c *Context, w http.ResponseWriter, r *http.Request) {
return
}
w.Write([]byte(c.App.PostWithProxyAddedToImageURLs(rpost).ToJson()))
rpost, err = c.App.PreparePostForClient(rpost)
if err != nil {
mlog.Error("Failed to prepare post for updatePost response", mlog.Any("err", err))
}
w.Write([]byte(rpost.ToJson()))
}
func patchPost(c *Context, w http.ResponseWriter, r *http.Request) {
@@ -470,7 +513,12 @@ func patchPost(c *Context, w http.ResponseWriter, r *http.Request) {
return
}
w.Write([]byte(c.App.PostWithProxyAddedToImageURLs(patchedPost).ToJson()))
patchedPost, err = c.App.PreparePostForClient(patchedPost)
if err != nil {
mlog.Error("Failed to prepare post for patchPost response", mlog.Any("err", err))
}
w.Write([]byte(patchedPost.ToJson()))
}
func saveIsPinnedPost(c *Context, w http.ResponseWriter, r *http.Request, isPinned bool) {