diff --git a/src/controller/buffers/mastodon/base.py b/src/controller/buffers/mastodon/base.py index a7b1ad7d..df008a03 100644 --- a/src/controller/buffers/mastodon/base.py +++ b/src/controller/buffers/mastodon/base.py @@ -16,6 +16,7 @@ from mysc.thread_utils import call_threaded from pubsub import pub from extra import ocr from wxUI import buffers, dialogs, commonMessageDialogs, menus +from wxUI.dialogs.mastodon import dialogs as dialogs log = logging.getLogger("controller.buffers.mastodon.base") @@ -264,13 +265,17 @@ class BaseBuffer(base.Buffer): def share_item(self, *args, **kwargs): if self.can_share() == False: return output.speak(_("This action is not supported on protected accounts.")) - toot = self.get_right_tweet() + toot = self.get_item() id = toot.id - pass + if self.session.settings["general"]["boost_mode"] == "ask": + answer = dialogs.boost_question() + if answer == True: + self._direct_boost(id) + else: + self._direct_boost(id) - def _direct_retweet(self, id): - item = self.session.api_call(call_name="retweet", _sound="retweet_send.ogg", id=id) - pass + def _direct_boost(self, id): + item = self.session.api_call(call_name="status_reblog", _sound="retweet_send.ogg", id=id) def onFocus(self, *args, **kwargs): toot = self.get_item() diff --git a/src/sessions/mastodon/session.py b/src/sessions/mastodon/session.py index c561aa59..d87c49f9 100644 --- a/src/sessions/mastodon/session.py +++ b/src/sessions/mastodon/session.py @@ -9,6 +9,7 @@ import config import config_utils import output import application +from mastodon import MastodonError, MastodonNotFoundError, MastodonUnauthorizedError from pubsub import pub from mysc.thread_utils import call_threaded from sessions import base @@ -114,3 +115,29 @@ class Session(base.baseSession): num = num+1 self.db[name] = objects return num + + def api_call(self, call_name, action="", _sound=None, report_success=False, report_failure=True, preexec_message="", *args, **kwargs): + finished = False + tries = 0 + if preexec_message: + output.speak(preexec_message, True) + while finished==False and tries < 25: + try: + val = getattr(self.api, call_name)(*args, **kwargs) + finished = True + except MastodonError as e: + output.speak(str(e)) + val = None + if type(e) != MastodonNotFoundError and type(e) != MastodonUnauthorizedError : + tries = tries+1 + time.sleep(5) + elif report_failure: + output.speak(_("%s failed. Reason: %s") % (action, str(e))) + finished = True +# except: +# tries = tries + 1 +# time.sleep(5) + if report_success: + output.speak(_("%s succeeded.") % action) + if _sound != None: self.sound.play(_sound) + return val