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 6 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
Prev Previous commit
messages: Add logic to handle the SHOW_POLL_VOTES hotkey.
rsashank committed Jan 20, 2025

Verified

This commit was signed with the committer’s verified signature.
commit dfbf2ee4db1ef087deba5d083f04a27dcb14fdff
17 changes: 10 additions & 7 deletions zulipterminal/ui_tools/messages.py
Original file line number Diff line number Diff line change
@@ -69,6 +69,7 @@ def __init__(self, message: Message, model: "Model", last_message: Any) -> None:
self.topic_links: Dict[str, Tuple[str, int, bool]] = dict()
self.time_mentions: List[Tuple[str, str]] = list()
self.last_message = last_message
self.widget_type: str = ""
# if this is the first message
if self.last_message is None:
self.last_message = defaultdict(dict)
@@ -735,9 +736,9 @@ def main_view(self) -> List[Any]:
)

if self.message.get("submessages"):
widget_type = find_widget_type(self.message.get("submessages", []))
self.widget_type = find_widget_type(self.message.get("submessages", []))

if widget_type == "todo":
if self.widget_type == "todo":
title, tasks = process_todo_widget(self.message.get("submessages", []))

todo_widget = "<strong>To-do</strong>\n" + f"<strong>{title}</strong>"
@@ -759,8 +760,8 @@ 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(
elif self.widget_type == "poll":
self.poll_question, self.poll_options = process_poll_widget(
Comment on lines +763 to +764
Copy link
Collaborator

Choose a reason for hiding this comment

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

Nit: You've added self.widget_type, but not initialized the others earlier in this commit.

self.message.get("submessages", [])
)

@@ -774,13 +775,13 @@ def main_view(self) -> List[Any]:

poll_widget = f"<strong>Poll\n{poll_question}</strong>"

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

for option_info in poll_options.values():
for option_info in self.poll_options.values():
padded_votes = f"{len(option_info['votes']):>{max_votes_len}}"
poll_widget += f"\n[ {padded_votes} ] {option_info['option']}"
else:
@@ -1189,4 +1190,6 @@ def keypress(self, size: urwid_Size, key: str) -> Optional[str]:
self.model.controller.show_emoji_picker(self.message)
elif is_command_key("MSG_SENDER_INFO", key):
self.model.controller.show_msg_sender_info(self.message["sender_id"])
elif is_command_key("SHOW_POLL_VOTES", key) and self.widget_type == "poll":
Copy link
Collaborator

Choose a reason for hiding this comment

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

For no options, the popup operates but shows no data - maybe we should just skip the popup if there is no extra data to show?

self.model.controller.show_poll_vote(self.poll_question, self.poll_options)
return key