Skip to content
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

Merged
merged 7 commits into from
Aug 9, 2024

Conversation

sm-sayedi
Copy link
Collaborator

@sm-sayedi sm-sayedi commented Jul 29, 2024

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.

Note: This is the fourth (last) PR in the series of PRs #608 is divided into, coming after #828.

Fixes: #228

Copy link
Member

@rajveermalviya rajveermalviya left a 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.

Comment on lines 247 to 251
if (!userA.isBot && userB.isBot) {
return -1;
} else if (userA.isBot && !userB.isBot) {
return 1;
}
Copy link
Member

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.

@rajveermalviya rajveermalviya added mentor review GSoC mentor review needed. and removed buddy review GSoC buddy review needed. labels Jul 30, 2024
@rajveermalviya rajveermalviya requested a review from hackerkid July 30, 2024 17:27
@sm-sayedi sm-sayedi force-pushed the issue-228-sort-@-mention-results branch from 24f3ea5 to fefaf31 Compare July 31, 2024 06:23
@sm-sayedi
Copy link
Collaborator Author

Thanks @rajveermalviya for the review and the tip. Changes applied.

@sm-sayedi sm-sayedi added the maintainer review PR ready for review by Zulip maintainers label Jul 31, 2024
@sm-sayedi sm-sayedi requested a review from chrisbobbe July 31, 2024 06:40
Copy link
Collaborator

@chrisbobbe chrisbobbe left a 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.

.normalizedNameForUser(userA);
final userBName = store.autocompleteViewManager.autocompleteDataCache
.normalizedNameForUser(userB);
return userAName.compareTo(userBName);
Copy link
Collaborator

@chrisbobbe chrisbobbe Jul 31, 2024

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, à]
}

Copy link
Collaborator

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.

@chrisbobbe chrisbobbe added integration review Added by maintainers when PR may be ready for integration and removed maintainer review PR ready for review by Zulip maintainers labels Jul 31, 2024
@sm-sayedi sm-sayedi force-pushed the issue-228-sort-@-mention-results branch from fefaf31 to a70e75f Compare August 1, 2024 06:28
@sm-sayedi
Copy link
Collaborator Author

Thanks @chrisbobbe for the review.

@sm-sayedi sm-sayedi requested a review from gnprice August 1, 2024 06:38
@sm-sayedi sm-sayedi force-pushed the issue-228-sort-@-mention-results branch from a70e75f to d1c4539 Compare August 4, 2024 04:28
@chrisbobbe
Copy link
Collaborator

(I see my comment has been resolved, so it's Greg's turn now.)

sm-sayedi and others added 7 commits August 8, 2024 17:19
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.
@gnprice gnprice force-pushed the issue-228-sort-@-mention-results branch from d1c4539 to e51d2f2 Compare August 9, 2024 00:31
@gnprice gnprice merged commit e51d2f2 into zulip:main Aug 9, 2024
Copy link
Member

@gnprice gnprice left a 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.

Comment on lines 620 to 621
test('DmNarrow: DM recency > this-conversation recency or stream recency '
'or human vs. bot user or alphabetical order', () async {
Copy link
Member

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).

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
integration review Added by maintainers when PR may be ready for integration mentor review GSoC mentor review needed.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

autocomplete: Sort user-mention autocomplete results
4 participants