@@ 430,14 430,23 @@ func ElectionWaitTUI(kill <-chan error, client *mautrix.Client, el *election.Ele
el.RUnlock()
update := func() {
el.RLock()
- // TODO: handle duplicate joins from one UserID
+ defer el.RUnlock()
// TODO: handle users who joined after cutoff
voters := make([]string, 0, len(el.Joins))
for _, voter := range el.Joins {
- voters = append(voters, voter.JoinEvt.Sender.String())
+ name := voter.JoinEvt.Sender.String()
+ i := sort.Search(len(voters), func(i int) bool {
+ return name <= voters[i]
+ })
+ if i >= len(voters) {
+ voters = append(voters, name)
+ } else if voters[i] == name {
+ // voter already in map; skip to keep unique
+ continue
+ } else {
+ voters = append(voters[:i], append([]string{name}, voters[i:]...)...)
+ }
}
- el.RUnlock()
- sort.Strings(voters)
text := strings.Join(voters, "\n")
text = "Joined voters:\n" + text
votersTextView.SetText(text)