from __future__ import annotations from yuxi.channel.extensions.imessage.targets import build_session_key from yuxi.channel.message.models import PeerKind from yuxi.channel.protocols import SessionResolution class IMessageSessionAdapter: def resolve_session(self, msg: object) -> SessionResolution: if hasattr(msg, "sender") and hasattr(msg.sender, "kind"): if msg.sender.kind == PeerKind.DIRECT: sender_id = msg.sender.id if hasattr(msg.sender, "id") else "unknown" return SessionResolution(kind="direct", conversation_id=sender_id) gid = "unknown" if hasattr(msg, "group") and msg.group: gid = msg.group.id or "unknown" return SessionResolution(kind="group", conversation_id=gid) def build_dm_session_key(self, account_id: str, handle: str) -> str: return build_session_key("imessage", account_id, "direct", handle) def build_group_session_key(self, account_id: str, chat_guid: str) -> str: return build_session_key("imessage", account_id, "group", chat_guid)