|
33 | 33 | from zulipterminal.server_url import near_message_url
|
34 | 34 | from zulipterminal.ui_tools.tables import render_table
|
35 | 35 | from zulipterminal.urwid_types import urwid_MarkupTuple, urwid_Size
|
36 |
| -from zulipterminal.widget import find_widget_type |
| 36 | +from zulipterminal.widget import find_widget_type, process_poll_widget |
37 | 37 |
|
38 | 38 |
|
39 | 39 | if typing.TYPE_CHECKING:
|
@@ -731,9 +731,33 @@ def main_view(self) -> List[Any]:
|
731 | 731 | )
|
732 | 732 |
|
733 | 733 | if self.message.get("submessages"):
|
734 |
| - widget_type = find_widget_type( # noqa: F841 |
735 |
| - self.message.get("submessages") |
736 |
| - ) |
| 734 | + widget_type = find_widget_type(self.message.get("submessages")) |
| 735 | + |
| 736 | + if widget_type == "poll": |
| 737 | + poll_question, poll_options = process_poll_widget( |
| 738 | + self.message.get("submessages") |
| 739 | + ) |
| 740 | + |
| 741 | + poll_widget = ( |
| 742 | + f"<strong>Poll: {poll_question}</strong>" |
| 743 | + if poll_question |
| 744 | + else "No poll question provided. Please add one via the web app." |
| 745 | + ) |
| 746 | + |
| 747 | + if poll_options: |
| 748 | + max_votes_len = max( |
| 749 | + len(str(len(option["votes"]))) |
| 750 | + for option in poll_options.values() |
| 751 | + ) |
| 752 | + |
| 753 | + for option_info in poll_options.values(): |
| 754 | + padded_votes = f"{len(option_info['votes']):>{max_votes_len}}" |
| 755 | + poll_widget += f"\n[ {padded_votes} ] {option_info['option']}" |
| 756 | + else: |
| 757 | + poll_widget += "\nNo options provided." |
| 758 | + "Please add them via the web app." |
| 759 | + |
| 760 | + self.message["content"] = poll_widget |
737 | 761 |
|
738 | 762 | # Transform raw message content into markup (As needed by urwid.Text)
|
739 | 763 | content, self.message_links, self.time_mentions = self.transform_content(
|
|
0 commit comments