Skip to content

Commit

Permalink
messages: Implement logic to display polls on ZT.
Browse files Browse the repository at this point in the history
  • Loading branch information
rsashank committed Oct 8, 2024
1 parent 100ab3b commit 7319fdf
Showing 1 changed file with 28 additions and 4 deletions.
32 changes: 28 additions & 4 deletions zulipterminal/ui_tools/messages.py
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@
from zulipterminal.server_url import near_message_url
from zulipterminal.ui_tools.tables import render_table
from zulipterminal.urwid_types import urwid_MarkupTuple, urwid_Size
from zulipterminal.widget import find_widget_type
from zulipterminal.widget import find_widget_type, process_poll_widget


if typing.TYPE_CHECKING:
Expand Down Expand Up @@ -731,9 +731,33 @@ def main_view(self) -> List[Any]:
)

if self.message.get("submessages"):
widget_type = find_widget_type( # noqa: F841
self.message.get("submessages")
)
widget_type = find_widget_type(self.message.get("submessages"))

if widget_type == "poll":
poll_question, poll_options = process_poll_widget(
self.message.get("submessages")
)

poll_widget = (
f"<strong>Poll: {poll_question}</strong>"
if poll_question
else "No poll question provided. Please add one via the web app."
)

if poll_options:
max_votes_len = max(
len(str(len(option["votes"])))
for option in poll_options.values()
)

for option_info in poll_options.values():
padded_votes = f"{len(option_info['votes']):>{max_votes_len}}"
poll_widget += f"\n[ {padded_votes} ] {option_info['option']}"
else:
poll_widget += "\nNo options provided."
"Please add them via the web app."

self.message["content"] = poll_widget

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

0 comments on commit 7319fdf

Please sign in to comment.