Skip to content

Commit dfbf2ee

Browse files
committed
messages: Add logic to handle the SHOW_POLL_VOTES hotkey.
1 parent a4019c5 commit dfbf2ee

File tree

1 file changed

+10
-7
lines changed

1 file changed

+10
-7
lines changed

zulipterminal/ui_tools/messages.py

+10-7
Original file line numberDiff line numberDiff line change
@@ -69,6 +69,7 @@ def __init__(self, message: Message, model: "Model", last_message: Any) -> None:
6969
self.topic_links: Dict[str, Tuple[str, int, bool]] = dict()
7070
self.time_mentions: List[Tuple[str, str]] = list()
7171
self.last_message = last_message
72+
self.widget_type: str = ""
7273
# if this is the first message
7374
if self.last_message is None:
7475
self.last_message = defaultdict(dict)
@@ -735,9 +736,9 @@ def main_view(self) -> List[Any]:
735736
)
736737

737738
if self.message.get("submessages"):
738-
widget_type = find_widget_type(self.message.get("submessages", []))
739+
self.widget_type = find_widget_type(self.message.get("submessages", []))
739740

740-
if widget_type == "todo":
741+
if self.widget_type == "todo":
741742
title, tasks = process_todo_widget(self.message.get("submessages", []))
742743

743744
todo_widget = "<strong>To-do</strong>\n" + f"<strong>{title}</strong>"
@@ -759,8 +760,8 @@ def main_view(self) -> List[Any]:
759760
# though it's not very useful.
760761
self.message["content"] = todo_widget
761762

762-
elif widget_type == "poll":
763-
poll_question, poll_options = process_poll_widget(
763+
elif self.widget_type == "poll":
764+
self.poll_question, self.poll_options = process_poll_widget(
764765
self.message.get("submessages", [])
765766
)
766767

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

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

777-
if poll_options:
778+
if self.poll_options:
778779
max_votes_len = max(
779780
len(str(len(option["votes"])))
780-
for option in poll_options.values()
781+
for option in self.poll_options.values()
781782
)
782783

783-
for option_info in poll_options.values():
784+
for option_info in self.poll_options.values():
784785
padded_votes = f"{len(option_info['votes']):>{max_votes_len}}"
785786
poll_widget += f"\n[ {padded_votes} ] {option_info['option']}"
786787
else:
@@ -1189,4 +1190,6 @@ def keypress(self, size: urwid_Size, key: str) -> Optional[str]:
11891190
self.model.controller.show_emoji_picker(self.message)
11901191
elif is_command_key("MSG_SENDER_INFO", key):
11911192
self.model.controller.show_msg_sender_info(self.message["sender_id"])
1193+
elif is_command_key("SHOW_POLL_VOTES", key) and self.widget_type == "poll":
1194+
self.model.controller.show_poll_vote(self.poll_question, self.poll_options)
11921195
return key

0 commit comments

Comments
 (0)