Fix post ownership detection for local posts to enable edit functionality
- Fixed ownership detection logic to handle both local and federated post formats - Local posts have acct="username" while federated posts have acct="username@instance.com" - Updated logic in both timeline_view.py and post_actions_manager.py for consistency - Removed duplicate keyboard shortcut from context menu to prevent conflicts - Added debug logging to help troubleshoot ownership detection - Edit functionality now works correctly for user's own posts 🤖 Generated with [Claude Code](https://claude.ai/code) Co-Authored-By: Claude <noreply@anthropic.com>
This commit is contained in:
@@ -154,11 +154,19 @@ class PostActionsManager(QObject):
|
|||||||
return False
|
return False
|
||||||
|
|
||||||
# Check if this is user's own post
|
# Check if this is user's own post
|
||||||
is_own_post = (
|
username_match = post.account.username == active_account.username
|
||||||
post.account.username == active_account.username
|
active_instance = active_account.instance_url.replace("https://", "").replace("http://", "")
|
||||||
and post.account.acct.split("@")[-1]
|
|
||||||
== active_account.instance_url.replace("https://", "").replace("http://", "")
|
# Handle both local and federated post formats
|
||||||
)
|
if "@" in post.account.acct:
|
||||||
|
# Federated post: acct is "username@instance.com"
|
||||||
|
post_instance = post.account.acct.split("@")[-1]
|
||||||
|
instance_match = post_instance == active_instance
|
||||||
|
else:
|
||||||
|
# Local post: acct is just "username", assume same instance
|
||||||
|
instance_match = True
|
||||||
|
|
||||||
|
is_own_post = username_match and instance_match
|
||||||
|
|
||||||
if not is_own_post:
|
if not is_own_post:
|
||||||
self.action_failed.emit("delete", "Cannot delete: Not your post")
|
self.action_failed.emit("delete", "Cannot delete: Not your post")
|
||||||
@@ -203,11 +211,19 @@ class PostActionsManager(QObject):
|
|||||||
return False
|
return False
|
||||||
|
|
||||||
# Don't allow blocking yourself
|
# Don't allow blocking yourself
|
||||||
is_own_post = (
|
username_match = post.account.username == active_account.username
|
||||||
post.account.username == active_account.username
|
active_instance = active_account.instance_url.replace("https://", "").replace("http://", "")
|
||||||
and post.account.acct.split("@")[-1]
|
|
||||||
== active_account.instance_url.replace("https://", "").replace("http://", "")
|
# Handle both local and federated post formats
|
||||||
)
|
if "@" in post.account.acct:
|
||||||
|
# Federated post: acct is "username@instance.com"
|
||||||
|
post_instance = post.account.acct.split("@")[-1]
|
||||||
|
instance_match = post_instance == active_instance
|
||||||
|
else:
|
||||||
|
# Local post: acct is just "username", assume same instance
|
||||||
|
instance_match = True
|
||||||
|
|
||||||
|
is_own_post = username_match and instance_match
|
||||||
|
|
||||||
if is_own_post:
|
if is_own_post:
|
||||||
self.action_failed.emit("block", "Cannot block yourself")
|
self.action_failed.emit("block", "Cannot block yourself")
|
||||||
@@ -258,11 +274,19 @@ class PostActionsManager(QObject):
|
|||||||
return False
|
return False
|
||||||
|
|
||||||
# Don't allow muting yourself
|
# Don't allow muting yourself
|
||||||
is_own_post = (
|
username_match = post.account.username == active_account.username
|
||||||
post.account.username == active_account.username
|
active_instance = active_account.instance_url.replace("https://", "").replace("http://", "")
|
||||||
and post.account.acct.split("@")[-1]
|
|
||||||
== active_account.instance_url.replace("https://", "").replace("http://", "")
|
# Handle both local and federated post formats
|
||||||
)
|
if "@" in post.account.acct:
|
||||||
|
# Federated post: acct is "username@instance.com"
|
||||||
|
post_instance = post.account.acct.split("@")[-1]
|
||||||
|
instance_match = post_instance == active_instance
|
||||||
|
else:
|
||||||
|
# Local post: acct is just "username", assume same instance
|
||||||
|
instance_match = True
|
||||||
|
|
||||||
|
is_own_post = username_match and instance_match
|
||||||
|
|
||||||
if is_own_post:
|
if is_own_post:
|
||||||
self.action_failed.emit("mute", "Cannot mute yourself")
|
self.action_failed.emit("mute", "Cannot mute yourself")
|
||||||
@@ -298,11 +322,19 @@ class PostActionsManager(QObject):
|
|||||||
return False
|
return False
|
||||||
|
|
||||||
# Check if this is user's own post
|
# Check if this is user's own post
|
||||||
is_own_post = (
|
username_match = post.account.username == active_account.username
|
||||||
post.account.username == active_account.username
|
active_instance = active_account.instance_url.replace("https://", "").replace("http://", "")
|
||||||
and post.account.acct.split("@")[-1]
|
|
||||||
== active_account.instance_url.replace("https://", "").replace("http://", "")
|
# Handle both local and federated post formats
|
||||||
)
|
if "@" in post.account.acct:
|
||||||
|
# Federated post: acct is "username@instance.com"
|
||||||
|
post_instance = post.account.acct.split("@")[-1]
|
||||||
|
instance_match = post_instance == active_instance
|
||||||
|
else:
|
||||||
|
# Local post: acct is just "username", assume same instance
|
||||||
|
instance_match = True
|
||||||
|
|
||||||
|
is_own_post = username_match and instance_match
|
||||||
|
|
||||||
if not is_own_post:
|
if not is_own_post:
|
||||||
self.action_failed.emit("edit", "Cannot edit: Not your post")
|
self.action_failed.emit("edit", "Cannot edit: Not your post")
|
||||||
|
|||||||
@@ -1411,14 +1411,31 @@ class TimelineView(QTreeWidget):
|
|||||||
active_account = self.account_manager.get_active_account()
|
active_account = self.account_manager.get_active_account()
|
||||||
is_own_post = False
|
is_own_post = False
|
||||||
if active_account and hasattr(post, "account"):
|
if active_account and hasattr(post, "account"):
|
||||||
|
# Debug logging for ownership detection
|
||||||
|
post_username = post.account.username
|
||||||
|
post_acct = post.account.acct
|
||||||
|
active_username = active_account.username
|
||||||
|
active_instance = active_account.instance_url.replace("https://", "").replace("http://", "")
|
||||||
|
post_instance = post_acct.split("@")[-1]
|
||||||
|
|
||||||
|
self.logger.debug(f"Ownership check: post.username='{post_username}', active.username='{active_username}'")
|
||||||
|
self.logger.debug(f"Ownership check: post.acct='{post_acct}', post_instance='{post_instance}', active_instance='{active_instance}'")
|
||||||
|
|
||||||
# Check if this is user's own post
|
# Check if this is user's own post
|
||||||
is_own_post = (
|
username_match = post.account.username == active_account.username
|
||||||
post.account.username == active_account.username
|
|
||||||
and post.account.acct.split("@")[-1]
|
# Handle both local and federated post formats
|
||||||
== active_account.instance_url.replace("https://", "").replace(
|
if "@" in post.account.acct:
|
||||||
"http://", ""
|
# Federated post: acct is "username@instance.com"
|
||||||
)
|
post_instance = post.account.acct.split("@")[-1]
|
||||||
)
|
instance_match = post_instance == active_instance
|
||||||
|
else:
|
||||||
|
# Local post: acct is just "username", assume same instance
|
||||||
|
instance_match = True
|
||||||
|
|
||||||
|
is_own_post = username_match and instance_match
|
||||||
|
|
||||||
|
self.logger.debug(f"Ownership check result: is_own_post={is_own_post}")
|
||||||
|
|
||||||
# Copy to clipboard action
|
# Copy to clipboard action
|
||||||
copy_action = QAction("&Copy to Clipboard", self)
|
copy_action = QAction("&Copy to Clipboard", self)
|
||||||
@@ -1463,9 +1480,8 @@ class TimelineView(QTreeWidget):
|
|||||||
if is_own_post:
|
if is_own_post:
|
||||||
menu.addSeparator()
|
menu.addSeparator()
|
||||||
|
|
||||||
# Edit action
|
# Edit action (no shortcut here - global shortcut in main window)
|
||||||
edit_action = QAction("&Edit Post", self)
|
edit_action = QAction("&Edit Post", self)
|
||||||
edit_action.setShortcut("Ctrl+Shift+E")
|
|
||||||
edit_action.triggered.connect(lambda: self.edit_requested.emit(post))
|
edit_action.triggered.connect(lambda: self.edit_requested.emit(post))
|
||||||
menu.addAction(edit_action)
|
menu.addAction(edit_action)
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user