|
32 | 32 | MentionedButton, |
33 | 33 | MessageLinkButton, |
34 | 34 | PMButton, |
| 35 | + SpoilerButton, |
35 | 36 | StarredButton, |
36 | 37 | StreamButton, |
37 | 38 | TopicButton, |
@@ -1338,6 +1339,8 @@ def __init__( |
1338 | 1339 | msg_info.append(("Message Links", [])) |
1339 | 1340 | if time_mentions: |
1340 | 1341 | msg_info.append(("Time mentions", time_mentions)) |
| 1342 | + if spoilers: |
| 1343 | + msg_info.append(("Spoilers", [])) |
1341 | 1344 | if msg["reactions"]: |
1342 | 1345 | reactions = sorted( |
1343 | 1346 | (reaction["emoji_name"], reaction["user"]["full_name"]) |
@@ -1388,6 +1391,25 @@ def __init__( |
1388 | 1391 | ) |
1389 | 1392 | popup_width = max(popup_width, message_link_width) |
1390 | 1393 |
|
| 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 | + |
1391 | 1413 | super().__init__(controller, widgets, "MSG_INFO", popup_width, title) |
1392 | 1414 |
|
1393 | 1415 | @staticmethod |
|
0 commit comments