@@ -69,6 +69,7 @@ def __init__(self, message: Message, model: "Model", last_message: Any) -> None:
69
69
self .topic_links : Dict [str , Tuple [str , int , bool ]] = dict ()
70
70
self .time_mentions : List [Tuple [str , str ]] = list ()
71
71
self .last_message = last_message
72
+ self .widget_type : str = ""
72
73
# if this is the first message
73
74
if self .last_message is None :
74
75
self .last_message = defaultdict (dict )
@@ -733,9 +734,9 @@ def main_view(self) -> List[Any]:
733
734
)
734
735
735
736
if self .message .get ("submessages" ):
736
- widget_type = find_widget_type (self .message .get ("submessages" , []))
737
+ self . widget_type = find_widget_type (self .message .get ("submessages" , []))
737
738
738
- if widget_type == "todo" :
739
+ if self . widget_type == "todo" :
739
740
title , tasks = process_todo_widget (self .message .get ("submessages" , []))
740
741
741
742
todo_widget = "<strong>To-do</strong>\n " + f"<strong>{ title } </strong>"
@@ -757,28 +758,28 @@ def main_view(self) -> List[Any]:
757
758
# though it's not very useful.
758
759
self .message ["content" ] = todo_widget
759
760
760
- elif widget_type == "poll" :
761
- poll_question , poll_options = process_poll_widget (
761
+ elif self . widget_type == "poll" :
762
+ self . poll_question , self . poll_options = process_poll_widget (
762
763
self .message .get ("submessages" , [])
763
764
)
764
765
765
766
# TODO: ZT doesn't yet support adding poll questions after the
766
767
# creation of the poll. So, if the poll question is not provided,
767
768
# we show a message to add one via the web app.
768
- if not poll_question :
769
- poll_question = (
769
+ if not self . poll_question :
770
+ self . poll_question = (
770
771
"No poll question is provided. Please add one via the web app."
771
772
)
772
773
773
- poll_widget = f"<strong>Poll\n { poll_question } </strong>"
774
+ poll_widget = f"<strong>Poll\n { self . poll_question } </strong>"
774
775
775
- if poll_options :
776
+ if self . poll_options :
776
777
max_votes_len = max (
777
778
len (str (len (option ["votes" ])))
778
- for option in poll_options .values ()
779
+ for option in self . poll_options .values ()
779
780
)
780
781
781
- for option_info in poll_options .values ():
782
+ for option_info in self . poll_options .values ():
782
783
padded_votes = f"{ len (option_info ['votes' ]):>{max_votes_len }} "
783
784
poll_widget += f"\n [ { padded_votes } ] { option_info ['option' ]} "
784
785
else :
@@ -1188,4 +1189,6 @@ def keypress(self, size: urwid_Size, key: str) -> Optional[str]:
1188
1189
self .model .controller .show_emoji_picker (self .message )
1189
1190
elif is_command_key ("MSG_SENDER_INFO" , key ):
1190
1191
self .model .controller .show_msg_sender_info (self .message ["sender_id" ])
1192
+ elif is_command_key ("SHOW_POLL_VOTES" , key ) and self .widget_type == "poll" :
1193
+ self .model .controller .show_poll_vote (self .poll_question , self .poll_options )
1191
1194
return key
0 commit comments