Fixed a bug with duplicate identifiers.
@@ -1010,9 +1010,10 @@ func (window *Window) PopulateMentionWindowFromCurrentGuild(mentionWindow *tview
}
}
+ roleMap := make(map[string]*discordgo.Role)
for _, role := range guild.Roles {
- role := role.Name
- memberNames = append(memberNames, role)
+ roleMap[role.Name] = role
+ memberNames = append(memberNames, role.Name)
}
searchResults := fuzzy.ScoreSearch(namePart, memberNames)
@@ -1020,28 +1021,31 @@ func (window *Window) PopulateMentionWindowFromCurrentGuild(mentionWindow *tview
userWithNickSet := make(map[string]struct{})
for _, result := range sortedResults {
- userOrNickName := result.Key
- userAndNickName := nameMap[userOrNickName]
- var userNodeText string
- var userName string
- if len(userAndNickName) > 0 {
- _, containsStr := userWithNickSet[userAndNickName]
+ // Check if result was a role.
+ if role, ok := roleMap[result.Key]; ok {
+ window.addNodeToMentionWindow(mentionWindow, role.Name, role)
+ continue
+ }
+
+ var displayName string = result.Key
+ var userMentionReference string = result.Key
+ if combinedUserAndNickName, ok := nameMap[result.Key]; ok {
// If the combined string has been added, skip this entry.
- if containsStr {
+ if _, containsStr := userWithNickSet[combinedUserAndNickName]; containsStr {
continue
}
- userWithNickSet[userAndNickName] = struct{}{}
- userNodeText = userAndNickName
- userName = nameMap[userAndNickName]
- } else {
- userNodeText = userOrNickName
- userName = userOrNickName
+ userWithNickSet[combinedUserAndNickName] = struct{}{}
+ displayName = combinedUserAndNickName
+ userMentionReference = nameMap[combinedUserAndNickName]
+ }
+ window.addNodeToMentionWindow(mentionWindow, displayName, userMentionReference)
}
- userNode := tview.NewTreeNode(userNodeText)
- userNode.SetReference(userName)
- mentionWindow.GetRoot().AddChild(userNode)
}
+func (window *Window) addNodeToMentionWindow(mentionWindow *tview.TreeView, name string, reference interface{}) {
+ userNode := tview.NewTreeNode(name)
+ userNode.SetReference(reference)
+ mentionWindow.GetRoot().AddChild(userNode)
}
func (window *Window) PopulateMentionWindowFromCurrentChannel(mentionWindow *tview.TreeView, namePart string) {
