MM-54201 Refactor mention parsing in preparation for multi-word mentions (#25030)
* 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>
Этот коммит содержится в:
коммит произвёл
GitHub
родитель
74f35aa92c
Коммит
a78710c2a6
91
server/channels/app/mention_results.go
Обычный файл
91
server/channels/app/mention_results.go
Обычный файл
@@ -0,0 +1,91 @@
|
||||
// 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
|
||||
}
|
||||
Ссылка в новой задаче
Block a user