73 lines
No EOL
1.7 KiB
Python
73 lines
No EOL
1.7 KiB
Python
from dataclasses import dataclass
|
|
from typing import Optional, List, Dict, Any
|
|
from enum import Enum
|
|
|
|
|
|
class NotificationType(Enum):
|
|
MENTION = "mention"
|
|
REPLY = "reply"
|
|
FOLLOW = "follow"
|
|
FAVOURITE = "favourite"
|
|
REBLOG = "reblog"
|
|
POLL = "poll"
|
|
OTHER = "other"
|
|
|
|
|
|
class Visibility(Enum):
|
|
PUBLIC = "public"
|
|
UNLISTED = "unlisted"
|
|
HOME = "home"
|
|
FOLLOWERS = "followers"
|
|
SPECIFIED = "specified"
|
|
DIRECT = "direct"
|
|
|
|
|
|
@dataclass
|
|
class FediverseUser:
|
|
"""Common user representation across Fediverse platforms"""
|
|
id: str
|
|
username: str
|
|
host: Optional[str] = None # None for local users
|
|
display_name: Optional[str] = None
|
|
|
|
@property
|
|
def full_handle(self) -> str:
|
|
"""Returns the full fediverse handle (@user@domain or @user for local)"""
|
|
if self.host:
|
|
return f"@{self.username}@{self.host}"
|
|
return f"@{self.username}"
|
|
|
|
|
|
@dataclass
|
|
class FediverseFile:
|
|
"""Common file/attachment representation"""
|
|
id: str
|
|
url: str
|
|
type: Optional[str] = None
|
|
name: Optional[str] = None
|
|
|
|
|
|
@dataclass
|
|
class FediversePost:
|
|
"""Common post representation across Fediverse platforms"""
|
|
id: str
|
|
text: Optional[str]
|
|
user: FediverseUser
|
|
visibility: Visibility
|
|
created_at: Optional[str] = None
|
|
files: List[FediverseFile] = None
|
|
reply_to_id: Optional[str] = None
|
|
|
|
def __post_init__(self):
|
|
if self.files is None:
|
|
self.files = []
|
|
|
|
|
|
@dataclass
|
|
class FediverseNotification:
|
|
"""Common notification representation across Fediverse platforms"""
|
|
id: str
|
|
type: NotificationType
|
|
user: FediverseUser
|
|
post: Optional[FediversePost] = None
|
|
created_at: Optional[str] = None |