47 lines
1.2 KiB
Python
47 lines
1.2 KiB
Python
|
|
from __future__ import annotations
|
||
|
|
|
||
|
|
from dataclasses import dataclass
|
||
|
|
|
||
|
|
from yuxi.channels.models import ChatType
|
||
|
|
from yuxi.channels.adapters.signal.normalize import normalize_target
|
||
|
|
|
||
|
|
|
||
|
|
@dataclass
|
||
|
|
class OutboundSession:
|
||
|
|
peer: str
|
||
|
|
chat_type: ChatType
|
||
|
|
from_: str
|
||
|
|
to: str
|
||
|
|
|
||
|
|
@classmethod
|
||
|
|
def resolve(cls, target: str, account_number: str) -> OutboundSession:
|
||
|
|
normalized = normalize_target(target)
|
||
|
|
if normalized.startswith("group:"):
|
||
|
|
return cls(
|
||
|
|
peer=normalized,
|
||
|
|
chat_type=ChatType.GROUP,
|
||
|
|
from_=account_number,
|
||
|
|
to=normalized,
|
||
|
|
)
|
||
|
|
if normalized.startswith("uuid:"):
|
||
|
|
return cls(
|
||
|
|
peer=normalized,
|
||
|
|
chat_type=ChatType.DIRECT,
|
||
|
|
from_=account_number,
|
||
|
|
to=normalized,
|
||
|
|
)
|
||
|
|
return cls(
|
||
|
|
peer=normalized,
|
||
|
|
chat_type=ChatType.DIRECT,
|
||
|
|
from_=account_number,
|
||
|
|
to=normalized,
|
||
|
|
)
|
||
|
|
|
||
|
|
@property
|
||
|
|
def is_group(self) -> bool:
|
||
|
|
return self.chat_type == ChatType.GROUP
|
||
|
|
|
||
|
|
@property
|
||
|
|
def conversation_id(self) -> str:
|
||
|
|
return self.peer
|