Skip to content

Commit f0cd8bc

Browse files
committed
views: Show SpoilerButton in message info view if present.
1 parent 60f9249 commit f0cd8bc

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,
@@ -1630,6 +1631,8 @@ def __init__(
16301631
msg_info.append(("Topic Links", []))
16311632
if time_mentions:
16321633
msg_info.append(("Time mentions", time_mentions))
1634+
if spoilers:
1635+
msg_info.append(("Spoilers", []))
16331636
if msg["reactions"]:
16341637
reactions = sorted(
16351638
(reaction["emoji_name"], reaction["user"]["full_name"])
@@ -1683,6 +1686,26 @@ def __init__(
16831686
widgets = widgets[:slice_index] + topic_link_widgets + widgets[slice_index:]
16841687
popup_width = max(popup_width, topic_link_width)
16851688

1689+
if spoilers:
1690+
spoiler_buttons = []
1691+
spoiler_width = 0
1692+
for index, (header_len, header, content) in enumerate(spoilers):
1693+
spoiler_width = max(header_len, spoiler_width)
1694+
display_attr = None if index % 2 else "popup_contrast"
1695+
spoiler_buttons.append(
1696+
SpoilerButton(controller, header_len, header, content, display_attr)
1697+
)
1698+
1699+
# slice_index = Number of labels before message links + 1 newline
1700+
# + 1 'Spoilers' category label.
1701+
# + 2 for Viewing Actions category label and its newline
1702+
slice_index = len(msg_info[0][1]) + len(msg_info[1][1]) + 2 + 2
1703+
slice_index += sum([len(w) + 2 for w in self.button_widgets])
1704+
self.button_widgets.append(spoiler_buttons)
1705+
1706+
widgets = widgets[:slice_index] + spoiler_buttons + widgets[slice_index:]
1707+
popup_width = max(popup_width, spoiler_width)
1708+
16861709
super().__init__(controller, widgets, "MSG_INFO", popup_width, title)
16871710

16881711
@staticmethod

0 commit comments

Comments
 (0)