Skip to content

Commit

Permalink
boxes/model: Order mentions typeahead by subscribers for stream msgs.
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
kaustubh-nair committed Jul 27, 2020
1 parent 19053c2 commit ae1c02a
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 3 deletions.
6 changes: 6 additions & 0 deletions zulipterminal/model.py
Original file line number Diff line number Diff line change
Expand Up @@ -461,6 +461,12 @@ def _update_initial_data(self) -> None:
]
raise ServerConnectionFailure(", ".join(failure_text))

def get_other_subscribers_in_stream(self, stream_id: int) -> List[int]:
assert stream_id in self.stream_dict

return [sub for sub in self.stream_dict[stream_id]['subscribers']
if sub != self.user_id]

def get_all_users(self) -> List[Dict[str, Any]]:
# Dict which stores the active/idle status of users (by email)
presences = self.initial_data['presences']
Expand Down
11 changes: 8 additions & 3 deletions zulipterminal/ui_tools/boxes.py
Original file line number Diff line number Diff line change
Expand Up @@ -62,8 +62,11 @@ def private_box_view(self, button: Any=None, email: str='',
]
self.focus_position = 1

def stream_box_view(self, caption: str='', title: str='') -> None:
def stream_box_view(self, stream_id: int, caption: str='', title: str='',
) -> None:
self.set_editor_mode()
self.recipient_user_ids = self.model.get_other_subscribers_in_stream(
stream_id)
self.to_write_box = None
self.msg_write_box = ReadlineEdit(multiline=True)
self.msg_write_box.enable_autocomplete(
Expand Down Expand Up @@ -899,7 +902,8 @@ def keypress(self, size: urwid_Size, key: str) -> Optional[str]:
elif self.message['type'] == 'stream':
self.model.controller.view.write_box.stream_box_view(
caption=self.message['display_recipient'],
title=self.message['subject']
title=self.message['subject'],
stream_id=self.stream_id,
)
elif is_command_key('STREAM_MESSAGE', key):
if self.message['type'] == 'private':
Expand All @@ -909,7 +913,8 @@ def keypress(self, size: urwid_Size, key: str) -> Optional[str]:
)
elif self.message['type'] == 'stream':
self.model.controller.view.write_box.stream_box_view(
caption=self.message['display_recipient']
caption=self.message['display_recipient'],
stream_id=self.stream_id,
)
elif is_command_key('STREAM_NARROW', key):
if self.message['type'] == 'private':
Expand Down

0 comments on commit ae1c02a

Please sign in to comment.