Some checks failed
CI / test (push) Failing after 19s
backend: - add unread_count to ChatRead serialization - compute unread_count per chat using message_receipts and hidden messages web: - add unread badges in chat list - track unread boundary per chat in store - show 'New messages' divider in message list - update realtime flow to increment/clear unread on incoming events
68 lines
1.5 KiB
Python
68 lines
1.5 KiB
Python
from datetime import datetime
|
|
|
|
from pydantic import BaseModel, ConfigDict, Field
|
|
|
|
from app.chats.models import ChatMemberRole, ChatType
|
|
|
|
|
|
class ChatRead(BaseModel):
|
|
model_config = ConfigDict(from_attributes=True)
|
|
|
|
id: int
|
|
type: ChatType
|
|
title: str | None = None
|
|
display_title: str | None = None
|
|
handle: str | None = None
|
|
description: str | None = None
|
|
is_public: bool = False
|
|
is_saved: bool = False
|
|
unread_count: int = 0
|
|
pinned_message_id: int | None = None
|
|
created_at: datetime
|
|
|
|
|
|
class ChatMemberRead(BaseModel):
|
|
model_config = ConfigDict(from_attributes=True)
|
|
|
|
id: int
|
|
user_id: int
|
|
role: ChatMemberRole
|
|
joined_at: datetime
|
|
|
|
|
|
class ChatDetailRead(ChatRead):
|
|
members: list[ChatMemberRead]
|
|
|
|
|
|
class ChatCreateRequest(BaseModel):
|
|
type: ChatType
|
|
title: str | None = Field(default=None, max_length=255)
|
|
handle: str | None = Field(default=None, max_length=64)
|
|
description: str | None = Field(default=None, max_length=512)
|
|
is_public: bool = False
|
|
member_ids: list[int] = Field(default_factory=list)
|
|
|
|
|
|
class ChatMemberAddRequest(BaseModel):
|
|
user_id: int
|
|
|
|
|
|
class ChatMemberRoleUpdateRequest(BaseModel):
|
|
role: ChatMemberRole
|
|
|
|
|
|
class ChatTitleUpdateRequest(BaseModel):
|
|
title: str = Field(min_length=1, max_length=255)
|
|
|
|
|
|
class ChatPinMessageRequest(BaseModel):
|
|
message_id: int | None = None
|
|
|
|
|
|
class ChatDeleteRequest(BaseModel):
|
|
for_all: bool = False
|
|
|
|
|
|
class ChatDiscoverRead(ChatRead):
|
|
is_member: bool
|