Skip to content

Commit

Permalink
views: Show SpoilerButton in message info view if present.
Browse files Browse the repository at this point in the history
  • Loading branch information
rsashank committed Jul 1, 2024
1 parent 60f9249 commit f0cd8bc
Showing 1 changed file with 23 additions and 0 deletions.
23 changes: 23 additions & 0 deletions zulipterminal/ui_tools/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,7 @@
MentionedButton,
MessageLinkButton,
PMButton,
SpoilerButton,
StarredButton,
StreamButton,
TopicButton,
Expand Down Expand Up @@ -1630,6 +1631,8 @@ def __init__(
msg_info.append(("Topic Links", []))
if time_mentions:
msg_info.append(("Time mentions", time_mentions))
if spoilers:
msg_info.append(("Spoilers", []))
if msg["reactions"]:
reactions = sorted(
(reaction["emoji_name"], reaction["user"]["full_name"])
Expand Down Expand Up @@ -1683,6 +1686,26 @@ def __init__(
widgets = widgets[:slice_index] + topic_link_widgets + widgets[slice_index:]
popup_width = max(popup_width, topic_link_width)

if spoilers:
spoiler_buttons = []
spoiler_width = 0
for index, (header_len, header, content) in enumerate(spoilers):
spoiler_width = max(header_len, spoiler_width)
display_attr = None if index % 2 else "popup_contrast"
spoiler_buttons.append(
SpoilerButton(controller, header_len, header, content, display_attr)
)

# slice_index = Number of labels before message links + 1 newline
# + 1 'Spoilers' category label.
# + 2 for Viewing Actions category label and its newline
slice_index = len(msg_info[0][1]) + len(msg_info[1][1]) + 2 + 2
slice_index += sum([len(w) + 2 for w in self.button_widgets])
self.button_widgets.append(spoiler_buttons)

widgets = widgets[:slice_index] + spoiler_buttons + widgets[slice_index:]
popup_width = max(popup_width, spoiler_width)

super().__init__(controller, widgets, "MSG_INFO", popup_width, title)

@staticmethod
Expand Down

0 comments on commit f0cd8bc

Please sign in to comment.