mirror of
https://github.com/MCV-Software/TWBlue.git
synced 2026-03-06 01:17:32 +01:00
Fix broken application.app.controller references in Bluesky buffers
application.app was never set anywhere - application.py is just a constants module. Every call to view_chat(), on_new_chat(), view_conversation(), on_reposts(), and on_likes() crashed with AttributeError, silently swallowed by get_event's except clause. Fix: store controller reference on each buffer during create_buffer() in mainController, then use self.controller instead of the broken application.app.controller pattern throughout all Bluesky buffer and dialog code. Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
This commit is contained in:
@@ -317,8 +317,9 @@ def _extract_post_view_data(session: Any, item: Any) -> dict[str, Any] | None:
|
|||||||
|
|
||||||
|
|
||||||
class viewPost(base_messages.basicMessage):
|
class viewPost(base_messages.basicMessage):
|
||||||
def __init__(self, session: Any, item: Any):
|
def __init__(self, session: Any, item: Any, controller: Any = None):
|
||||||
self.session = session
|
self.session = session
|
||||||
|
self.controller = controller
|
||||||
data = _extract_post_view_data(session, item)
|
data = _extract_post_view_data(session, item)
|
||||||
if not data:
|
if not data:
|
||||||
output.speak(_("No post available to view."), True)
|
output.speak(_("No post available to view."), True)
|
||||||
@@ -362,11 +363,10 @@ class viewPost(base_messages.basicMessage):
|
|||||||
output.speak(_("Link copied to clipboard."))
|
output.speak(_("Link copied to clipboard."))
|
||||||
|
|
||||||
def on_reposts(self, *args, **kwargs):
|
def on_reposts(self, *args, **kwargs):
|
||||||
if not self.post_uri:
|
if not self.post_uri or not self.controller:
|
||||||
return
|
return
|
||||||
try:
|
try:
|
||||||
import application
|
controller = self.controller
|
||||||
controller = application.app.controller
|
|
||||||
account_name = self.session.get_name()
|
account_name = self.session.get_name()
|
||||||
list_name = f"{self.post_uri}-reposts"
|
list_name = f"{self.post_uri}-reposts"
|
||||||
existing = controller.search_buffer(list_name, account_name)
|
existing = controller.search_buffer(list_name, account_name)
|
||||||
@@ -391,11 +391,10 @@ class viewPost(base_messages.basicMessage):
|
|||||||
pass
|
pass
|
||||||
|
|
||||||
def on_likes(self, *args, **kwargs):
|
def on_likes(self, *args, **kwargs):
|
||||||
if not self.post_uri:
|
if not self.post_uri or not self.controller:
|
||||||
return
|
return
|
||||||
try:
|
try:
|
||||||
import application
|
controller = self.controller
|
||||||
controller = application.app.controller
|
|
||||||
account_name = self.session.get_name()
|
account_name = self.session.get_name()
|
||||||
list_name = f"{self.post_uri}-likes"
|
list_name = f"{self.post_uri}-likes"
|
||||||
existing = controller.search_buffer(list_name, account_name)
|
existing = controller.search_buffer(list_name, account_name)
|
||||||
|
|||||||
@@ -530,7 +530,7 @@ class BaseBuffer(base.Buffer):
|
|||||||
pub.sendMessage("execute-action", action="user_details")
|
pub.sendMessage("execute-action", action="user_details")
|
||||||
return
|
return
|
||||||
try:
|
try:
|
||||||
blueski_messages.viewPost(self.session, item)
|
blueski_messages.viewPost(self.session, item, controller=getattr(self, "controller", None))
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
log.error("Error opening Bluesky post viewer: %s", e)
|
log.error("Error opening Bluesky post viewer: %s", e)
|
||||||
|
|
||||||
@@ -572,9 +572,8 @@ class BaseBuffer(base.Buffer):
|
|||||||
res = api.chat.bsky.convo.get_convo_for_members({"members": [did]})
|
res = api.chat.bsky.convo.get_convo_for_members({"members": [did]})
|
||||||
convo_id = res.convo.id
|
convo_id = res.convo.id
|
||||||
|
|
||||||
import application
|
|
||||||
title = _("Chat: {0}").format(handle)
|
title = _("Chat: {0}").format(handle)
|
||||||
application.app.controller.create_buffer(
|
self.controller.create_buffer(
|
||||||
buffer_type="chat_messages",
|
buffer_type="chat_messages",
|
||||||
session_type="blueski",
|
session_type="blueski",
|
||||||
buffer_title=title,
|
buffer_title=title,
|
||||||
@@ -830,9 +829,8 @@ class BaseBuffer(base.Buffer):
|
|||||||
uri = item.get("uri") if isinstance(item, dict) else getattr(item, "uri", None)
|
uri = item.get("uri") if isinstance(item, dict) else getattr(item, "uri", None)
|
||||||
if not uri: return
|
if not uri: return
|
||||||
|
|
||||||
import application
|
controller = self.controller
|
||||||
controller = application.app.controller
|
|
||||||
|
|
||||||
details = self.get_selected_item_author_details()
|
details = self.get_selected_item_author_details()
|
||||||
handle = "Unknown"
|
handle = "Unknown"
|
||||||
if details:
|
if details:
|
||||||
|
|||||||
@@ -167,8 +167,7 @@ class ConversationListBuffer(BaseBuffer):
|
|||||||
user_handle = getattr(profile, "handle", None) or (profile.get("handle") if isinstance(profile, dict) else None) or handle
|
user_handle = getattr(profile, "handle", None) or (profile.get("handle") if isinstance(profile, dict) else None) or handle
|
||||||
title = _("Chat: {0}").format(user_handle)
|
title = _("Chat: {0}").format(user_handle)
|
||||||
# Create the buffer under direct_messages node
|
# Create the buffer under direct_messages node
|
||||||
import application
|
wx.CallAfter(self._create_chat_buffer, self.controller, title, convo_id)
|
||||||
wx.CallAfter(self._create_chat_buffer, application.app.controller, title, convo_id)
|
|
||||||
# Refresh conversation list
|
# Refresh conversation list
|
||||||
wx.CallAfter(self.start_stream, True, False)
|
wx.CallAfter(self.start_stream, True, False)
|
||||||
except Exception:
|
except Exception:
|
||||||
@@ -340,8 +339,7 @@ class ConversationListBuffer(BaseBuffer):
|
|||||||
|
|
||||||
title = _("Chat: {0}").format(names)
|
title = _("Chat: {0}").format(names)
|
||||||
|
|
||||||
import application
|
self._create_chat_buffer(self.controller, title, convo_id)
|
||||||
self._create_chat_buffer(application.app.controller, title, convo_id)
|
|
||||||
|
|
||||||
def _create_chat_buffer(self, controller, title, convo_id):
|
def _create_chat_buffer(self, controller, title, convo_id):
|
||||||
"""Create a chat buffer under the direct_messages node, avoiding duplicates."""
|
"""Create a chat buffer under the direct_messages node, avoiding duplicates."""
|
||||||
|
|||||||
@@ -436,6 +436,7 @@ class Controller(object):
|
|||||||
kwargs["parent"] = self.view.nb # self.view.nb is the wx.Treebook
|
kwargs["parent"] = self.view.nb # self.view.nb is the wx.Treebook
|
||||||
|
|
||||||
buffer = buffer_panel_class(**kwargs) # This is the wx.Panel instance
|
buffer = buffer_panel_class(**kwargs) # This is the wx.Panel instance
|
||||||
|
buffer.controller = self
|
||||||
|
|
||||||
if start:
|
if start:
|
||||||
try:
|
try:
|
||||||
|
|||||||
Reference in New Issue
Block a user