Fix for OOO bug that reply message does not get inserted consistently. (#9742)

Этот коммит содержится в:
Chris Duarte
2018-10-30 14:30:15 -07:00
коммит произвёл Christopher Speller
родитель 5d6c686d80
Коммит f23eeb56c7
3 изменённых файлов: 8 добавлений и 18 удалений

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

@@ -8,7 +8,7 @@ import (
"github.com/mattermost/mattermost-server/model" "github.com/mattermost/mattermost-server/model"
) )
func (a *App) SendAutoResponse(channel *model.Channel, receiver *model.User, rootId string) { func (a *App) SendAutoResponse(channel *model.Channel, receiver *model.User) {
if receiver == nil || receiver.NotifyProps == nil { if receiver == nil || receiver.NotifyProps == nil {
return return
} }
@@ -20,8 +20,8 @@ func (a *App) SendAutoResponse(channel *model.Channel, receiver *model.User, roo
autoResponderPost := &model.Post{ autoResponderPost := &model.Post{
ChannelId: channel.Id, ChannelId: channel.Id,
Message: message, Message: message,
RootId: rootId, RootId: "",
ParentId: rootId, ParentId: "",
Type: model.POST_AUTO_RESPONDER, Type: model.POST_AUTO_RESPONDER,
UserId: receiver.Id, UserId: receiver.Id,
} }

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

@@ -94,28 +94,25 @@ func TestSendAutoResponseSuccess(t *testing.T) {
userUpdated1, err := th.App.PatchUser(user.Id, patch, true) userUpdated1, err := th.App.PatchUser(user.Id, patch, true)
require.Nil(t, err) require.Nil(t, err)
firstPost, _ := th.App.CreatePost(&model.Post{ th.App.CreatePost(&model.Post{
ChannelId: th.BasicChannel.Id, ChannelId: th.BasicChannel.Id,
Message: "zz" + model.NewId() + "a", Message: "zz" + model.NewId() + "a",
UserId: th.BasicUser.Id}, UserId: th.BasicUser.Id},
th.BasicChannel, th.BasicChannel,
false) false)
th.App.SendAutoResponse(th.BasicChannel, userUpdated1, firstPost.Id) th.App.SendAutoResponse(th.BasicChannel, userUpdated1)
if list, err := th.App.GetPosts(th.BasicChannel.Id, 0, 1); err != nil { if list, err := th.App.GetPosts(th.BasicChannel.Id, 0, 1); err != nil {
require.Nil(t, err) require.Nil(t, err)
} else { } else {
autoResponderPostFound := false autoResponderPostFound := false
autoResponderIsComment := false
for _, post := range list.Posts { for _, post := range list.Posts {
if post.Type == model.POST_AUTO_RESPONDER { if post.Type == model.POST_AUTO_RESPONDER {
autoResponderIsComment = post.RootId == firstPost.Id
autoResponderPostFound = true autoResponderPostFound = true
} }
} }
assert.True(t, autoResponderPostFound) assert.True(t, autoResponderPostFound)
assert.True(t, autoResponderIsComment)
} }
} }
@@ -134,27 +131,24 @@ func TestSendAutoResponseFailure(t *testing.T) {
userUpdated1, err := th.App.PatchUser(user.Id, patch, true) userUpdated1, err := th.App.PatchUser(user.Id, patch, true)
require.Nil(t, err) require.Nil(t, err)
firstPost, _ := th.App.CreatePost(&model.Post{ th.App.CreatePost(&model.Post{
ChannelId: th.BasicChannel.Id, ChannelId: th.BasicChannel.Id,
Message: "zz" + model.NewId() + "a", Message: "zz" + model.NewId() + "a",
UserId: th.BasicUser.Id}, UserId: th.BasicUser.Id},
th.BasicChannel, th.BasicChannel,
false) false)
th.App.SendAutoResponse(th.BasicChannel, userUpdated1, firstPost.Id) th.App.SendAutoResponse(th.BasicChannel, userUpdated1)
if list, err := th.App.GetPosts(th.BasicChannel.Id, 0, 1); err != nil { if list, err := th.App.GetPosts(th.BasicChannel.Id, 0, 1); err != nil {
require.Nil(t, err) require.Nil(t, err)
} else { } else {
autoResponderPostFound := false autoResponderPostFound := false
autoResponderIsComment := false
for _, post := range list.Posts { for _, post := range list.Posts {
if post.Type == model.POST_AUTO_RESPONDER { if post.Type == model.POST_AUTO_RESPONDER {
autoResponderIsComment = post.RootId == firstPost.Id
autoResponderPostFound = true autoResponderPostFound = true
} }
} }
assert.False(t, autoResponderPostFound) assert.False(t, autoResponderPostFound)
assert.False(t, autoResponderIsComment)
} }
} }

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

@@ -79,11 +79,7 @@ func (a *App) SendNotifications(post *model.Post, team *model.Team, channel *mod
if post.Type != model.POST_AUTO_RESPONDER { if post.Type != model.POST_AUTO_RESPONDER {
a.Go(func() { a.Go(func() {
rootId := post.Id a.SendAutoResponse(channel, otherUser)
if post.RootId != "" && post.RootId != post.Id {
rootId = post.RootId
}
a.SendAutoResponse(channel, otherUser, rootId)
}) })
} }