-
-
Notifications
You must be signed in to change notification settings - Fork 422
main: Autocomplete deprioritize own name #355
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
chat/room.go
Outdated
@@ -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 { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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
@@ -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 { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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
names := h.NamesPrefix(partial) | ||
if len(names) == 0 { | ||
// Didn't find anything | ||
return "" | ||
} | ||
|
||
for i, user := range names { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
thats sounds reasonable,yes.
14db2dd
to
f8b3ce8
Compare
host.go
Outdated
names := h.NamesPrefix(partial) | ||
if len(names) == 0 { | ||
// Didn't find anything | ||
return "" | ||
} | ||
|
||
for _, userName := range names { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why do we need a loop? Why not just check the name we're going to return?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
How's this?
host.go
Outdated
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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.