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

64 lines
1.5 KiB
Python

from typing import Optional, List
from pydantic import BaseModel
from datetime import datetime
from app.models.message import MessageType, MessageStatus
class MessageBase(BaseModel):
content: Optional[str] = None
content_type: MessageType = MessageType.TEXT
reply_to_id: Optional[int] = None
class MessageCreate(MessageBase):
chat_id: int
class MessageUpdate(BaseModel):
content: Optional[str] = None
class MediaFile(BaseModel):
id: int
filename: str
original_filename: str
file_size: int
mime_type: str
media_type: str
width: Optional[int] = None
height: Optional[int] = None
duration: Optional[int] = None
thumbnail_url: Optional[str] = None
class Config:
from_attributes = True
class MessageMention(BaseModel):
id: int
username: str
full_name: Optional[str] = None
class MessageInDBBase(MessageBase):
id: int
chat_id: int
sender_id: int
status: MessageStatus
is_edited: bool = False
is_deleted: bool = False
edited_at: Optional[datetime] = None
created_at: datetime
class Config:
from_attributes = True
class Message(MessageInDBBase):
sender_username: str
sender_avatar: Optional[str] = None
media_files: List[MediaFile] = []
mentions: List[MessageMention] = []
reply_to: Optional['Message'] = None
class MessageList(BaseModel):
messages: List[Message]
total: int
page: int
has_more: bool
# Enable forward references
Message.model_rebuild()