From f23eeb56c7ab228952583800d2806b41c304e198 Mon Sep 17 00:00:00 2001 From: Chris Duarte Date: Tue, 30 Oct 2018 14:30:15 -0700 Subject: [PATCH] Fix for OOO bug that reply message does not get inserted consistently. (#9742) --- app/auto_responder.go | 6 +++--- app/auto_responder_test.go | 14 ++++---------- app/notification.go | 6 +----- 3 files changed, 8 insertions(+), 18 deletions(-) diff --git a/app/auto_responder.go b/app/auto_responder.go index a57a53f797..a8523680e4 100644 --- a/app/auto_responder.go +++ b/app/auto_responder.go @@ -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, } diff --git a/app/auto_responder_test.go b/app/auto_responder_test.go index 4afa033486..04a1d5c041 100644 --- a/app/auto_responder_test.go +++ b/app/auto_responder_test.go @@ -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) } } diff --git a/app/notification.go b/app/notification.go index 02f766d4d8..54f1f470da 100644 --- a/app/notification.go +++ b/app/notification.go @@ -79,11 +79,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) }) }