Skip to content

Commit

Permalink
messages: Add logic to handle the SHOW_POLL_VOTES hotkey.
Browse files Browse the repository at this point in the history
  • Loading branch information
rsashank committed Nov 4, 2024
1 parent 990118a commit 78fd5df
Showing 1 changed file with 12 additions and 9 deletions.
21 changes: 12 additions & 9 deletions zulipterminal/ui_tools/messages.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -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>"
Expand All @@ -759,24 +760,24 @@ 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(
self.message.get("submessages", [])
)

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

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:
Expand Down Expand Up @@ -1185,4 +1186,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":
self.model.controller.show_poll_vote(self.poll_question, self.poll_options)
return key

0 comments on commit 78fd5df

Please sign in to comment.