MM-30970 Add Basic unreadMentions support for collapsed threads (#16407)
Co-authored-by: Mattermod <mattermod@users.noreply.github.com>
Этот коммит содержится в:
коммит произвёл
GitHub
родитель
1bd7dc41bd
Коммит
c2036f614e
60
app/post.go
60
app/post.go
@@ -458,7 +458,7 @@ func (a *App) handlePostEvents(post *model.Post, user *model.User, channel *mode
|
||||
}
|
||||
|
||||
if *a.Config().ServiceSettings.ThreadAutoFollow && post.RootId != "" {
|
||||
if err := a.Srv().Store.Thread().CreateMembershipIfNeeded(post.UserId, post.RootId, true); err != nil {
|
||||
if err := a.Srv().Store.Thread().CreateMembershipIfNeeded(post.UserId, post.RootId, true, false, true); err != nil {
|
||||
return err
|
||||
}
|
||||
}
|
||||
@@ -1340,6 +1340,64 @@ func (a *App) MaxPostSize() int {
|
||||
return a.Srv().MaxPostSize()
|
||||
}
|
||||
|
||||
// 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
|
||||
}
|
||||
|
||||
keywords := addMentionKeywordsForUser(
|
||||
map[string][]string{},
|
||||
user,
|
||||
map[string]string{},
|
||||
&model.Status{Status: model.STATUS_ONLINE}, // Assume the user is online since they would've triggered this
|
||||
true, // Assume channel mentions are always allowed for simplicity
|
||||
)
|
||||
|
||||
posts, nErr := a.Srv().Store.Thread().GetPosts(post.Id, timestamp)
|
||||
if nErr != nil {
|
||||
return 0, model.NewAppError("countMentionsFromPost", "app.channel.count_posts_since.app_error", nil, nErr.Error(), http.StatusInternalServerError)
|
||||
}
|
||||
|
||||
count := 0
|
||||
|
||||
if channel.Type == model.CHANNEL_DIRECT {
|
||||
// In a DM channel, every post made by the other user is a mention
|
||||
otherId := channel.GetOtherUserIdForDM(user.Id)
|
||||
for _, p := range posts {
|
||||
if p.UserId == otherId {
|
||||
count++
|
||||
}
|
||||
}
|
||||
|
||||
return int64(count), nil
|
||||
}
|
||||
|
||||
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)
|
||||
}
|
||||
|
||||
mentions := getExplicitMentions(post, keywords, groups)
|
||||
if _, ok := mentions.Mentions[user.Id]; ok {
|
||||
count += 1
|
||||
}
|
||||
|
||||
for _, p := range posts {
|
||||
mentions = getExplicitMentions(p, keywords, groups)
|
||||
if _, ok := mentions.Mentions[user.Id]; ok {
|
||||
count += 1
|
||||
}
|
||||
}
|
||||
|
||||
return int64(count), nil
|
||||
}
|
||||
|
||||
// countMentionsFromPost returns the number of posts in the post's channel that mention the user after and including the
|
||||
// given post.
|
||||
func (a *App) countMentionsFromPost(user *model.User, post *model.Post) (int, *model.AppError) {
|
||||
|
||||
Ссылка в новой задаче
Block a user