PLT-6960 Only update post.EditAt when the message changes (#6840)

Этот коммит содержится в:
Harrison Healey
2017-07-04 15:17:54 -04:00
коммит произвёл Joram Wilander
родитель 1858fba7d4
Коммит 4bd7b68b24
2 изменённых файлов: 38 добавлений и 10 удалений

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

@@ -266,9 +266,11 @@ func UpdatePost(post *model.Post, safeUpdate bool) (*model.Post, *model.AppError
newPost := &model.Post{}
*newPost = *oldPost
newPost.Message = post.Message
newPost.EditAt = model.GetMillis()
newPost.Hashtags, _ = model.ParseHashtags(post.Message)
if newPost.Message != post.Message {
newPost.Message = post.Message
newPost.EditAt = model.GetMillis()
newPost.Hashtags, _ = model.ParseHashtags(post.Message)
}
if !safeUpdate {
newPost.IsPinned = post.IsPinned

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

@@ -5,11 +5,37 @@ package app
import (
"testing"
"time"
"github.com/mattermost/platform/model"
"fmt"
"github.com/mattermost/platform/model"
)
func TestUpdatePostEditAt(t *testing.T) {
th := Setup().InitBasic()
post := &model.Post{}
*post = *th.BasicPost
post.IsPinned = true
if saved, err := UpdatePost(post, true); err != nil {
t.Fatal(err)
} else if saved.EditAt != post.EditAt {
t.Fatal("shouldn't have updated post.EditAt when pinning post")
*post = *saved
}
time.Sleep(time.Millisecond * 100)
post.Message = model.NewId()
if saved, err := UpdatePost(post, true); err != nil {
t.Fatal(err)
} else if saved.EditAt == post.EditAt {
t.Fatal("should have updated post.EditAt when updating post message")
}
}
func TestPostReplyToPostWhereRootPosterLeftChannel(t *testing.T) {
// This test ensures that when replying to a root post made by a user who has since left the channel, the reply
// post completes successfully. This is a regression test for PLT-6523.
@@ -29,13 +55,13 @@ func TestPostReplyToPostWhereRootPosterLeftChannel(t *testing.T) {
}
replyPost := model.Post{
Message: "asd",
ChannelId: channel.Id,
RootId: rootPost.Id,
ParentId: rootPost.Id,
Message: "asd",
ChannelId: channel.Id,
RootId: rootPost.Id,
ParentId: rootPost.Id,
PendingPostId: model.NewId() + ":" + fmt.Sprint(model.GetMillis()),
UserId: userInChannel.Id,
CreateAt: 0,
UserId: userInChannel.Id,
CreateAt: 0,
}
if _, err := CreatePostAsUser(&replyPost); err != nil {