MM-34774 Root post with mention should be auto-followed but hidden from thread results (#17390)
Этот коммит содержится в:
коммит произвёл
GitHub
родитель
ab8b8e8bf2
Коммит
9a27d135a1
@@ -100,7 +100,6 @@ func (a *App) SendNotifications(post *model.Post, team *model.Team, channel *mod
|
||||
keywords := a.getMentionKeywordsInChannel(profileMap, allowChannelMentions, channelMemberNotifyPropsMap)
|
||||
|
||||
mentions = getExplicitMentions(post, keywords, groups)
|
||||
|
||||
// Add an implicit mention when a user is added to a channel
|
||||
// even if the user has set 'username mentions' to false in account settings.
|
||||
if post.Type == model.POST_ADD_TO_CHANNEL {
|
||||
@@ -124,6 +123,8 @@ func (a *App) SendNotifications(post *model.Post, team *model.Team, channel *mod
|
||||
|
||||
// get users that have comment thread mentions enabled
|
||||
if post.RootId != "" && parentPostList != nil {
|
||||
rootPost := parentPostList.Posts[parentPostList.Order[0]]
|
||||
mentions.merge(getExplicitMentions(rootPost, keywords, groups))
|
||||
for _, threadPost := range parentPostList.Posts {
|
||||
profile := profileMap[threadPost.UserId]
|
||||
if profile == nil {
|
||||
@@ -756,6 +757,12 @@ func (m *ExplicitMentions) addMentions(userIDs []string, mentionType MentionType
|
||||
}
|
||||
}
|
||||
|
||||
func (m *ExplicitMentions) merge(other *ExplicitMentions) {
|
||||
for userID, mentionType := range other.Mentions {
|
||||
m.addMention(userID, mentionType)
|
||||
}
|
||||
}
|
||||
|
||||
func (m *ExplicitMentions) removeMention(userID string) {
|
||||
delete(m.Mentions, userID)
|
||||
}
|
||||
|
||||
@@ -1924,6 +1924,36 @@ func TestThreadMembership(t *testing.T) {
|
||||
})
|
||||
}
|
||||
|
||||
func TestAutofollowBasedOnRootPost(t *testing.T) {
|
||||
th := Setup(t).InitBasic()
|
||||
defer th.TearDown()
|
||||
os.Setenv("MM_FEATUREFLAGS_COLLAPSEDTHREADS", "true")
|
||||
defer os.Unsetenv("MM_FEATUREFLAGS_COLLAPSEDTHREADS")
|
||||
|
||||
th.App.UpdateConfig(func(cfg *model.Config) {
|
||||
*cfg.ServiceSettings.ThreadAutoFollow = true
|
||||
*cfg.ServiceSettings.CollapsedThreads = model.COLLAPSED_THREADS_DEFAULT_ON
|
||||
})
|
||||
|
||||
channel := th.BasicChannel
|
||||
user := th.BasicUser
|
||||
user2 := th.BasicUser2
|
||||
appErr := th.App.JoinChannel(channel, user.Id)
|
||||
require.Nil(t, appErr)
|
||||
appErr = th.App.JoinChannel(channel, user2.Id)
|
||||
require.Nil(t, appErr)
|
||||
p1, err := th.App.CreatePost(&model.Post{UserId: user.Id, ChannelId: channel.Id, Message: "Hi @" + user2.Username}, channel, false, false)
|
||||
require.Nil(t, err)
|
||||
m, e := th.App.GetThreadMembershipsForUser(user2.Id, th.BasicTeam.Id)
|
||||
require.NoError(t, e)
|
||||
require.Len(t, m, 0)
|
||||
_, err2 := th.App.CreatePost(&model.Post{RootId: p1.Id, UserId: user.Id, ChannelId: channel.Id, Message: "Hola"}, channel, false, false)
|
||||
require.Nil(t, err2)
|
||||
m, e = th.App.GetThreadMembershipsForUser(user2.Id, th.BasicTeam.Id)
|
||||
require.NoError(t, e)
|
||||
require.Len(t, m, 1)
|
||||
}
|
||||
|
||||
func TestCollapsedThreadFetch(t *testing.T) {
|
||||
th := Setup(t).InitBasic()
|
||||
defer th.TearDown()
|
||||
|
||||
Ссылка в новой задаче
Block a user