feat: log presence, read receipts, group leaves, links, profiles, stories

This commit is contained in:
h
2026-05-29 22:13:59 +02:00
parent bfd16ab02c
commit bcb94b6474
31 changed files with 1298 additions and 19 deletions
+176
View File
@@ -234,3 +234,179 @@ class CapturePolicy(SQLModel, table=True):
onupdate=func.now(),
)
)
class Presence(SQLModel, table=True):
__tablename__ = "presence"
account_id: int = Field(primary_key=True)
peer_id: int = Field(sa_column=Column(BigInteger, primary_key=True))
ts: datetime = Field(sa_column=Column(DateTime(timezone=True), primary_key=True))
status: str
last_online_date: datetime | None = Field(
default=None, sa_column=Column(DateTime(timezone=True))
)
next_offline_date: datetime | None = Field(
default=None, sa_column=Column(DateTime(timezone=True))
)
raw: dict[str, Any] = Field(
default_factory=dict, sa_column=Column(JSONB, nullable=False)
)
class ReadReceipt(SQLModel, table=True):
__tablename__ = "read_receipts"
account_id: int = Field(primary_key=True)
chat_id: int = Field(sa_column=Column(BigInteger, primary_key=True))
message_id: int = Field(sa_column=Column(BigInteger, primary_key=True))
ts: datetime = Field(sa_column=Column(DateTime(timezone=True), primary_key=True))
reader_id: int = Field(sa_column=Column(BigInteger, nullable=False))
kind: str
raw: dict[str, Any] = Field(
default_factory=dict, sa_column=Column(JSONB, nullable=False)
)
class Peer(SQLModel, table=True):
__tablename__ = "peers"
account_id: int = Field(primary_key=True)
peer_id: int = Field(sa_column=Column(BigInteger, primary_key=True))
first_name: str | None = None
last_name: str | None = None
username: str | None = None
phone: str | None = None
photo_unique_id: str | None = None
is_deleted_account: bool = False
raw: dict[str, Any] = Field(
default_factory=dict, sa_column=Column(JSONB, nullable=False)
)
updated_at: datetime = Field(
sa_column=Column(
DateTime(timezone=True),
nullable=False,
server_default=func.now(),
onupdate=func.now(),
)
)
class PeerHistory(SQLModel, table=True):
__tablename__ = "peer_history"
account_id: int = Field(primary_key=True)
peer_id: int = Field(sa_column=Column(BigInteger, primary_key=True))
observed_at: datetime = Field(
sa_column=Column(DateTime(timezone=True), primary_key=True)
)
first_name: str | None = None
last_name: str | None = None
username: str | None = None
phone: str | None = None
photo_unique_id: str | None = None
is_deleted_account: bool = False
raw: dict[str, Any] = Field(
default_factory=dict, sa_column=Column(JSONB, nullable=False)
)
class Avatar(SQLModel, table=True):
__tablename__ = "avatars"
id: int | None = Field(default=None, primary_key=True)
account_id: int
owner_id: int = Field(sa_column=Column(BigInteger, nullable=False))
owner_kind: str
unique_id: str
storage_key: str | None = None
file_size: int | None = Field(default=None, sa_column=Column(BigInteger))
mime: str | None = None
downloaded: bool = False
raw: dict[str, Any] = Field(
default_factory=dict, sa_column=Column(JSONB, nullable=False)
)
first_seen_at: datetime = Field(
sa_column=Column(
DateTime(timezone=True), nullable=False, server_default=func.now()
)
)
class ChatHistory(SQLModel, table=True):
__tablename__ = "chat_history"
account_id: int = Field(primary_key=True)
chat_id: int = Field(sa_column=Column(BigInteger, primary_key=True))
message_id: int = Field(sa_column=Column(BigInteger, primary_key=True))
event: str
title: str | None = None
photo_unique_id: str | None = None
actor_id: int | None = Field(default=None, sa_column=Column(BigInteger))
ts: datetime = Field(sa_column=Column(DateTime(timezone=True), nullable=False))
raw: dict[str, Any] = Field(
default_factory=dict, sa_column=Column(JSONB, nullable=False)
)
class Membership(SQLModel, table=True):
__tablename__ = "memberships"
account_id: int = Field(primary_key=True)
chat_id: int = Field(sa_column=Column(BigInteger, primary_key=True))
message_id: int = Field(sa_column=Column(BigInteger, primary_key=True))
user_id: int = Field(sa_column=Column(BigInteger, primary_key=True))
event: str
actor_id: int | None = Field(default=None, sa_column=Column(BigInteger))
ts: datetime = Field(sa_column=Column(DateTime(timezone=True), nullable=False))
raw: dict[str, Any] = Field(
default_factory=dict, sa_column=Column(JSONB, nullable=False)
)
class Story(SQLModel, table=True):
__tablename__ = "stories"
account_id: int = Field(primary_key=True)
peer_id: int = Field(sa_column=Column(BigInteger, primary_key=True))
story_id: int = Field(sa_column=Column(BigInteger, primary_key=True))
date: datetime | None = Field(
default=None, sa_column=Column(DateTime(timezone=True))
)
expire_date: datetime | None = Field(
default=None, sa_column=Column(DateTime(timezone=True))
)
caption: str | None = None
media_kind: str | None = None
storage_key: str | None = None
file_size: int | None = Field(default=None, sa_column=Column(BigInteger))
downloaded: bool = False
views: int | None = None
pinned: bool = False
deleted: bool = False
raw: dict[str, Any] = Field(
default_factory=dict, sa_column=Column(JSONB, nullable=False)
)
observed_at: datetime = Field(
sa_column=Column(
DateTime(timezone=True), nullable=False, server_default=func.now()
)
)
class Link(SQLModel, table=True):
__tablename__ = "links"
account_id: int = Field(primary_key=True)
chat_id: int = Field(sa_column=Column(BigInteger, primary_key=True))
message_id: int = Field(sa_column=Column(BigInteger, primary_key=True))
position: int = Field(primary_key=True)
url: str
kind: str
web_url: str | None = None
web_title: str | None = None
web_description: str | None = None
web_site_name: str | None = None
raw: dict[str, Any] = Field(
default_factory=dict, sa_column=Column(JSONB, nullable=False)
)