mirror of
https://github.com/shazow/ssh-chat.git
synced 2025-04-13 15:47:17 +03:00
in autocomplete list moves your name to last item in the list of sorted current users
This commit is contained in:
parent
208a6a4712
commit
5ff2ea085b
10
chat/room.go
10
chat/room.go
@ -226,7 +226,7 @@ func (r *Room) SetTopic(s string) {
|
||||
|
||||
// NamesPrefix lists all members' names with a given prefix, used to query
|
||||
// for autocompletion purposes. Sorted by which user was last active.
|
||||
func (r *Room) NamesPrefix(prefix string) []string {
|
||||
func (r *Room) NamesPrefix(prefix string, current_user *message.User) []string {
|
||||
items := r.Members.ListPrefix(prefix)
|
||||
|
||||
// Sort results by recently active
|
||||
@ -235,6 +235,14 @@ func (r *Room) NamesPrefix(prefix string) []string {
|
||||
users = append(users, item.Value().(*Member).User)
|
||||
}
|
||||
sort.Sort(message.RecentActiveUsers(users))
|
||||
for i, user := range users {
|
||||
if user.Name() == current_user.Name() {
|
||||
// move it to the end. one user in the list?
|
||||
save := users[0]
|
||||
copy(users[i:], users[i+1:])
|
||||
users[len(users)-1] = save
|
||||
}
|
||||
}
|
||||
|
||||
// Pull out names
|
||||
names := make([]string, 0, len(items))
|
||||
|
6
host.go
6
host.go
@ -243,8 +243,8 @@ func (h *Host) Serve() {
|
||||
h.listener.Serve()
|
||||
}
|
||||
|
||||
func (h *Host) completeName(partial string) string {
|
||||
names := h.NamesPrefix(partial)
|
||||
func (h *Host) completeName(partial string, current_user *message.User) string {
|
||||
names := h.NamesPrefix(partial, current_user)
|
||||
if len(names) == 0 {
|
||||
// Didn't find anything
|
||||
return ""
|
||||
@ -300,7 +300,7 @@ func (h *Host) AutoCompleteFunction(u *message.User) func(line string, pos int,
|
||||
}
|
||||
} else {
|
||||
// Name
|
||||
completed = h.completeName(partial)
|
||||
completed = h.completeName(partial, u)
|
||||
if completed == "" {
|
||||
return
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user