From 29341b8fe571678d2a958c8266f1043d76b1ce22 Mon Sep 17 00:00:00 2001 From: Eli Yukelzon Date: Thu, 29 Apr 2021 10:52:29 +0300 Subject: [PATCH] MM-35290 CRT: Reply on a unfollowed thread causes re-following (#17537) --- app/notification.go | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/app/notification.go b/app/notification.go index b283b51e83..74fdde7002 100644 --- a/app/notification.go +++ b/app/notification.go @@ -191,6 +191,20 @@ func (a *App) SendNotifications(post *model.Post, team *model.Team, channel *mod go func(userID string) { defer close(mac) _, incrementMentions := mentions.Mentions[userID] + // if the user was not explicitly mentioned, check if they explicitly unfollowed the thread + if !incrementMentions { + membership, err := a.Srv().Store.Thread().GetMembershipForUser(userID, post.RootId) + var nfErr *store.ErrNotFound + + if err != nil && !errors.As(err, &nfErr) { + mac <- model.NewAppError("SendNotifications", "app.channel.autofollow.app_error", nil, err.Error(), http.StatusInternalServerError) + return + } + + if membership != nil && !membership.Following { + return + } + } _, err := a.Srv().Store.Thread().MaintainMembership(userID, post.RootId, true, incrementMentions, *a.Config().ServiceSettings.ThreadAutoFollow, userID == post.UserId, userID == post.UserId) if err != nil { mac <- model.NewAppError("SendNotifications", "app.channel.autofollow.app_error", nil, err.Error(), http.StatusInternalServerError)