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:
Storm Dragon
2025-08-16 15:40:02 -04:00
parent 86c0d0442a
commit 643f5cc4f5
2 changed files with 77 additions and 29 deletions

View File

@@ -154,11 +154,19 @@ class PostActionsManager(QObject):
return False
# Check if this is user's own post
is_own_post = (
post.account.username == active_account.username
and post.account.acct.split("@")[-1]
== active_account.instance_url.replace("https://", "").replace("http://", "")
)
username_match = post.account.username == active_account.username
active_instance = 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:
self.action_failed.emit("delete", "Cannot delete: Not your post")
@@ -203,11 +211,19 @@ class PostActionsManager(QObject):
return False
# Don't allow blocking yourself
is_own_post = (
post.account.username == active_account.username
and post.account.acct.split("@")[-1]
== active_account.instance_url.replace("https://", "").replace("http://", "")
)
username_match = post.account.username == active_account.username
active_instance = 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:
self.action_failed.emit("block", "Cannot block yourself")
@@ -258,11 +274,19 @@ class PostActionsManager(QObject):
return False
# Don't allow muting yourself
is_own_post = (
post.account.username == active_account.username
and post.account.acct.split("@")[-1]
== active_account.instance_url.replace("https://", "").replace("http://", "")
)
username_match = post.account.username == active_account.username
active_instance = 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:
self.action_failed.emit("mute", "Cannot mute yourself")
@@ -298,11 +322,19 @@ class PostActionsManager(QObject):
return False
# Check if this is user's own post
is_own_post = (
post.account.username == active_account.username
and post.account.acct.split("@")[-1]
== active_account.instance_url.replace("https://", "").replace("http://", "")
)
username_match = post.account.username == active_account.username
active_instance = 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:
self.action_failed.emit("edit", "Cannot edit: Not your post")

View File

@@ -1411,14 +1411,31 @@ class TimelineView(QTreeWidget):
active_account = self.account_manager.get_active_account()
is_own_post = False
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
is_own_post = (
post.account.username == active_account.username
and post.account.acct.split("@")[-1]
== active_account.instance_url.replace("https://", "").replace(
"http://", ""
)
)
username_match = post.account.username == active_account.username
# 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
self.logger.debug(f"Ownership check result: is_own_post={is_own_post}")
# Copy to clipboard action
copy_action = QAction("&Copy to Clipboard", self)
@@ -1463,9 +1480,8 @@ class TimelineView(QTreeWidget):
if is_own_post:
menu.addSeparator()
# Edit action
# Edit action (no shortcut here - global shortcut in main window)
edit_action = QAction("&Edit Post", self)
edit_action.setShortcut("Ctrl+Shift+E")
edit_action.triggered.connect(lambda: self.edit_requested.emit(post))
menu.addAction(edit_action)