-
-
Notifications
You must be signed in to change notification settings - Fork 264
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add support for Polls Widget on ZT. #1551
Open
rsashank
wants to merge
6
commits into
zulip:main
Choose a base branch
from
rsashank:polls
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
+475
−4
Open
Changes from 1 commit
Commits
Show all changes
6 commits
Select commit
Hold shift + click to select a range
33fe3dd
widget: Add process_poll_widget function.
rsashank 610dfd0
messages: Implement logic to display polls on ZT.
rsashank 97c80bd
keys: Add SHOW_POLL_VOTES hotkey.
rsashank f32b62a
views: Add PollResultsView class.
rsashank a4019c5
core: Add show_poll_vote method to Controller.
rsashank dfbf2ee
messages: Add logic to handle the SHOW_POLL_VOTES hotkey.
rsashank File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev
Previous commit
Loading status checks…
messages: Add logic to handle the SHOW_POLL_VOTES hotkey.
commit dfbf2ee4db1ef087deba5d083f04a27dcb14fdff
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -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) | ||
|
@@ -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>" | ||
|
@@ -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", []) | ||
) | ||
|
||
|
@@ -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: | ||
|
@@ -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": | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. For no options, the popup operates but shows no data - maybe we should just skip the popup if there is no extra data to show? |
||
self.model.controller.show_poll_vote(self.poll_question, self.poll_options) | ||
return key |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nit: You've added self.widget_type, but not initialized the others earlier in this commit.