Recuperar código antiguo que funciona. Limpiar basura.

This commit is contained in:
Jesús Pavón Abián
2026-02-01 20:21:44 +01:00
parent 86adf2311a
commit 0d8395c6fc
2 changed files with 46 additions and 145 deletions

View File

@@ -11,6 +11,7 @@ from pubsub import pub
from controller.buffers.base import base from controller.buffers.base import base
from controller.blueski import messages as blueski_messages from controller.blueski import messages as blueski_messages
from sessions.blueski import compose, utils from sessions.blueski import compose, utils
from mysc.thread_utils import call_threaded
from wxUI.buffers.blueski import panels as BlueskiPanels from wxUI.buffers.blueski import panels as BlueskiPanels
from wxUI import commonMessageDialogs from wxUI import commonMessageDialogs
from wxUI.dialogs.blueski import menus from wxUI.dialogs.blueski import menus
@@ -193,9 +194,23 @@ class BaseBuffer(base.Buffer):
dlg = postDialogs.Post(caption=_("New Post")) dlg = postDialogs.Post(caption=_("New Post"))
if dlg.ShowModal() == wx.ID_OK: if dlg.ShowModal() == wx.ID_OK:
text, files, cw, langs = dlg.get_payload() text, files, cw, langs = dlg.get_payload()
self.session.send_message(message=text, files=files, cw_text=cw, langs=langs) if not text and not files:
self.session.sound.play("tweet_send.ogg") dlg.Destroy()
output.speak(_("Sent.")) 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() dlg.Destroy()
def on_reply(self, evt): def on_reply(self, evt):
@@ -226,14 +241,33 @@ class BaseBuffer(base.Buffer):
dlg = postDialogs.Post(caption=_("Reply"), text=initial_text) dlg = postDialogs.Post(caption=_("Reply"), text=initial_text)
if dlg.ShowModal() == wx.ID_OK: if dlg.ShowModal() == wx.ID_OK:
text, files, cw, langs = dlg.get_payload() 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) if not text and not files:
self.session.sound.play("reply_send.ogg") dlg.Destroy()
output.speak(_("Reply sent.")) return
if getattr(self, "type", "") == "conversation": def do_send():
try: 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: 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() dlg.Destroy()
def on_repost(self, evt): def on_repost(self, evt):

View File

@@ -638,70 +638,10 @@ class Controller(object):
buffer = self.get_best_buffer() buffer = self.get_best_buffer()
alias_controller = userAlias.userAliasController(buffer.session.settings) alias_controller = userAlias.userAliasController(buffer.session.settings)
def post_tweet(self, event=None): # This is the "New Post" menu item def post_tweet(self, event=None):
"""Opens the compose dialog for a new post."""
buffer = self.get_best_buffer() buffer = self.get_best_buffer()
if not buffer or not buffer.session: if hasattr(buffer, "post_status"):
output.speak(_("No active session to compose a post."), True) buffer.post_status()
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
def handle_compose_dialog_send(self, session, text, files, reply_to, cw_text, is_sensitive, kwargs, dialog_instance): 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.""" """Handles the actual sending of a post after ComposeDialog publishes data."""
@@ -749,81 +689,8 @@ class Controller(object):
def post_reply(self, *args, **kwargs): def post_reply(self, *args, **kwargs):
buffer = self.get_current_buffer() 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"): if hasattr(buffer, "reply"):
return 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): def send_dm(self, *args, **kwargs):