Skip to content

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

Merged
merged 4 commits into from
Jul 30, 2020

Conversation

pavelz
Copy link
Contributor

@pavelz pavelz commented Jul 24, 2020

Current user is moved to the last item on the name lookup list.

Fixes #314.

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 {
Copy link
Owner

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 {
Copy link
Owner

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.

Suggested change
func (h *Host) completeName(partial string, current_user *message.User) string {
func (h *Host) completeName(partial string, currentUser *message.User) string {

@shazow shazow changed the title current user is moved to the last item main: Autocomplete deprioritize own name Jul 24, 2020
@shazow
Copy link
Owner

shazow commented Jul 24, 2020

One more request if possible:

Would you mind fixing

return a[i].lastMsg.After(a[j].lastMsg)
to use user.joined if user.lastMsg is zero-value?

@pavelz
Copy link
Contributor Author

pavelz commented Jul 27, 2020

to use user.joined if user.lastMsg is zero-value?
sure!

@pavelz pavelz force-pushed the my_name_last_autocomplete branch from 2f0bf90 to 14db2dd Compare July 28, 2020 02:35
host.go Outdated
names := h.NamesPrefix(partial)
if len(names) == 0 {
// Didn't find anything
return ""
}

for i, user := range names {
Copy link
Owner

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.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

thats sounds reasonable,yes.

@pavelz pavelz force-pushed the my_name_last_autocomplete branch from 14db2dd to f8b3ce8 Compare July 28, 2020 21:56
host.go Outdated
names := h.NamesPrefix(partial)
if len(names) == 0 {
// Didn't find anything
return ""
}

for _, userName := range names {
Copy link
Owner

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?

Copy link
Owner

@shazow shazow left a 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
Comment on lines 246 to 259
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]
}
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
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 ""
}

@pavelz pavelz force-pushed the my_name_last_autocomplete branch from f8b3ce8 to 284fde4 Compare July 29, 2020 22:14
* 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
@pavelz pavelz force-pushed the my_name_last_autocomplete branch from 284fde4 to 5885f7f Compare July 29, 2020 22:23
@shazow shazow merged commit fa8df81 into shazow:master Jul 30, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Autocomplete: Prioritize your own name last
2 participants