Skip to content

Commit 3c2836b

Browse files
committed
views: Show SpoilerButton in message info view if present.
This commit wraps-up the PR by appending the SpoilerButton to message info view if present. Co-authored by: Preet Mishra (<[email protected]>). Fixes zulip#688.
1 parent 819c30d commit 3c2836b

File tree

1 file changed

+22
-0
lines changed

1 file changed

+22
-0
lines changed

zulipterminal/ui_tools/views.py

+22
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@
3232
MentionedButton,
3333
MessageLinkButton,
3434
PMButton,
35+
SpoilerButton,
3536
StarredButton,
3637
StreamButton,
3738
TopicButton,
@@ -1338,6 +1339,8 @@ def __init__(
13381339
msg_info.append(("Message Links", []))
13391340
if time_mentions:
13401341
msg_info.append(("Time mentions", time_mentions))
1342+
if spoilers:
1343+
msg_info.append(("Spoilers", []))
13411344
if msg["reactions"]:
13421345
reactions = sorted(
13431346
(reaction["emoji_name"], reaction["user"]["full_name"])
@@ -1388,6 +1391,25 @@ def __init__(
13881391
)
13891392
popup_width = max(popup_width, message_link_width)
13901393

1394+
if spoilers:
1395+
spoiler_buttons = []
1396+
spoiler_width = 0
1397+
for index, (header_len, header, content) in enumerate(spoilers):
1398+
spoiler_width = max(header_len, spoiler_width)
1399+
display_attr = None if index % 2 else "popup_contrast"
1400+
spoiler_buttons.append(
1401+
SpoilerButton(controller, header_len, header, content, display_attr)
1402+
)
1403+
1404+
# slice_index = Number of labels before message links + 1 newline
1405+
# + 1 'Spoilers' category label.
1406+
slice_index = len(msg_info[0][1]) + 2
1407+
slice_index += sum([len(w) + 2 for w in button_widgets])
1408+
button_widgets.append(spoiler_buttons)
1409+
1410+
widgets = widgets[:slice_index] + spoiler_buttons + widgets[slice_index:]
1411+
popup_width = max(popup_width, spoiler_width)
1412+
13911413
super().__init__(controller, widgets, "MSG_INFO", popup_width, title)
13921414

13931415
@staticmethod

0 commit comments

Comments
 (0)