diff --git a/tests/ui_tools/test_buttons.py b/tests/ui_tools/test_buttons.py index 644bc7d811..380ce821e0 100644 --- a/tests/ui_tools/test_buttons.py +++ b/tests/ui_tools/test_buttons.py @@ -322,8 +322,8 @@ def spoiler_button( header: List[Any] = [""], content: List[Any] = [""], message: Message = {}, - topic_links: Dict[str, Tuple[str, int, bool]] = {}, - message_links: Dict[str, Tuple[str, int, bool]] = {}, + topic_links: Dict[str, Tuple[str, int, bool, bool]] = {}, + message_links: Dict[str, Tuple[str, int, bool, bool]] = {}, time_mentions: List[Tuple[str, str]] = [], spoilers: List[Tuple[int, List[Any], List[Any]]] = [], display_attr: Optional[str] = None, diff --git a/tests/ui_tools/test_messages.py b/tests/ui_tools/test_messages.py index f2f7825256..2c0c999fc0 100644 --- a/tests/ui_tools/test_messages.py +++ b/tests/ui_tools/test_messages.py @@ -1881,7 +1881,7 @@ def test_reactions_view( [ ( "https://github.com/zulip/zulip-terminal/pull/1", - ("#T1", 1, True), + ("#T1", 1, True, False), ), ] ), @@ -1893,8 +1893,8 @@ def test_reactions_view( case( OrderedDict( [ - ("https://foo.com", ("Foo!", 1, True)), - ("https://bar.com", ("Bar!", 2, True)), + ("https://foo.com", ("Foo!", 1, True, False)), + ("https://bar.com", ("Bar!", 2, True, False)), ] ), "1: https://foo.com\n2: https://bar.com", @@ -1913,8 +1913,11 @@ def test_reactions_view( case( OrderedDict( [ - ("https://example.com", ("https://example.com", 1, False)), - ("http://example.com", ("http://example.com", 2, False)), + ( + "https://example.com", + ("https://example.com", 1, False, False), + ), + ("http://example.com", ("http://example.com", 2, False, False)), ] ), None, @@ -1925,8 +1928,8 @@ def test_reactions_view( case( OrderedDict( [ - ("https://foo.com", ("https://foo.com, Text", 1, True)), - ("https://bar.com", ("Text, https://bar.com", 2, True)), + ("https://foo.com", ("https://foo.com, Text", 1, True, False)), + ("https://bar.com", ("Text, https://bar.com", 2, True, False)), ] ), "1: https://foo.com\n2: https://bar.com", @@ -1945,9 +1948,9 @@ def test_reactions_view( case( OrderedDict( [ - ("https://foo.com", ("Foo!", 1, True)), - ("http://example.com", ("example.com", 2, False)), - ("https://bar.com", ("Bar!", 3, True)), + ("https://foo.com", ("Foo!", 1, True, False)), + ("http://example.com", ("example.com", 2, False, False)), + ("https://bar.com", ("Bar!", 3, True, False)), ] ), "1: https://foo.com\n3: https://bar.com", @@ -1994,7 +1997,7 @@ def test_footlinks_view( def test_footlinks_limit(self, maximum_footlinks, expected_instance): message_links = OrderedDict( [ - ("https://github.com/zulip/zulip-terminal", ("ZT", 1, True)), + ("https://github.com/zulip/zulip-terminal", ("ZT", 1, True, False)), ] ) diff --git a/tests/ui_tools/test_popups.py b/tests/ui_tools/test_popups.py index 1fe9247608..9041a3767a 100644 --- a/tests/ui_tools/test_popups.py +++ b/tests/ui_tools/test_popups.py @@ -1054,9 +1054,9 @@ def test_init(self, message_fixture: Message) -> None: assert self.msg_info_view.time_mentions == list() assert self.msg_info_view.spoilers == list() - def test_pop_up_info_order(self, message_fixture: Message) -> None: - topic_links = OrderedDict([("https://bar.com", ("topic", 1, True))]) - message_links = OrderedDict([("image.jpg", ("image", 1, True))]) + def test_popup_info_order(self, message_fixture: Message) -> None: + topic_links = OrderedDict([("https://bar.com", ("topic", 1, True, False))]) + message_links = OrderedDict([("image.jpg", ("image", 1, True, False))]) msg_info_view = MsgInfoView( self.controller, message_fixture, @@ -1302,14 +1302,14 @@ def test_height_reactions( ], [ ( - OrderedDict([("https://bar.com", ("Foo", 1, True))]), + OrderedDict([("https://bar.com", ("Foo", 1, True, False))]), "1: Foo\nhttps://bar.com", {None: "popup_contrast"}, {None: "selected"}, 15, ), ( - OrderedDict([("https://foo.com", ("", 1, True))]), + OrderedDict([("https://foo.com", ("", 1, True, False))]), "1: https://foo.com", {None: "popup_contrast"}, {None: "selected"}, @@ -1323,7 +1323,7 @@ def test_height_reactions( ) def test_create_link_buttons( self, - initial_link: "OrderedDict[str, Tuple[str, int, bool]]", + initial_link: "OrderedDict[str, Tuple[str, int, bool, bool]]", expected_text: str, expected_attr_map: Dict[None, str], expected_focus_map: Dict[None, str], @@ -1588,8 +1588,8 @@ def test_markup_description( ( OrderedDict( [ - ("https://example.com", ("Example", 1, True)), - ("https://generic.com", ("Generic", 2, True)), + ("https://example.com", ("Example", 1, True, False)), + ("https://generic.com", ("Generic", 2, True, False)), ] ), "1: https://example.com\n2: https://generic.com", @@ -1608,7 +1608,7 @@ def test_markup_description( ) def test_footlinks( self, - message_links: "OrderedDict[str, Tuple[str, int, bool]]", + message_links: "OrderedDict[str, Tuple[str, int, bool, bool]]", expected_text: str, expected_attrib: List[Tuple[Optional[str], int]], expected_footlinks_width: int, diff --git a/zulipterminal/core.py b/zulipterminal/core.py index 8215f52041..6f313b72c5 100644 --- a/zulipterminal/core.py +++ b/zulipterminal/core.py @@ -262,8 +262,8 @@ def show_topic_edit_mode(self, button: Any) -> None: def show_msg_info( self, msg: Message, - topic_links: Dict[str, Tuple[str, int, bool]], - message_links: Dict[str, Tuple[str, int, bool]], + topic_links: Dict[str, Tuple[str, int, bool, bool]], + message_links: Dict[str, Tuple[str, int, bool, bool]], time_mentions: List[Tuple[str, str]], spoilers: List[Tuple[int, List[Any], List[Any]]], ) -> None: @@ -342,8 +342,8 @@ def show_msg_sender_info(self, user_id: int) -> None: def show_full_rendered_message( self, message: Message, - topic_links: Dict[str, Tuple[str, int, bool]], - message_links: Dict[str, Tuple[str, int, bool]], + topic_links: Dict[str, Tuple[str, int, bool, bool]], + message_links: Dict[str, Tuple[str, int, bool, bool]], time_mentions: List[Tuple[str, str]], spoilers: List[Tuple[int, List[Any], List[Any]]], ) -> None: @@ -363,8 +363,8 @@ def show_full_rendered_message( def show_full_raw_message( self, message: Message, - topic_links: Dict[str, Tuple[str, int, bool]], - message_links: Dict[str, Tuple[str, int, bool]], + topic_links: Dict[str, Tuple[str, int, bool, bool]], + message_links: Dict[str, Tuple[str, int, bool, bool]], time_mentions: List[Tuple[str, str]], spoilers: List[Tuple[int, List[Any], List[Any]]], ) -> None: @@ -384,8 +384,8 @@ def show_full_raw_message( def show_edit_history( self, message: Message, - topic_links: Dict[str, Tuple[str, int, bool]], - message_links: Dict[str, Tuple[str, int, bool]], + topic_links: Dict[str, Tuple[str, int, bool, bool]], + message_links: Dict[str, Tuple[str, int, bool, bool]], time_mentions: List[Tuple[str, str]], spoilers: List[Tuple[int, List[Any], List[Any]]], ) -> None: @@ -494,8 +494,8 @@ def show_spoiler( self, content: str, message: Message, - topic_links: Dict[str, Tuple[str, int, bool]], - message_links: Dict[str, Tuple[str, int, bool]], + topic_links: Dict[str, Tuple[str, int, bool, bool]], + message_links: Dict[str, Tuple[str, int, bool, bool]], time_mentions: List[Tuple[str, str]], spoilers: List[Tuple[int, List[Any], List[Any]]], ) -> None: diff --git a/zulipterminal/ui_tools/buttons.py b/zulipterminal/ui_tools/buttons.py index 19a8295cb6..7003d230d6 100644 --- a/zulipterminal/ui_tools/buttons.py +++ b/zulipterminal/ui_tools/buttons.py @@ -325,8 +325,8 @@ def __init__( header: List[Any], content: List[Any], message: Message, - topic_links: Dict[str, Tuple[str, int, bool]], - message_links: Dict[str, Tuple[str, int, bool]], + topic_links: Dict[str, Tuple[str, int, bool, bool]], + message_links: Dict[str, Tuple[str, int, bool, bool]], time_mentions: List[Tuple[str, str]], spoilers: List[Tuple[int, List[Any], List[Any]]], display_attr: Optional[str], diff --git a/zulipterminal/ui_tools/messages.py b/zulipterminal/ui_tools/messages.py index 274b485474..e695dbd4cf 100644 --- a/zulipterminal/ui_tools/messages.py +++ b/zulipterminal/ui_tools/messages.py @@ -60,8 +60,8 @@ def __init__(self, message: Message, model: "Model", last_message: Any) -> None: self.topic_name = "" self.email = "" # FIXME: Can we remove this? self.user_id: Optional[int] = None - self.message_links: Dict[str, Tuple[str, int, bool]] = dict() - self.topic_links: Dict[str, Tuple[str, int, bool]] = dict() + self.message_links: Dict[str, Tuple[str, int, bool, bool]] = dict() + self.topic_links: Dict[str, Tuple[str, int, bool, bool]] = dict() self.time_mentions: List[Tuple[str, str]] = list() self.spoilers: List[Tuple[int, List[Any], List[Any]]] = list() self.last_message = last_message @@ -77,6 +77,7 @@ def __init__(self, message: Message, model: "Model", last_message: Any) -> None: link["text"], len(self.topic_links) + 1, True, + False, ) self.stream_name = self.message["display_recipient"] @@ -314,7 +315,7 @@ def reactions_view( @staticmethod def footlinks_view( - message_links: Dict[str, Tuple[str, int, bool]], + message_links: Dict[str, Tuple[str, int, bool, bool]], *, maximum_footlinks: int, padded: bool, @@ -331,7 +332,7 @@ def footlinks_view( footlinks = [] counter = 0 footlinks_width = 0 - for link, (text, index, show_footlink) in message_links.items(): + for link, (text, index, show_footlink, spoiler_link) in message_links.items(): if counter == maximum_footlinks: break if not show_footlink: @@ -374,7 +375,7 @@ def soup2markup( cls, soup: Any, metadata: Dict[str, Any], **state: Any ) -> Tuple[ List[Any], - Dict[str, Tuple[str, int, bool]], + Dict[str, Tuple[str, int, bool, bool]], List[Tuple[str, str]], List[Tuple[int, List[Any], List[Any]]], ]: @@ -503,8 +504,11 @@ def soup2markup( # Do not show as a footlink as the text is sufficient # to represent the link. show_footlink = False + + spoiler_link = False if element.find_parent("div", class_="spoiler-block"): show_footlink = False + spoiler_link = True # Detect duplicate links to save screen real estate. if link not in metadata["message_links"]: @@ -512,18 +516,23 @@ def soup2markup( text, len(metadata["message_links"]) + 1, show_footlink, + spoiler_link, ) else: # Append the text if its link already exist with a # different text. - saved_text, saved_link_index, saved_footlink_status = metadata[ - "message_links" - ][link] + ( + saved_text, + saved_link_index, + saved_footlink_status, + spoiler_link, + ) = metadata["message_links"][link] if saved_text != text: metadata["message_links"][link] = ( f"{saved_text}, {text}", saved_link_index, show_footlink or saved_footlink_status, + spoiler_link, ) markup.extend( @@ -900,7 +909,7 @@ def transform_content( cls, content: Any, server_url: str ) -> Tuple[ Tuple[None, Any], - Dict[str, Tuple[str, int, bool]], + Dict[str, Tuple[str, int, bool, bool]], List[Tuple[str, str]], List[Tuple[int, List[Any], List[Any]]], ]: diff --git a/zulipterminal/ui_tools/views.py b/zulipterminal/ui_tools/views.py index 1df1461156..2b209e8236 100644 --- a/zulipterminal/ui_tools/views.py +++ b/zulipterminal/ui_tools/views.py @@ -1084,8 +1084,8 @@ def __init__( title: str, content: str, message: Message, - topic_links: Dict[str, Tuple[str, int, bool]], - message_links: Dict[str, Tuple[str, int, bool]], + topic_links: Dict[str, Tuple[str, int, bool, bool]], + message_links: Dict[str, Tuple[str, int, bool, bool]], time_mentions: List[Tuple[str, str]], spoilers: List[Tuple[int, List[Any], List[Any]]], ) -> None: @@ -1609,8 +1609,8 @@ def __init__( controller: Any, msg: Message, title: str, - topic_links: Dict[str, Tuple[str, int, bool]], - message_links: Dict[str, Tuple[str, int, bool]], + topic_links: Dict[str, Tuple[str, int, bool, bool]], + message_links: Dict[str, Tuple[str, int, bool, bool]], time_mentions: List[Tuple[str, str]], spoilers: List[Tuple[int, List[Any], List[Any]]], ) -> None: @@ -1748,17 +1748,21 @@ def __init__( @staticmethod def create_link_buttons( - controller: Any, links: Dict[str, Tuple[str, int, bool]] + controller: Any, links: Dict[str, Tuple[str, int, bool, bool]] ) -> Tuple[List[MessageLinkButton], int]: link_widgets = [] link_width = 0 for index, link in enumerate(links): - text, link_index, _ = links[link] + text, link_index, _, spoiler_link = links[link] if text: caption = f"{link_index}: {text}\n{link}" + if spoiler_link: + caption = f"{link_index} [spoiler]: {text}\n{link}" else: caption = f"{link_index}: {link}" + if spoiler_link: + caption = f"{link_index} [spoiler]: {link}" link_width = max(link_width, len(max(caption.split("\n"), key=len))) display_attr = None if index % 2 else "popup_contrast" @@ -1884,8 +1888,8 @@ def __init__( self, controller: Any, message: Message, - topic_links: Dict[str, Tuple[str, int, bool]], - message_links: Dict[str, Tuple[str, int, bool]], + topic_links: Dict[str, Tuple[str, int, bool, bool]], + message_links: Dict[str, Tuple[str, int, bool, bool]], time_mentions: List[Tuple[str, str]], spoilers: List[Tuple[int, List[Any], List[Any]]], title: str, @@ -2005,8 +2009,8 @@ def __init__( self, controller: Any, message: Message, - topic_links: Dict[str, Tuple[str, int, bool]], - message_links: Dict[str, Tuple[str, int, bool]], + topic_links: Dict[str, Tuple[str, int, bool, bool]], + message_links: Dict[str, Tuple[str, int, bool, bool]], time_mentions: List[Tuple[str, str]], spoilers: List[Tuple[int, List[Any], List[Any]]], title: str, @@ -2052,8 +2056,8 @@ def __init__( self, controller: Any, message: Message, - topic_links: Dict[str, Tuple[str, int, bool]], - message_links: Dict[str, Tuple[str, int, bool]], + topic_links: Dict[str, Tuple[str, int, bool, bool]], + message_links: Dict[str, Tuple[str, int, bool, bool]], time_mentions: List[Tuple[str, str]], spoilers: List[Tuple[int, List[Any], List[Any]]], title: str,