Skip to content

Commit af39cee

Browse files
committed
messages: Implement logic to display polls on ZT.
1 parent 827ef2c commit af39cee

File tree

1 file changed

+33
-1
lines changed

1 file changed

+33
-1
lines changed

zulipterminal/ui_tools/messages.py

Lines changed: 33 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,11 @@
3333
from zulipterminal.server_url import near_message_url
3434
from zulipterminal.ui_tools.tables import render_table
3535
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+
)
3741

3842

3943
if typing.TYPE_CHECKING:
@@ -755,6 +759,34 @@ def main_view(self) -> List[Any]:
755759
# though it's not very useful.
756760
self.message["content"] = todo_widget
757761

762+
elif widget_type == "poll":
763+
poll_question, poll_options = process_poll_widget(
764+
self.message.get("submessages", [])
765+
)
766+
767+
poll_widget = (
768+
f"<strong>Poll\n{poll_question}</strong>"
769+
if poll_question
770+
else "No poll question provided. Please add one via the web app."
771+
)
772+
773+
if poll_options:
774+
max_votes_len = max(
775+
len(str(len(option["votes"])))
776+
for option in poll_options.values()
777+
)
778+
779+
for option_info in poll_options.values():
780+
padded_votes = f"{len(option_info['votes']):>{max_votes_len}}"
781+
poll_widget += f"\n[ {padded_votes} ] {option_info['option']}"
782+
else:
783+
poll_widget += "\nNo options provided."
784+
"Please add them via the web app."
785+
786+
# Update the message content with the latest poll_widget,
787+
# similar to the todo_widget above.
788+
self.message["content"] = poll_widget
789+
758790
# Transform raw message content into markup (As needed by urwid.Text)
759791
content, self.message_links, self.time_mentions = self.transform_content(
760792
self.message["content"], self.model.server_url

0 commit comments

Comments
 (0)