diff --git a/chat/message/user.go b/chat/message/user.go index 0fc8cc1..d4cc304 100644 --- a/chat/message/user.go +++ b/chat/message/user.go @@ -258,5 +258,11 @@ func (a RecentActiveUsers) Less(i, j int) bool { defer a[i].mu.Unlock() a[j].mu.Lock() defer a[j].mu.Unlock() - return a[i].lastMsg.After(a[j].lastMsg) + + if a[i].lastMsg.IsZero() { + return a[i].joined.Before(a[j].joined) + } else { + return a[i].lastMsg.Before(a[j].lastMsg) + } + } diff --git a/host.go b/host.go index 1c615c0..7be6aed 100644 --- a/host.go +++ b/host.go @@ -243,14 +243,19 @@ func (h *Host) Serve() { h.listener.Serve() } -func (h *Host) completeName(partial string) string { +func (h *Host) completeName(partial string, skipName string) string { names := h.NamesPrefix(partial) if len(names) == 0 { // Didn't find anything return "" + } else if name := names[0]; name != skipName { + // First name is not the skipName, great + return name + } else if len(names) > 1 { + // Next candidate + return names[1] } - - return names[len(names)-1] + return "" } func (h *Host) completeCommand(partial string) string { @@ -300,7 +305,7 @@ func (h *Host) AutoCompleteFunction(u *message.User) func(line string, pos int, } } else { // Name - completed = h.completeName(partial) + completed = h.completeName(partial, u.Name()) if completed == "" { return }