mirror of
https://github.com/mattermost/mattermost.git
synced 2026-05-28 04:35:04 -04:00
* MM-54201 Move ExplicitMentions to its own file and rename it (#24932) * MM-54201 Move ExplicitMentions to its own file and rename it * Fix vet * MM-54201 Refactor current mention parsing into MentionParserStandard (#24936) * MM-54201 Refactor current mention parsing into MentionParserStandard * Fix vet * MM-54201 Unify user and group mention parsing logic (#24937) * MM-54201 Add MentionKeywords type * MM-54201 Move group mentions into MentionKeywords * Fix flaky test caused by random iteration order * Update server/channels/app/mention_results.go Co-authored-by: Jesse Hallam <jesse.hallam@gmail.com> * Address feedback --------- Co-authored-by: Jesse Hallam <jesse.hallam@gmail.com> --------- Co-authored-by: Jesse Hallam <jesse.hallam@gmail.com>
91 lines
2.2 KiB
Go
91 lines
2.2 KiB
Go
// Copyright (c) 2015-present Mattermost, Inc. All Rights Reserved.
|
|
// See LICENSE.txt for license information.
|
|
|
|
package app
|
|
|
|
const (
|
|
// Different types of mentions ordered by their priority from lowest to highest
|
|
|
|
// A placeholder that should never be used in practice
|
|
NoMention MentionType = iota
|
|
|
|
// The post is in a GM
|
|
GMMention
|
|
|
|
// The post is in a thread that the user has commented on
|
|
ThreadMention
|
|
|
|
// The post is a comment on a thread started by the user
|
|
CommentMention
|
|
|
|
// The post contains an at-channel, at-all, or at-here
|
|
ChannelMention
|
|
|
|
// The post is a DM
|
|
DMMention
|
|
|
|
// The post contains an at-mention for the user
|
|
KeywordMention
|
|
|
|
// The post contains a group mention for the user
|
|
GroupMention
|
|
)
|
|
|
|
type MentionType int
|
|
|
|
type MentionResults struct {
|
|
// Mentions maps the ID of each user that was mentioned to how they were mentioned.
|
|
Mentions map[string]MentionType
|
|
|
|
// GroupMentions maps the ID of each group that was mentioned to how it was mentioned.
|
|
GroupMentions map[string]MentionType
|
|
|
|
// OtherPotentialMentions contains a list of strings that looked like mentions, but didn't have
|
|
// a corresponding keyword.
|
|
OtherPotentialMentions []string
|
|
|
|
// HereMentioned is true if the message contained @here.
|
|
HereMentioned bool
|
|
|
|
// AllMentioned is true if the message contained @all.
|
|
AllMentioned bool
|
|
|
|
// ChannelMentioned is true if the message contained @channel.
|
|
ChannelMentioned bool
|
|
}
|
|
|
|
func (m *MentionResults) isUserMentioned(userID string) bool {
|
|
if _, ok := m.Mentions[userID]; ok {
|
|
return true
|
|
}
|
|
|
|
if _, ok := m.GroupMentions[userID]; ok {
|
|
return true
|
|
}
|
|
|
|
return m.HereMentioned || m.AllMentioned || m.ChannelMentioned
|
|
}
|
|
|
|
func (m *MentionResults) addMention(userID string, mentionType MentionType) {
|
|
if m.Mentions == nil {
|
|
m.Mentions = make(map[string]MentionType)
|
|
}
|
|
|
|
if currentType, ok := m.Mentions[userID]; ok && currentType >= mentionType {
|
|
return
|
|
}
|
|
|
|
m.Mentions[userID] = mentionType
|
|
}
|
|
|
|
func (m *MentionResults) removeMention(userID string) {
|
|
delete(m.Mentions, userID)
|
|
}
|
|
|
|
func (m *MentionResults) addGroupMention(groupID string) {
|
|
if m.GroupMentions == nil {
|
|
m.GroupMentions = make(map[string]MentionType)
|
|
}
|
|
|
|
m.GroupMentions[groupID] = GroupMention
|
|
}
|