From 0d8395c6fcee814356f34c819c0d657be3b0950f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jes=C3=BAs=20Pav=C3=B3n=20Abi=C3=A1n?= Date: Sun, 1 Feb 2026 20:21:44 +0100 Subject: [PATCH] =?UTF-8?q?Recuperar=20c=C3=B3digo=20antiguo=20que=20funci?= =?UTF-8?q?ona.=20Limpiar=20basura.?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/controller/buffers/blueski/base.py | 52 +++++++-- src/controller/mainController.py | 139 +------------------------ 2 files changed, 46 insertions(+), 145 deletions(-) diff --git a/src/controller/buffers/blueski/base.py b/src/controller/buffers/blueski/base.py index 593a9770..474557c6 100644 --- a/src/controller/buffers/blueski/base.py +++ b/src/controller/buffers/blueski/base.py @@ -11,6 +11,7 @@ from pubsub import pub from controller.buffers.base import base from controller.blueski import messages as blueski_messages from sessions.blueski import compose, utils +from mysc.thread_utils import call_threaded from wxUI.buffers.blueski import panels as BlueskiPanels from wxUI import commonMessageDialogs from wxUI.dialogs.blueski import menus @@ -193,9 +194,23 @@ class BaseBuffer(base.Buffer): dlg = postDialogs.Post(caption=_("New Post")) if dlg.ShowModal() == wx.ID_OK: text, files, cw, langs = dlg.get_payload() - self.session.send_message(message=text, files=files, cw_text=cw, langs=langs) - self.session.sound.play("tweet_send.ogg") - output.speak(_("Sent.")) + if not text and not files: + dlg.Destroy() + return + def do_send(): + try: + uri = self.session.send_message(message=text, files=files, cw_text=cw, langs=langs) + if uri: + wx.CallAfter(self.session.sound.play, "tweet_send.ogg") + wx.CallAfter(output.speak, _("Sent.")) + if hasattr(self, "start_stream"): + wx.CallAfter(self.start_stream, False, False) + else: + wx.CallAfter(output.speak, _("Failed to send post."), True) + except Exception: + log.exception("Error sending Bluesky post") + wx.CallAfter(output.speak, _("An error occurred while posting."), True) + call_threaded(do_send) dlg.Destroy() def on_reply(self, evt): @@ -226,14 +241,33 @@ class BaseBuffer(base.Buffer): dlg = postDialogs.Post(caption=_("Reply"), text=initial_text) if dlg.ShowModal() == wx.ID_OK: text, files, cw, langs = dlg.get_payload() - self.session.send_message(message=text, files=files, reply_to=uri, reply_to_cid=reply_cid, cw_text=cw, langs=langs) - self.session.sound.play("reply_send.ogg") - output.speak(_("Reply sent.")) - if getattr(self, "type", "") == "conversation": + if not text and not files: + dlg.Destroy() + return + def do_send(): try: - self.start_stream(mandatory=True, play_sound=False) + uri_resp = self.session.send_message( + message=text, + files=files, + reply_to=uri, + reply_to_cid=reply_cid, + cw_text=cw, + langs=langs + ) + if uri_resp: + wx.CallAfter(self.session.sound.play, "reply_send.ogg") + wx.CallAfter(output.speak, _("Reply sent.")) + if getattr(self, "type", "") == "conversation": + try: + wx.CallAfter(self.start_stream, True, False) + except Exception: + pass + else: + wx.CallAfter(output.speak, _("Failed to send reply."), True) except Exception: - pass + log.exception("Error sending Bluesky reply") + wx.CallAfter(output.speak, _("An error occurred while replying."), True) + call_threaded(do_send) dlg.Destroy() def on_repost(self, evt): diff --git a/src/controller/mainController.py b/src/controller/mainController.py index b6fed3f9..ec06f83b 100644 --- a/src/controller/mainController.py +++ b/src/controller/mainController.py @@ -638,70 +638,10 @@ class Controller(object): buffer = self.get_best_buffer() alias_controller = userAlias.userAliasController(buffer.session.settings) - def post_tweet(self, event=None): # This is the "New Post" menu item - """Opens the compose dialog for a new post.""" + def post_tweet(self, event=None): buffer = self.get_best_buffer() - if not buffer or not buffer.session: - output.speak(_("No active session to compose a post."), True) - return - - session = buffer.session - # Compose for Bluesky (ATProto): dialog with attachments/CW/language - if getattr(session, "type", "") == "blueski": - # In invisible interface, prefer a quick, minimal compose to avoid complex UI - if self.showing == False: - # Parent=None so it shows even if main window is hidden - dlg = wx.TextEntryDialog(None, _("Write your post:"), _("Compose")) - if dlg.ShowModal() == wx.ID_OK: - text = dlg.GetValue().strip() - dlg.Destroy() - if not text: - return - try: - uri = session.send_message(text) - if uri: - output.speak(_("Post sent successfully!"), True) - else: - output.speak(_("Failed to send post."), True) - except Exception: - log.exception("Error sending Bluesky post from invisible compose") - output.speak(_("An error occurred while posting to Bluesky."), True) - else: - dlg.Destroy() - return - from wxUI.dialogs.blueski.postDialogs import Post as ATPostDialog - dlg = ATPostDialog() - if dlg.ShowModal() == wx.ID_OK: - text, files, cw_text, langs = dlg.get_payload() - dlg.Destroy() - if not text and not files: - return - try: - uri = session.send_message(text, files=files, cw_text=cw_text, is_sensitive=bool(cw_text), languages=langs) - if uri: - output.speak(_("Post sent successfully!"), True) - try: - if hasattr(buffer, "start_stream"): - buffer.start_stream(mandatory=False, play_sound=False) - except Exception: - pass - else: - output.speak(_("Failed to send post."), True) - except Exception: - log.exception("Error sending Bluesky post from compose dialog") - output.speak(_("An error occurred while posting to Bluesky."), True) - else: - dlg.Destroy() - return - # For a new post, reply_to_uri and quote_uri are None. - # Import the new dialog - from wxUI.dialogs.composeDialog import ComposeDialog - # Pass self.view as parent - dialog = ComposeDialog(parent=self.view, session=session) - # We don't call dialog.ShowModal() directly if its on_send uses pubsub. - # The dialog will be shown, and its on_send will publish a message. - # mainController.handle_compose_dialog_send will handle the rest. - dialog.Show() # Use Show() for non-modal if pubsub handles closing, or ShowModal() if dialog handles its lifecycle + if hasattr(buffer, "post_status"): + buffer.post_status() def handle_compose_dialog_send(self, session, text, files, reply_to, cw_text, is_sensitive, kwargs, dialog_instance): """Handles the actual sending of a post after ComposeDialog publishes data.""" @@ -749,81 +689,8 @@ class Controller(object): def post_reply(self, *args, **kwargs): buffer = self.get_current_buffer() - if not buffer: - return - # Use buffer's own reply method if available (handles Mastodon and most cases) if hasattr(buffer, "reply"): return buffer.reply() - # Fallback for buffers without reply method - if not buffer.session: - output.speak(_("No active session to reply."), True) - return - - selected_item_uri = None - if hasattr(buffer, "get_selected_item_id"): - selected_item_uri = buffer.get_selected_item_id() - selected_item_cid = None - if hasattr(buffer, "get_selected_item_cid"): - selected_item_cid = buffer.get_selected_item_cid() - if not selected_item_uri: - output.speak(_("No item selected to reply to."), True) - return - - session = buffer.session - if getattr(session, "type", "") == "blueski": - author_handle = "" - if hasattr(buffer, "get_selected_item_author_details"): - details = buffer.get_selected_item_author_details() - if details: - author_handle = details.get("handle", "") or details.get("did", "") - initial_text = f"@{author_handle} " if author_handle and not author_handle.startswith("@") else (f"{author_handle} " if author_handle else "") - if self.showing == False: - dlg = wx.TextEntryDialog(None, _("Write your reply:"), _("Reply")) - if dlg.ShowModal() == wx.ID_OK: - text = dlg.GetValue().strip() - dlg.Destroy() - if not text: - return - try: - uri = session.send_message(text, reply_to=selected_item_uri, reply_to_cid=selected_item_cid) - if uri: - output.speak(_("Reply sent."), True) - else: - output.speak(_("Failed to send reply."), True) - except Exception: - log.exception("Error sending Bluesky reply (invisible)") - output.speak(_("An error occurred while replying."), True) - else: - dlg.Destroy() - return - from wxUI.dialogs.blueski.postDialogs import Post as ATPostDialog - dlg = ATPostDialog(caption=_("Reply"), text=initial_text) - if dlg.ShowModal() == wx.ID_OK: - text, files, cw_text, langs = dlg.get_payload() - dlg.Destroy() - if not text and not files: - return - try: - uri = session.send_message(text, files=files, cw_text=cw_text, is_sensitive=bool(cw_text), languages=langs, reply_to=selected_item_uri, reply_to_cid=selected_item_cid) - if uri: - output.speak(_("Reply sent."), True) - try: - if hasattr(buffer, "start_stream"): - buffer.start_stream(mandatory=False, play_sound=False) - except Exception: - pass - else: - output.speak(_("Failed to send reply."), True) - except Exception: - log.exception("Error sending Bluesky reply (dialog)") - output.speak(_("An error occurred while replying."), True) - else: - dlg.Destroy() - return - - from wxUI.dialogs.composeDialog import ComposeDialog - dialog = ComposeDialog(parent=self.view, session=buffer.session, reply_to_uri=selected_item_uri, initial_text="") - dialog.Show() def send_dm(self, *args, **kwargs):