chore(mentions)_: Add suggestion limit for mention recommendations (#5774)

- Introduce a constant `suggestionsLimit` set to 15
- Apply the suggestion limit when calculating mention suggestions
- Replace unlimited suggestions (-1) with the new limit in relevant function calls
- This change aims to improve performance and user experience by limiting the number of mention suggestions displayed
This commit is contained in:
frank 2024-08-30 09:37:08 +08:00 committed by GitHub
parent 28e7a364c7
commit 82ba10ede7
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194

View File

@ -30,6 +30,8 @@ const (
charCodeBlock = "`"
intUnknown = -1
suggestionsLimit = 10
)
var (
@ -370,7 +372,7 @@ func (m *MentionManager) calculateSuggestionsWithMentionableUsers(chatID string,
searchedText := strings.ToLower(subs(fullText, atSignIdx+1, end))
m.logger.Debug("calculateSuggestionsWithMentionableUsers", zap.Int("atSignIdx", atSignIdx), zap.String("searchedText", searchedText), zap.String("fullText", fullText), zap.Any("state", state), zap.Int("end", end))
if end-atSignIdx <= 100 {
suggestions = getUserSuggestions(mentionableUsers, searchedText, -1)
suggestions = getUserSuggestions(mentionableUsers, searchedText, suggestionsLimit)
}
}
@ -729,7 +731,7 @@ func matchMention(text string, users map[string]*MentionableUser, mentionKeyIdx
searchedText = string(tt[:lastChar])
}
userSuggestions := getUserSuggestions(users, searchedText, -1)
userSuggestions := getUserSuggestions(users, searchedText, suggestionsLimit)
userSuggestionsCnt := len(userSuggestions)
switch {
case userSuggestionsCnt == 0: