[MM-32253] Fix "Cannot mark unread a DM message in a thread" (#16794)

Automatic Merge
This commit is contained in:
Daniel Espino García
2021-02-01 14:52:27 +01:00
committed by GitHub
parent 13616cac0f
commit ff970e080b
2 changed files with 9 additions and 5 deletions

View File

@@ -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)

View File

@@ -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)