-
-
Notifications
You must be signed in to change notification settings - Fork 261
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
Order typeahead by narrow/recipients #730
Order typeahead by narrow/recipients #730
Conversation
ac53aae
to
25b38c1
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.
@kaustubh-nair This looks useful :)
Regarding streams, I think we should be careful that we don't forget to keep our stream-subscriber lists up to date via subscription
events. If ZT runs for some time then these will become out of date. For a long time we didn't update the presence list and it was a little too easy to forget it was out of date.
I was testing the stream autocomplete on ZT, but there's more users subscribed to that stream than I realized!
25b38c1
to
1ec052f
Compare
1ec052f
to
5e152f6
Compare
@neiljp Thanks for the review, updated the PR |
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.
@kaustubh-nair This user ordering is definitely better without 'ourselves' 👍
There are a few remaining points to fix/discuss, but this is close to merging, I think?
With a workaround for the 'no subscriber' case, I think we could leave the problem of updating potential 'subscribers' when the target of the message changes in the compose box to a a later PR, unless you want to add it as an extra commit? If we do leave it then could you please open an issue if you don't plan to work on it straight away?
Another follow-up aspect we could consider would be 'dividers' in the footer, perhaps, to separate 'this conversation' from 'others'? That could be reflected in partitioning the user list based on 'in this conversation' too? (sort of pinning them above?) That's probably worth discussing :)
zulipterminal/ui_tools/boxes.py
Outdated
print(self.subscriber_ids, flush=True) | ||
# Remove current user. | ||
self.subscriber_ids.remove(self.model.user_id) | ||
print(self.subscriber_ids, flush=True) |
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.
Perhaps add commits between the ones you push, for debugging, to drop in the push but which you can put back? :)
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.
Oh no, I keep forgetting to check for these 🤦
zulipterminal/ui_tools/boxes.py
Outdated
@@ -36,8 +37,14 @@ def main_view(self, new: bool) -> Any: | |||
def set_editor_mode(self) -> None: | |||
self.view.controller.enter_editor_mode_with(self) | |||
|
|||
def private_box_view(self, button: Any=None, email: str='') -> None: | |||
def private_box_view(self, button: Any=None, email: str='', | |||
subscriber_ids: List[int]=[]) -> None: |
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.
A default argument like this is one of the traps in python. If we truly need a default argument then we need to use None
as default.
Note that there are other calls to private_box_view
, and at least x
can cause a crash right now. We could work around that in the first instance, but ultimately I think we want to update subscribers/recipients when the stream/users list is updated. For example, if I compose to #announce, but edit it to go to #test here, then autocomplete is still based on announce right now.
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.
OK, a shallow copy is causing the crash here rather than the change in recipients. I think it is fine to not have the current user stored in the recipients at all? That would also be consistent with the other recipient data we're storing in MessageBox
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.
Updating subscribers requires a little more discussion, opened #737
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.
On second thought, this wouldn't be too hard I'll fix this in the same PR
I also just got a crash from |
5e152f6
to
e0816b3
Compare
bbc238a
to
b6d21a9
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.
@kaustubh-nair Thanks for adding the subscription events 👍 Here's the next iteration of comments.
zulipterminal/ui_tools/boxes.py
Outdated
@@ -36,8 +37,10 @@ def main_view(self, new: bool) -> Any: | |||
def set_editor_mode(self) -> None: | |||
self.view.controller.enter_editor_mode_with(self) | |||
|
|||
def private_box_view(self, button: Any=None, email: str='') -> None: | |||
def private_box_view(self, button: Any=None, email: str='', | |||
recipient_user_ids: List[int]=[]) -> None: |
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.
I know that we're not modifying the list right now, but this would be safer if we treated this as Optional[List[int]]=None
, as I suggested in the last review, in case we later do so. Here's an article discussing this: https://towardsdatascience.com/python-pitfall-mutable-default-arguments-9385e8265422
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.
Oh no, that's horrible!
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.
Another approach I've seen which we could try here is to use the type checker and only allow passing in a Sequence
, but the change you've made looks fine.
4ab3291
to
1dfa9f4
Compare
tests/model/test_model.py
Outdated
def test__handle_subscription_event_muting(self, model, mocker, | ||
stream_button, event, | ||
final_muted_streams): |
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 this intentional?
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.
Yes, this test deals only with muting, I'll move this to the previous commit though
zulipterminal/ui_tools/boxes.py
Outdated
self.set_editor_mode() | ||
subscribers = deepcopy(self.model.get_subscribers_in_stream(stream_id)) |
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 not return a new list in the method, and skip the need for the deepcopy? Alternatively, we're only using it here so far, so we could change it to be get_other_subscribers_in_stream
and incorporate the extra code below?
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.
Thismethod can be used for displaying subscriber counts.
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.
Returning a new list is the same as using deepcopy(I think?), so I would just be moving the deepcopy to the model?
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.
OK, modified it to get_other_subscribers_in_stream()
and used the stream_dict
directly for subscribers counts. Removed the test because I don't see a point in writing an entire test just for a simple assert_called_once_with()
. This can added when the whole method is tested.
@kaustubh-nair In addition to the few minor points above, I'd suggest you checking the other |
3678459
to
ae1c02a
Compare
Show user-name suggestions first instead of groups, since they are used more often. This is important when a user is using typeahead with an empty query ( for example just '@' ) because in the future, when typeaheads are ordered by the participants in the current narrow - having groups first would not make this ordering apparent on empty queries.
This commit orders typeahead for mentions such that participants of the private message/group message are displayed first. WriteBox now stores an additional attribute called recipient_user_ids which stores the user_ids of the recipients/subscribers in a conversation. Test added.
The subscription event includes an 'op' attribute to differentiate between different operations possible for updating subscriptions. This this commit changes subscription handling to use the 'update' operation for identifying the mute/unmute events. Tests parameters updated, and renamed the test appropriately.
The optional flag include_subscribers in client.register is set to True so that subscriber data for streams is returned. This data can be useful for multiple features, such as ordering typeahead by subscribers, and displaying number of subscribers in stream information. This commit also handles the subscription event for updating the stream subscribers. Test added.
ae1c02a
to
c9635db
Compare
Update recipient_user_ids in WriteBox for stream messages which is used to order mentions typeahead. The logic for doing this ordering has already been implemented in WriteBox.autocomplete_mentions(). stream_id is passed to WriteBox instead of using stream names to look-up subscriber data to avoid bugs due to duplicate stream names.
c9635db
to
0c84676
Compare
@kaustubh-nair Thanks for getting this work done, it makes the typeahead much more useful and the footer list more informative 👍 I know you have other typeahead work underway, but this change of footer ordering suggests we could consider other styles to use in the footer for typeahead or temporary notices, and/or maybe separators to mark different sections. |
Since Model.stream_dict does not contain data for unsubscribed streams, trying to handle this event raises exceptions. Fixes issue introduced in #730. Test added.
This PR orders the mentions typeahead such that participants/subscribers in the current conversation are shown first.
There are two parts to this:
Part 1: Add ordering logic (Commits 1 & 2) - This is done by adding a
recipient_user_ids
attribute toWriteBox
, storing the user ids of the participants. This is supported only for private messages because subscriber data for streams is not available. Note that storing recipient ids inMessageBox
is necessary because there is no other way to obtain the user ids.Part 2: Add subscriber data for streams thus enabling ordering (Commits 4 & 5) - Set
include_subscribers
to True while fetching initial data to get stream subscriber data. Just store this inWriteBox.recipient_user_ids
and voila!