~edwargix/tallyard

5c11b7e185de2fdbe09db138df8e39323bbd68a5 — David Florness 2 years ago d228189
TUI: don't display user ID more than once if user rejoins
1 files changed, 13 insertions(+), 4 deletions(-)

M ui/tui.go
M ui/tui.go => ui/tui.go +13 -4
@@ 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)