mirror of
https://github.com/MCV-Software/TWBlue.git
synced 2025-07-17 21:56:07 -04:00
Mastodon: Added experimental support for voting in polls
This commit is contained in:
@@ -20,6 +20,7 @@ from extra import ocr
|
||||
from wxUI import buffers, dialogs, commonMessageDialogs
|
||||
from wxUI.dialogs.mastodon import menus
|
||||
from wxUI.dialogs.mastodon import dialogs as mastodon_dialogs
|
||||
from wxUI.dialogs.mastodon.postDialogs import attachedPoll
|
||||
|
||||
log = logging.getLogger("controller.buffers.mastodon.base")
|
||||
|
||||
@@ -538,4 +539,29 @@ class BaseBuffer(base.Buffer):
|
||||
def ocr_image(self):
|
||||
post = self.get_item()
|
||||
media_list = []
|
||||
pass
|
||||
pass
|
||||
|
||||
def vote(self):
|
||||
post = self.get_item()
|
||||
if not hasattr(post, "poll") or post.poll == None:
|
||||
return
|
||||
poll = post.poll
|
||||
try:
|
||||
poll = self.session.api.poll(id=poll.id)
|
||||
except MastodonNotFoundError:
|
||||
output.speak(_("this poll no longer exists."))
|
||||
return
|
||||
if poll.expired:
|
||||
output.speak(_("This poll has already expired."))
|
||||
return
|
||||
if poll.voted:
|
||||
output.speak(_("You have already voted on this poll."))
|
||||
return
|
||||
options = poll.options
|
||||
dlg = attachedPoll(poll_options=[option.title for option in options], multiple=poll.multiple)
|
||||
answer = dlg.ShowModal()
|
||||
options = dlg.get_selected()
|
||||
dlg.Destroy()
|
||||
if answer != wx.ID_OK:
|
||||
return
|
||||
poll = self.session.api_call(call_name="poll_vote", id=poll.id, choices=options, preexec_message=_("Sending vote..."))
|
@@ -42,6 +42,9 @@ class NotificationsBuffer(BaseBuffer):
|
||||
def unfav(self):
|
||||
pass
|
||||
|
||||
def vote(self):
|
||||
pass
|
||||
|
||||
def can_share(self):
|
||||
return False
|
||||
|
||||
|
@@ -593,6 +593,11 @@ class Controller(object):
|
||||
if hasattr(buffer, "toggle_favorite"):
|
||||
return buffer.toggle_favorite()
|
||||
|
||||
def vote(self, *args, **kwargs):
|
||||
buffer = self.get_current_buffer()
|
||||
if hasattr(buffer, "vote"):
|
||||
return buffer.vote()
|
||||
|
||||
def view_item(self, *args, **kwargs):
|
||||
buffer = self.get_current_buffer()
|
||||
if hasattr(buffer, "view_item"):
|
||||
|
Reference in New Issue
Block a user