main: Autocomplete deprioritize own name#355
Conversation
chat/room.go
Outdated
| users = append(users, item.Value().(*Member).User) | ||
| } | ||
| sort.Sort(message.RecentActiveUsers(users)) | ||
| for i, user := range users { |
There was a problem hiding this comment.
Is it necessary to change the signature of a public method and break API compatibility?
Can we put this in completeName instead?
host.go
Outdated
|
|
||
| func (h *Host) completeName(partial string) string { | ||
| names := h.NamesPrefix(partial) | ||
| func (h *Host) completeName(partial string, current_user *message.User) string { |
There was a problem hiding this comment.
Go uses camelCase instead of snake_case for variables.
| func (h *Host) completeName(partial string, current_user *message.User) string { | |
| func (h *Host) completeName(partial string, currentUser *message.User) string { |
|
One more request if possible: Would you mind fixing Line 261 in 3b8e644 user.joined if user.lastMsg is zero-value?
|
|
2f0bf90 to
14db2dd
Compare
host.go
Outdated
| return "" | ||
| } | ||
|
|
||
| for i, user := range names { |
There was a problem hiding this comment.
Do we actually need a loop here, and a full array copy inside of it? We're just returning one name, could we check if the name we're returning is currentUser and if it is then return the one before that?
Also, then we don't need to pass in a currentUser *message.User, we could just pass in skipName string instead.
There was a problem hiding this comment.
thats sounds reasonable,yes.
14db2dd to
f8b3ce8
Compare
host.go
Outdated
| return "" | ||
| } | ||
|
|
||
| for _, userName := range names { |
There was a problem hiding this comment.
Why do we need a loop? Why not just check the name we're going to return?
| func (h *Host) completeName(partial string, skipName string) string { | ||
| names := h.NamesPrefix(partial) | ||
| if len(names) == 0 { | ||
| // Didn't find anything | ||
| return "" | ||
| } | ||
|
|
||
| for _, userName := range names { | ||
| if userName != skipName { | ||
| return userName | ||
| } | ||
| } | ||
|
|
||
| return names[len(names)-1] | ||
| } |
There was a problem hiding this comment.
| func (h *Host) completeName(partial string, skipName string) string { | |
| names := h.NamesPrefix(partial) | |
| if len(names) == 0 { | |
| // Didn't find anything | |
| return "" | |
| } | |
| for _, userName := range names { | |
| if userName != skipName { | |
| return userName | |
| } | |
| } | |
| return names[len(names)-1] | |
| } | |
| 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 "" | |
| } |
f8b3ce8 to
284fde4
Compare
* addded condition for zero time on lastMsg. * removed extra paramter in NamePrefix * moved code from NamePrefix to completeName * removed extra parameter in tests calling to NamePrefix
284fde4 to
5885f7f
Compare
Current user is moved to the last item on the name lookup list.
Fixes #314.