Automated Action 41bbd8c182 Build comprehensive real-time chat API with advanced features
Complete rewrite from task management to full-featured chat system:

Core Features:
- Real-time WebSocket messaging with connection management
- Direct messages and group chats with admin controls
- Message types: text, images, videos, audio, documents
- Message status tracking: sent, delivered, read receipts
- Typing indicators and user presence (online/offline)
- Message replies, editing, and deletion

Security & Encryption:
- End-to-end encryption with RSA + AES hybrid approach
- JWT authentication for API and WebSocket connections
- Secure file storage with access control
- Automatic RSA key pair generation per user

Media & File Sharing:
- Multi-format file upload (images, videos, audio, documents)
- Automatic thumbnail generation for images/videos
- File size validation and MIME type checking
- Secure download endpoints with permission checks

Notifications & Alerts:
- Real-time WebSocket notifications
- Push notifications via Firebase integration
- @username mention alerts with notification history
- Unread message and mention counting
- Custom notification types (message, mention, group invite)

Advanced Features:
- Group chat management with roles (member, admin, owner)
- User search and chat member management
- Message pagination and chat history
- Last seen timestamps and activity tracking
- Comprehensive API documentation with WebSocket events

Architecture:
- Clean layered architecture with services, models, schemas
- WebSocket connection manager for real-time features
- Modular notification system with multiple channels
- Comprehensive error handling and validation
- Production-ready with Docker support

Technologies: FastAPI, WebSocket, SQLAlchemy, SQLite, Cryptography, Firebase, Pillow
2025-06-21 16:49:25 +00:00

75 lines
1.8 KiB
Python

from typing import Optional, List
from pydantic import BaseModel
from datetime import datetime
from app.models.chat import ChatType
from app.models.chat_member import MemberRole
from app.schemas.user import UserPublic
class ChatBase(BaseModel):
name: Optional[str] = None
description: Optional[str] = None
chat_type: ChatType
avatar_url: Optional[str] = None
class ChatCreate(ChatBase):
member_ids: List[int] = [] # For group chats
class DirectChatCreate(BaseModel):
other_user_id: int
class ChatUpdate(BaseModel):
name: Optional[str] = None
description: Optional[str] = None
avatar_url: Optional[str] = None
class ChatMemberBase(BaseModel):
user_id: int
role: MemberRole = MemberRole.MEMBER
nickname: Optional[str] = None
class ChatMemberCreate(ChatMemberBase):
pass
class ChatMemberUpdate(BaseModel):
role: Optional[MemberRole] = None
nickname: Optional[str] = None
is_muted: Optional[bool] = None
class ChatMember(ChatMemberBase):
id: int
chat_id: int
is_muted: bool = False
is_banned: bool = False
joined_at: datetime
last_read_message_id: Optional[int] = None
user: UserPublic
class Config:
from_attributes = True
class ChatInDBBase(ChatBase):
id: int
is_active: bool = True
created_at: datetime
updated_at: Optional[datetime] = None
class Config:
from_attributes = True
class Chat(ChatInDBBase):
members: List[ChatMember] = []
last_message: Optional[dict] = None
unread_count: int = 0
class ChatList(BaseModel):
id: int
name: Optional[str] = None
chat_type: ChatType
avatar_url: Optional[str] = None
last_message: Optional[dict] = None
last_activity: Optional[datetime] = None
unread_count: int = 0
is_online: bool = False # For direct chats
class Config:
from_attributes = True