From ff970e080bf679543858e381f0d9d880773bddc3 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Daniel=20Espino=20Garc=C3=ADa?= Date: Mon, 1 Feb 2021 14:52:27 +0100 Subject: [PATCH] [MM-32253] Fix "Cannot mark unread a DM message in a thread" (#16794) Automatic Merge --- app/notification.go | 2 +- app/post.go | 12 ++++++++---- 2 files changed, 9 insertions(+), 5 deletions(-) diff --git a/app/notification.go b/app/notification.go index 2fab4f44fd..d02e40b064 100644 --- a/app/notification.go +++ b/app/notification.go @@ -837,7 +837,7 @@ func (a *App) getGroupsAllowedForReferenceInChannel(channel *model.Channel, team groupsMap := make(map[string]*model.Group) opts := model.GroupSearchOpts{FilterAllowReference: true} - if channel.IsGroupConstrained() || team.IsGroupConstrained() { + if channel.IsGroupConstrained() || (team != nil && team.IsGroupConstrained()) { var groups []*model.GroupWithSchemeAdmin if channel.IsGroupConstrained() { groups, err = a.Srv().Store.Group().GetGroupsByChannel(channel.Id, opts) diff --git a/app/post.go b/app/post.go index f97c707f09..b939a2df77 100644 --- a/app/post.go +++ b/app/post.go @@ -1343,10 +1343,6 @@ func (a *App) MaxPostSize() int { // countThreadMentions returns the number of times the user is mentioned in a specified thread after the timestamp. func (a *App) countThreadMentions(user *model.User, post *model.Post, teamId string, timestamp int64) (int64, *model.AppError) { - team, err := a.GetTeam(teamId) - if err != nil { - return 0, err - } channel, err := a.GetChannel(post.ChannelId) if err != nil { return 0, err @@ -1379,6 +1375,14 @@ func (a *App) countThreadMentions(user *model.User, post *model.Post, teamId str return int64(count), nil } + var team *model.Team + if teamId != "" { + team, err = a.GetTeam(teamId) + if err != nil { + return 0, err + } + } + groups, nErr := a.getGroupsAllowedForReferenceInChannel(channel, team) if nErr != nil { return 0, model.NewAppError("countMentionsFromPost", "app.channel.count_posts_since.app_error", nil, nErr.Error(), http.StatusInternalServerError)