Mastodon: Finished first implementation of 'reattempt to post on failures'. Should be relevant for #527, #526, #377, #137, #108

This commit is contained in:
Manuel Cortez 2023-03-23 13:17:55 -06:00
parent 3f0ee5650b
commit a57ea752d6
No known key found for this signature in database
GPG Key ID: 9E0735CA15EFE790
4 changed files with 31 additions and 12 deletions

View File

@ -564,4 +564,16 @@ class BaseBuffer(base.Buffer):
dlg.Destroy() dlg.Destroy()
if answer != wx.ID_OK: if answer != wx.ID_OK:
return return
poll = self.session.api_call(call_name="poll_vote", id=poll.id, choices=options, preexec_message=_("Sending vote...")) poll = self.session.api_call(call_name="poll_vote", id=poll.id, choices=options, preexec_message=_("Sending vote..."))
def post_from_error(self, visibility, data):
title = _("Post")
caption = _("Write your post here")
post = messages.post(session=self.session, title=title, caption=caption)
post.set_post_data(visibility=visibility, data=data)
response = post.message.ShowModal()
if response == wx.ID_OK:
post_data = post.get_data()
call_threaded(self.session.send_post, posts=post_data, visibility=post.get_visibility())
if hasattr(post.message, "destroy"):
post.message.destroy()

View File

@ -130,7 +130,7 @@ class Controller(object):
pub.subscribe(self.mastodon_new_item, "mastodon.new_item") pub.subscribe(self.mastodon_new_item, "mastodon.new_item")
pub.subscribe(self.mastodon_updated_item, "mastodon.updated_item") pub.subscribe(self.mastodon_updated_item, "mastodon.updated_item")
pub.subscribe(self.mastodon_new_conversation, "mastodon.conversation_received") pub.subscribe(self.mastodon_new_conversation, "mastodon.conversation_received")
pub.subscribe(self.mastodon_error_post, "mastodon.error_post")
# connect application events to GUI # connect application events to GUI
widgetUtils.connect_event(self.view, widgetUtils.CLOSE_EVENT, self.exit_) widgetUtils.connect_event(self.view, widgetUtils.CLOSE_EVENT, self.exit_)
widgetUtils.connect_event(self.view, widgetUtils.MENU, self.show_hide, menuitem=self.view.show_hide) widgetUtils.connect_event(self.view, widgetUtils.MENU, self.show_hide, menuitem=self.view.show_hide)
@ -1306,6 +1306,10 @@ class Controller(object):
# if "direct_messages" not in buffer.session.settings["other_buffers"]["muted_buffers"]: # if "direct_messages" not in buffer.session.settings["other_buffers"]["muted_buffers"]:
# self.notify(buffer.session, sound_to_play) # self.notify(buffer.session, sound_to_play)
def mastodon_error_post(self, name, reply_to, visibility, posts):
home = self.search_buffer("home_timeline", name)
wx.CallAfter(home.post_from_error, visibility=visibility, data=posts)
def report_error(self, *args, **kwargs): def report_error(self, *args, **kwargs):
"""Redirects the user to the issue page on github""" """Redirects the user to the issue page on github"""
log.debug("Redirecting the user to report an error...") log.debug("Redirecting the user to report an error...")

View File

@ -64,18 +64,22 @@ class post(messages.basicTweet):
self.add_post(event=None, update_gui=False) self.add_post(event=None, update_gui=False)
return self.thread return self.thread
def set_post_data(self, *data): def set_post_data(self, visibility, data):
if len(data) == 0: if len(data) == 0:
return return
if len(data) > 1: if len(data) > 1:
self.thread = data[:-1] self.thread = data[:-1]
for p in self.thread: for p in self.thread:
self.message.add_item(item=[p.get("text", ""), len(p.get("attachments", []))], list_type="post") self.message.add_item(item=[p.get("text") or "", len(p.get("attachments") or [])], list_type="post")
post = data[-1] post = data[-1]
self.attachments = post.get("attachments", []) self.attachments = post.get("attachments") or []
self.message.text.SetValue(post.get("text", "")) self.message.text.SetValue(post.get("text") or "")
self.message.sensitive.SetValue(post.get("sensitive", False)) self.message.sensitive.SetValue(post.get("sensitive") or False)
self.message.spoiler.SetValue(post.get("spoiler_text", "")) self.message.spoiler.SetValue(post.get("spoiler_text") or "")
visibility_settings = dict(public=0, unlisted=1, private=2, direct=3)
self.message.visibility.SetSelection(visibility_settings.get(visibility))
self.message.on_sensitivity_changed()
self.text_processor()
def text_processor(self, *args, **kwargs): def text_processor(self, *args, **kwargs):
text = self.message.text.GetValue() text = self.message.text.GetValue()

View File

@ -203,7 +203,7 @@ class Session(base.baseSession):
self.sound.play(_sound) self.sound.play(_sound)
return val return val
def send_post(self, reply_to=None, users=None, visibility=None, posts=[]): def send_post(self, reply_to=None, visibility=None, posts=[]):
""" Convenience function to send a thread. """ """ Convenience function to send a thread. """
in_reply_to_id = reply_to in_reply_to_id = reply_to
for obj in posts: for obj in posts:
@ -213,8 +213,7 @@ class Session(base.baseSession):
item = self.api_call(call_name="status_post", status=text, _sound="tweet_send.ogg", in_reply_to_id=in_reply_to_id, visibility=visibility, sensitive=obj["sensitive"], spoiler_text=obj["spoiler_text"]) item = self.api_call(call_name="status_post", status=text, _sound="tweet_send.ogg", in_reply_to_id=in_reply_to_id, visibility=visibility, sensitive=obj["sensitive"], spoiler_text=obj["spoiler_text"])
# If it fails, let's basically send an event with all passed info so we will catch it later. # If it fails, let's basically send an event with all passed info so we will catch it later.
except Exception as e: except Exception as e:
pub.sendMessage("mastodon.error_post", reply_to=reply_to, users=users, visibility=visibility, posts=posts) pub.sendMessage("mastodon.error_post", name=self.get_name(), reply_to=reply_to, visibility=visibility, posts=posts)
print("message sent")
return return
if item != None: if item != None:
in_reply_to_id = item["id"] in_reply_to_id = item["id"]
@ -232,7 +231,7 @@ class Session(base.baseSession):
if item != None: if item != None:
in_reply_to_id = item["id"] in_reply_to_id = item["id"]
except Exception as e: except Exception as e:
pub.sendMessage("mastodon.error_post", reply_to=reply_to, users=users, visibility=visibility, posts=posts) pub.sendMessage("mastodon.error_post", name=self.get_name(), reply_to=reply_to, visibility=visibility, posts=posts)
return return
def get_name(self): def get_name(self):