|
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, process_todo_widget |
| 36 | +from zulipterminal.widget import ( |
| 37 | + find_widget_type, |
| 38 | + process_poll_widget, |
| 39 | + process_todo_widget, |
| 40 | +) |
37 | 41 |
|
38 | 42 |
|
39 | 43 | if typing.TYPE_CHECKING:
|
@@ -753,6 +757,39 @@ def main_view(self) -> List[Any]:
|
753 | 757 | # though it's not very useful.
|
754 | 758 | self.message["content"] = todo_widget
|
755 | 759 |
|
| 760 | + elif widget_type == "poll": |
| 761 | + poll_question, poll_options = process_poll_widget( |
| 762 | + self.message.get("submessages", []) |
| 763 | + ) |
| 764 | + |
| 765 | + # TODO: ZT doesn't yet support adding poll questions after the |
| 766 | + # creation of the poll. So, if the poll question is not provided, |
| 767 | + # we show a message to add one via the web app. |
| 768 | + if not poll_question: |
| 769 | + poll_question = ( |
| 770 | + "No poll question is provided. Please add one via the web app." |
| 771 | + ) |
| 772 | + |
| 773 | + poll_widget = f"<strong>Poll\n{poll_question}</strong>" |
| 774 | + |
| 775 | + if poll_options: |
| 776 | + max_votes_len = max( |
| 777 | + len(str(len(option["votes"]))) |
| 778 | + for option in poll_options.values() |
| 779 | + ) |
| 780 | + |
| 781 | + for option_info in poll_options.values(): |
| 782 | + padded_votes = f"{len(option_info['votes']):>{max_votes_len}}" |
| 783 | + poll_widget += f"\n[ {padded_votes} ] {option_info['option']}" |
| 784 | + else: |
| 785 | + poll_widget += ( |
| 786 | + "\nNo options provided. Please add them via the web app." |
| 787 | + ) |
| 788 | + |
| 789 | + # Update the message content with the latest poll_widget, |
| 790 | + # similar to the todo_widget above. |
| 791 | + self.message["content"] = poll_widget |
| 792 | + |
756 | 793 | # Transform raw message content into markup (As needed by urwid.Text)
|
757 | 794 | content, self.message_links, self.time_mentions = self.transform_content(
|
758 | 795 | self.message["content"], self.model.server_url
|
|
0 commit comments