Skip to content

Commit 2b4f57f

Browse files
rsashankpreetmishraEzio-Sarthak
committed
views: Show SpoilerButton in message info view if present.
This commit appends the SpoilerButton to message info view if present. Co-authored-by: Preet Mishra <[email protected]> Co-authored-by: Ezio-Sarthak <[email protected]>
1 parent fb3cfb8 commit 2b4f57f

File tree

1 file changed

+23
-0
lines changed

1 file changed

+23
-0
lines changed

zulipterminal/ui_tools/views.py

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,7 @@
5151
MentionedButton,
5252
MessageLinkButton,
5353
PMButton,
54+
SpoilerButton,
5455
StarredButton,
5556
StreamButton,
5657
TopicButton,
@@ -1646,6 +1647,8 @@ def __init__(
16461647
msg_info.append(("Topic Links", []))
16471648
if time_mentions:
16481649
msg_info.append(("Time mentions", time_mentions))
1650+
if spoilers:
1651+
msg_info.append(("Spoilers", []))
16491652
if msg["reactions"]:
16501653
reactions = sorted(
16511654
(reaction["emoji_name"], reaction["user"]["full_name"])
@@ -1699,6 +1702,26 @@ def __init__(
16991702
widgets = widgets[:slice_index] + topic_link_widgets + widgets[slice_index:]
17001703
popup_width = max(popup_width, topic_link_width)
17011704

1705+
if spoilers:
1706+
spoiler_buttons = []
1707+
spoiler_width = 0
1708+
for index, (header_len, header, content) in enumerate(spoilers):
1709+
spoiler_width = max(header_len, spoiler_width)
1710+
display_attr = None if index % 2 else "popup_contrast"
1711+
spoiler_buttons.append(
1712+
SpoilerButton(controller, header_len, header, content, display_attr)
1713+
)
1714+
1715+
# slice_index = Number of labels before message links + 1 newline
1716+
# + 1 'Spoilers' category label.
1717+
# + 2 for Viewing Actions category label and its newline
1718+
slice_index = len(msg_info[0][1]) + len(msg_info[1][1]) + 2 + 2
1719+
slice_index += sum([len(w) + 2 for w in self.button_widgets])
1720+
self.button_widgets.append(spoiler_buttons)
1721+
1722+
widgets = widgets[:slice_index] + spoiler_buttons + widgets[slice_index:]
1723+
popup_width = max(popup_width, spoiler_width)
1724+
17021725
super().__init__(controller, widgets, "MSG_INFO", popup_width, title)
17031726

17041727
@staticmethod

0 commit comments

Comments
 (0)