From ce61ed8f52c5c6ff388146607563ffac0d644379 Mon Sep 17 00:00:00 2001 From: Devin Binnie <52460000+devinbinnie@users.noreply.github.com> Date: Tue, 18 Feb 2025 12:29:26 -0500 Subject: [PATCH] [MM-55090] Threads created by users should not be auto-followed on reply by the creator when they've left the channel (#30181) Co-authored-by: Mattermost Build Co-authored-by: Caleb Roseland --- server/channels/app/notification.go | 4 ++- server/channels/app/notification_test.go | 42 ++++++++++++++++++++++++ 2 files changed, 45 insertions(+), 1 deletion(-) diff --git a/server/channels/app/notification.go b/server/channels/app/notification.go index 5f1c8e06ee..7475d3afeb 100644 --- a/server/channels/app/notification.go +++ b/server/channels/app/notification.go @@ -229,7 +229,9 @@ func (a *App) SendNotifications(c request.CTX, post *model.Post, team *model.Tea if parentPostList != nil { rootPost := parentPostList.Posts[parentPostList.Order[0]] if rootPost.GetProp("from_webhook") != "true" { - threadParticipants[rootPost.UserId] = true + if _, ok := profileMap[rootPost.UserId]; ok { + threadParticipants[rootPost.UserId] = true + } } if channel.Type != model.ChannelTypeDirect { rootMentions = getExplicitMentions(rootPost, keywords) diff --git a/server/channels/app/notification_test.go b/server/channels/app/notification_test.go index a22dd395bd..53cdfc8e6d 100644 --- a/server/channels/app/notification_test.go +++ b/server/channels/app/notification_test.go @@ -2914,6 +2914,48 @@ func TestReplyPostNotificationsWithCRT(t *testing.T) { assert.Error(t, err) assert.Nil(t, membership) }) + + t.Run("should not auto follow when the original poster is no longer a channel member", func(t *testing.T) { + th := Setup(t).InitBasic() + defer th.TearDown() + + u1 := th.BasicUser + u2 := th.BasicUser2 + c1 := th.BasicChannel + th.AddUserToChannel(u2, c1) + + // Enable CRT + th.App.UpdateConfig(func(cfg *model.Config) { + *cfg.ServiceSettings.ThreadAutoFollow = true + *cfg.ServiceSettings.CollapsedThreads = model.CollapsedThreadsDefaultOn + }) + + rootPost := &model.Post{ + ChannelId: c1.Id, + Message: "root post by user1", + UserId: u1.Id, + } + rpost, appErr := th.App.CreatePost(th.Context, rootPost, c1, model.CreatePostFlags{SetOnline: true}) + require.Nil(t, appErr) + + // Remove user1 from the channel + appErr = th.App.RemoveUserFromChannel(th.Context, u1.Id, u1.Id, c1) + require.Nil(t, appErr) + + replyPost := &model.Post{ + ChannelId: c1.Id, + Message: "reply post by user2", + UserId: u2.Id, + RootId: rpost.Id, + } + _, appErr = th.App.CreatePost(th.Context, replyPost, c1, model.CreatePostFlags{SetOnline: true}) + require.Nil(t, appErr) + + // Ensure user1 is not auto-following the thread + threadMembership, appErr := th.App.GetThreadMembershipForUser(u1.Id, rpost.Id) + require.NotNil(t, appErr) + require.Nil(t, threadMembership) + }) } func TestChannelAutoFollowThreads(t *testing.T) {