@@ -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 )
@@ -733,9 +734,9 @@ def main_view(self) -> List[Any]:
733734 )
734735
735736 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" , []))
737738
738- if widget_type == "todo" :
739+ if self . widget_type == "todo" :
739740 title , tasks = process_todo_widget (self .message .get ("submessages" , []))
740741
741742 todo_widget = "<strong>To-do</strong>\n " + f"<strong>{ title } </strong>"
@@ -757,28 +758,28 @@ def main_view(self) -> List[Any]:
757758 # though it's not very useful.
758759 self .message ["content" ] = todo_widget
759760
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 (
762763 self .message .get ("submessages" , [])
763764 )
764765
765766 # TODO: ZT doesn't yet support adding poll questions after the
766767 # creation of the poll. So, if the poll question is not provided,
767768 # 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 = (
770771 "No poll question is provided. Please add one via the web app."
771772 )
772773
773- poll_widget = f"<strong>Poll\n { poll_question } </strong>"
774+ poll_widget = f"<strong>Poll\n { self . poll_question } </strong>"
774775
775- if poll_options :
776+ if self . poll_options :
776777 max_votes_len = max (
777778 len (str (len (option ["votes" ])))
778- for option in poll_options .values ()
779+ for option in self . poll_options .values ()
779780 )
780781
781- for option_info in poll_options .values ():
782+ for option_info in self . poll_options .values ():
782783 padded_votes = f"{ len (option_info ['votes' ]):>{max_votes_len }} "
783784 poll_widget += f"\n [ { padded_votes } ] { option_info ['option' ]} "
784785 else :
@@ -1188,4 +1189,6 @@ def keypress(self, size: urwid_Size, key: str) -> Optional[str]:
11881189 self .model .controller .show_emoji_picker (self .message )
11891190 elif is_command_key ("MSG_SENDER_INFO" , key ):
11901191 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 )
11911194 return key
0 commit comments