Skip to content

Commit

Permalink
buttons: Add handle_narrow to handle stream narrow.
Browse files Browse the repository at this point in the history
Note: Topic narrow has not been implemented yet.
  • Loading branch information
preetmishra committed Jul 31, 2020
1 parent 3adf08d commit 7541304
Showing 1 changed file with 25 additions and 2 deletions.
27 changes: 25 additions & 2 deletions zulipterminal/ui_tools/buttons.py
Original file line number Diff line number Diff line change
Expand Up @@ -286,11 +286,34 @@ def handle_link(self, *_: Any) -> None:
"""
if self.is_internal_link:
if '/#narrow/' in self.link:
# TODO: Handle internal link.
pass
self.handle_narrow()
elif '/user_uploads/' in self.link:
# TODO: Open media in the native viewer.
pass
else:
# TODO: Open external link in the web browser.
pass

def handle_narrow(self) -> None:
"""
Handles stream narrow.
"""
# TODO: Handle topic narrow.
link_split = self.link.split('/')

self.stream_id = int(link_split[5].split('-')[0])

# Return if the concerned stream is unsubscribed.
if self.stream_id not in self.model.stream_dict:
text = ' You are not subscribed to the stream'
self.view.set_footer_text(text, duration=3)
return

self.stream_name = self.model.stream_dict[self.stream_id]['name']

if '/stream/' in self.link:
self.controller.narrow_to_stream(self)

# Exit popup if the narrow was successful.
if hasattr(self.controller.loop.widget, '_Overlay__super'):
self.controller.exit_popup()

0 comments on commit 7541304

Please sign in to comment.