Files
twblue/src/controller/blueski/userActions.py
T

76 lines
3.4 KiB
Python
Raw Normal View History

from __future__ import annotations
import logging
from typing import TYPE_CHECKING, Any
fromapprove.translation import translate as _
# fromapprove.controller.mastodon import userActions as mastodon_user_actions # If adapting
if TYPE_CHECKING:
2026-01-10 19:46:53 +01:00
fromapprove.sessions.blueski.session import Session as BlueskiSession # Adjusted
logger = logging.getLogger(__name__)
2026-01-10 19:46:53 +01:00
# This file defines user-specific actions that can be performed on Blueski entities,
# typically represented as buttons or links in the UI, often on user profiles or posts.
2026-01-10 19:46:53 +01:00
# For Blueski, actions might include:
# - Viewing a user's profile on Bluesky/Blueski instance.
# - Following/Unfollowing a user.
# - Muting/Blocking a user.
# - Reporting a user.
# - Fetching a user's latest posts.
# These actions are often presented in a context menu or as direct buttons.
2026-01-10 19:46:53 +01:00
# The `get_user_actions` method in the BlueskiSession class would define these.
# This file would contain the implementation or further handling logic if needed,
# or if actions are too complex for simple lambda/method calls in the session class.
# Example structure for defining an action:
# (This might be more detailed if actions require forms or multi-step processes)
2026-01-10 19:46:53 +01:00
# def view_profile_action(session: BlueskiSession, user_id: str) -> dict[str, Any]:
# """
2026-01-10 19:46:53 +01:00
# Generates data for a "View Profile on Blueski" action.
# user_id here would be the Blueski DID or handle.
# """
# # profile_url = f"https://bsky.app/profile/{user_id}" # Example, construct from handle or DID
# # This might involve resolving DID to handle or vice-versa if only one is known.
# # handle = await session.util.get_username_from_user_id(user_id) or user_id
# # profile_url = f"https://bsky.app/profile/{handle}"
# return {
2026-01-10 19:46:53 +01:00
# "id": "blueski_view_profile",
# "label": _("View Profile on Bluesky"),
# "icon": "external-link-alt", # FontAwesome icon name
# "action_type": "link", # "link", "modal", "api_call"
# "url": profile_url, # For "link" type
2026-01-10 19:46:53 +01:00
# # "api_endpoint": "/api/blueski/user_action", # For "api_call"
# # "payload": {"action": "view_profile", "target_user_id": user_id},
# "confirmation_required": False,
# }
2026-01-10 19:46:53 +01:00
# async def follow_user_action_handler(session: BlueskiSession, target_user_id: str) -> dict[str, Any]:
# """
2026-01-10 19:46:53 +01:00
# Handles the 'follow_user' action for Blueski.
# target_user_id should be the DID of the user to follow.
# """
# # success = await session.util.follow_user(target_user_id)
# # if success:
# # return {"status": "success", "message": _("User {target_user_id} followed.").format(target_user_id=target_user_id)}
# # else:
# # return {"status": "error", "message": _("Failed to follow user {target_user_id}.").format(target_user_id=target_user_id)}
# return {"status": "pending", "message": "Follow action not implemented yet."}
# The list of available actions is typically defined in the Session class,
2026-01-10 19:46:53 +01:00
# e.g., BlueskiSession.get_user_actions(). That method would return a list
# of dictionaries, and this file might provide handlers for more complex actions
# if they aren't simple API calls defined directly in the session's util.
# For now, this file can be a placeholder if most actions are simple enough
# to be handled directly by the session.util methods or basic handler routes.
2026-01-10 19:46:53 +01:00
logger.info("Blueski userActions module loaded (placeholders).")