Commit 3abc825c authored by Chris Duarte's avatar Chris Duarte Committed by Jesse Hallam

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

parent 7982f4f8
......@@ -8,7 +8,7 @@ import (
"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 {
return
}
......@@ -20,8 +20,8 @@ func (a *App) SendAutoResponse(channel *model.Channel, receiver *model.User, roo
autoResponderPost := &model.Post{
ChannelId: channel.Id,
Message: message,
RootId: rootId,
ParentId: rootId,
RootId: "",
ParentId: "",
Type: model.POST_AUTO_RESPONDER,
UserId: receiver.Id,
}
......
......@@ -94,28 +94,25 @@ func TestSendAutoResponseSuccess(t *testing.T) {
userUpdated1, err := th.App.PatchUser(user.Id, patch, true)
require.Nil(t, err)
firstPost, _ := th.App.CreatePost(&model.Post{
th.App.CreatePost(&model.Post{
ChannelId: th.BasicChannel.Id,
Message: "zz" + model.NewId() + "a",
UserId: th.BasicUser.Id},
th.BasicChannel,
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 {
require.Nil(t, err)
} else {
autoResponderPostFound := false
autoResponderIsComment := false
for _, post := range list.Posts {
if post.Type == model.POST_AUTO_RESPONDER {
autoResponderIsComment = post.RootId == firstPost.Id
autoResponderPostFound = true
}
}
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)
require.Nil(t, err)
firstPost, _ := th.App.CreatePost(&model.Post{
th.App.CreatePost(&model.Post{
ChannelId: th.BasicChannel.Id,
Message: "zz" + model.NewId() + "a",
UserId: th.BasicUser.Id},
th.BasicChannel,
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 {
require.Nil(t, err)
} else {
autoResponderPostFound := false
autoResponderIsComment := false
for _, post := range list.Posts {
if post.Type == model.POST_AUTO_RESPONDER {
autoResponderIsComment = post.RootId == firstPost.Id
autoResponderPostFound = true
}
}
assert.False(t, autoResponderPostFound)
assert.False(t, autoResponderIsComment)
}
}
......@@ -81,11 +81,7 @@ func (a *App) SendNotifications(post *model.Post, team *model.Team, channel *mod
if post.Type != model.POST_AUTO_RESPONDER {
a.Go(func() {
rootId := post.Id
if post.RootId != "" && post.RootId != post.Id {
rootId = post.RootId
}
a.SendAutoResponse(channel, otherUser, rootId)
a.SendAutoResponse(channel, otherUser)
})
}
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment