Skip to content

Commit

Permalink
buttons/helper: Add support for topic narrow in handle_narrow.
Browse files Browse the repository at this point in the history
  • Loading branch information
preetmishra committed Jul 31, 2020
1 parent 7541304 commit 789d01a
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 3 deletions.
7 changes: 7 additions & 0 deletions zulipterminal/helper.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
Any, Callable, DefaultDict, Dict, FrozenSet, Iterable, List, Set, Tuple,
TypeVar, Union,
)
from urllib.parse import unquote

import lxml.html
from mypy_extensions import TypedDict
Expand Down Expand Up @@ -618,3 +619,9 @@ def display_error_if_present(response: Dict[str, Any], controller: Any
) -> None:
if response['result'] == 'error':
controller.view.set_footer_text(response['msg'], 3)


def hash_util_decode(string: str) -> str:
# Acknowledge custom string replacements in zulip/zulip's
# zerver/lib/url_encoding.py before unquote.
return unquote(string.replace('.', '%').replace('%2E', '.'))
10 changes: 7 additions & 3 deletions zulipterminal/ui_tools/buttons.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
import urwid

from zulipterminal.config.keys import is_command_key, keys_for_command
from zulipterminal.helper import hash_util_decode
from zulipterminal.urwid_types import urwid_Size


Expand Down Expand Up @@ -296,9 +297,8 @@ def handle_link(self, *_: Any) -> None:

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

self.stream_id = int(link_split[5].split('-')[0])
Expand All @@ -311,7 +311,11 @@ def handle_narrow(self) -> None:

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

if '/stream/' in self.link:
if '/topic/' in self.link:
encoded_topic = link_split[7]
self.topic_name = hash_util_decode(encoded_topic)
self.controller.narrow_to_topic(self)
elif '/stream/' in self.link:
self.controller.narrow_to_stream(self)

# Exit popup if the narrow was successful.
Expand Down

0 comments on commit 789d01a

Please sign in to comment.