Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add support for Polls Widget on ZT. #1551

Open
wants to merge 7 commits into
base: main
Choose a base branch
from
Open
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
34 changes: 33 additions & 1 deletion zulipterminal/ui_tools/messages.py
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,11 @@
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, process_todo_widget
from zulipterminal.widget import (
find_widget_type,
process_poll_widget,
process_todo_widget,
)


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

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

poll_widget = (
f"<strong>Poll\n{poll_question}</strong>"
if poll_question
else "No poll question provided. Please add one via the web app."
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nit: For this line and one further below, we might consider using a fixed string common to both cases, and adding a TODO comment which relates to the lack of this feature so far (in ZT).

)

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']}"
neiljp marked this conversation as resolved.
Show resolved Hide resolved
else:
poll_widget += "\nNo options provided."
"Please add them via the web app."

# Update the message content with the latest poll_widget,
# similar to the todo_widget above.
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(
self.message["content"], self.model.server_url
Expand Down