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 Jan 20, 2025
1 parent a4019c5 commit dfbf2ee
Showing 1 changed file with 10 additions and 7 deletions.
17 changes: 10 additions & 7 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,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(
self.message.get("submessages", [])
)

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

0 comments on commit dfbf2ee

Please sign in to comment.