Skip to content

Commit 7319fdf

Browse files
committed
messages: Implement logic to display polls on ZT.
1 parent 100ab3b commit 7319fdf

File tree

1 file changed

+28
-4
lines changed

1 file changed

+28
-4
lines changed

zulipterminal/ui_tools/messages.py

Lines changed: 28 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@
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
36+
from zulipterminal.widget import find_widget_type, process_poll_widget
3737

3838

3939
if typing.TYPE_CHECKING:
@@ -731,9 +731,33 @@ def main_view(self) -> List[Any]:
731731
)
732732

733733
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
737761

738762
# Transform raw message content into markup (As needed by urwid.Text)
739763
content, self.message_links, self.time_mentions = self.transform_content(

0 commit comments

Comments
 (0)