-
Notifications
You must be signed in to change notification settings - Fork 285
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
autocomplete: Add "human vs. bot user" and "Alphabetical order" criteria #849
autocomplete: Add "human vs. bot user" and "Alphabetical order" criteria #849
Conversation
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.
Thanks for working on this @sm-sayedi!
This look good to me, just one nit, moving on to the mentor review @hackerkid.
lib/model/autocomplete.dart
Outdated
if (!userA.isBot && userB.isBot) { | ||
return -1; | ||
} else if (userA.isBot && !userB.isBot) { | ||
return 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.
nit: Could be a small helper function like compareByRecency
and compareByDms
.
24f3ea5
to
fefaf31
Compare
Thanks @rajveermalviya for the review and the tip. Changes applied. |
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.
Thanks! One small comment below, and I'll mark this for Greg's review.
lib/model/autocomplete.dart
Outdated
.normalizedNameForUser(userA); | ||
final userBName = store.autocompleteViewManager.autocompleteDataCache | ||
.normalizedNameForUser(userB); | ||
return userAName.compareTo(userBName); |
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.
Let's add a TODO like we have in SubscriptionListPage
:
// TODO(i18n): add locale-aware sorting
For example, this would sort the list of names ['c', 'b', 'a', 'à']
as ['a', 'b', 'c', 'à']
, which unfortunately separates the 'a' and 'à' when it seems like they should appear next to each other.
You can try on dartpad.dev:
void main() {
final list = ['c', 'b', 'a', 'à'];
list.sort((a, b) => a.compareTo(b));
print(list); // [a, b, c, à]
}
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.
Could add a test that fails with the current code, with skip: true
, but passes with locale-aware sorting.
fefaf31
to
a70e75f
Compare
Thanks @chrisbobbe for the review. |
a70e75f
to
d1c4539
Compare
(I see my comment has been resolved, so it's Greg's turn now.) |
In @-mention autocomplete, users are suggested based on: 1. Recent activity in the current topic/stream. 2. Recent DM conversations. 3. Human vs. Bot users (human users come first).
In @-mention autocomplete, users are suggested based on: 1. Recent activity in the current topic/stream. 2. Recent DM conversations. 3. Human vs. Bot users (human users come first). 4. Alphabetical order. Fixes: zulip#228
The details of negative vs. positive vs. zero return values are part of the interface of comparators in general. The details of 1 vs. any other positive value, or -1 vs. any other negative value, are implementation details of the methods -- callers should only care about negative vs. positive vs. zero.
The way these tests were meant to work wasn't particularly explicit; and the recent changes adding more signals didn't take that intended structure into account, so that it became hard to see if the tests checked what they're intended to check. Bring them back to that structure, and add comments explaining it.
The recent changes that added two new ranking criteria added four new users to this test case. Two is enough to make the test's point, because it's enough for adding users that differ on the new criteria while tying on the criteria that have higher priority in the ranking.
d1c4539
to
e51d2f2
Compare
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.
Thanks @sm-sayedi, and thanks @rajveermalviya and @chrisbobbe for the previous reviews!
This looks good; merging, with some additional commits on top adjusting the tests and comments:
b48e54b autocomplete [nfc]: Simplify and clarify docs on comparator methods
093eaba autocomplete test: Fix up cross-signal tests; add comments to clarify
e51d2f2 autocomplete test: Tighten up "final results" test
So please take a look at those.
test/model/autocomplete_test.dart
Outdated
test('DmNarrow: DM recency > this-conversation recency or stream recency ' | ||
'or human vs. bot user or alphabetical order', () async { |
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.
This seems wrong — human-vs-bot should come before names, and the latter comes before those latter kinds of recency (because those don't count at all).
In @-mention autocomplete, users are suggested based on:
Note: This is the fourth (last) PR in the series of PRs #608 is divided into, coming after #828.
Fixes: #228