Repository navigation
Messaging System
AutoBot Solutions edited this page Apr 29, 2026
·
1 revision
The messaging system provides private communication between users through direct messages. It includes inbox management, sent messages, and message composition with read status tracking.
Message Model (app/models.py)
class Message(db.Model):
id = db.Column(db.Integer, primary_key=True)
sender_id = db.Column(db.Integer, db.ForeignKey('user.id'), nullable=False)
receiver_id = db.Column(db.Integer, db.ForeignKey('user.id'), nullable=False)
content = db.Column(db.Text, nullable=False)
is_read = db.Column(db.Boolean, default=False)
created_at = db.Column(db.DateTime, default=datetime.utcnow)
sender = db.relationship('User', foreign_keys=[sender_id], backref='sent_messages')
receiver = db.relationship('User', foreign_keys=[receiver_id], backref='received_messages')MessageForm (app/message/forms.py)
- Receiver selection (dropdown)
- Content field
- Submit button
Inbox Route (/messages)
- Requires authentication
- Lists received messages
- Shows unread count
- Displays sender information
- Message preview
- Read/unread styling
- Actions: Read, Delete
Sent Route (/messages/sent)
- Requires authentication
- Lists sent messages
- Shows recipient information
- Message preview
- Actions: Delete
New Message Route (/messages/new)
- Requires authentication
- Method: GET, POST
- Receiver selection dropdown
- Message composition
- Creates message
- Flash confirmation
Read Message Route (/messages/<message_id>/read)
- Requires authentication
- Marks message as read
- Redirects to inbox
- Only receiver can mark as read
Delete Message Route (/messages/<message_id>/delete)
- Requires authentication
- Deletes message
- Sender or receiver can delete
- Flash confirmation
- Redirects to inbox
- Lists all received messages
- Shows unread count
- Sender information with profile link
- Message preview (200 characters)
- Timestamp
- Read/unread visual distinction
- Actions: Read, Delete
- Lists all sent messages
- Shows recipient information
- Message preview
- Timestamp
- Actions: Delete
- Select recipient from dropdown
- All users except self
- Message content
- No character limit
- Instant delivery
- Boolean flag
- Default: false (unread)
- Set to true when opened
- Used for unread count
- Only receiver can mark as read
- Foreign key to User
- Relationship: sent_messages
- Cannot send to self
- Profile link displayed
- Foreign key to User
- Relationship: received_messages
- Can receive from anyone
- Profile link displayed
- Plain text content
- No Markdown processing
- No character limit
- No HTML allowed
- Creation time
- Displayed in notifications
- Used for sorting
unread_count = current_user.received_messages.filter_by(is_read=False).count()- Shown in navbar
- Envelope icon
- Magenta color badge
- Glowing effect
- Hidden when zero unread
- Hero section with unread count
- New message button
- Sent messages button
- Message list
- Read/unread styling
- Action links
- Hero section
- Inbox button
- New message button
- Message list
- Message metadata
- Delete action
- Message composition form
- Receiver dropdown
- Content textarea
- Submit button
- Cancel link
- Dark card background
- Border glow
- Unread: Cyan border with glow
- Hover effects
- Smooth transitions
- Magenta color
- Profile link
- Hover effect to cyan
- Text shadow on hover
- Primary text color
- Preview (200 chars)
- Truncation indicator
- Readable font
- Cyan color for read
- Red color for delete
- Hover effects
- Transition animations
- Authentication required
- Users can only see their own messages
- Cannot send to self
- Sender/receiver validation
- Private between sender and receiver
- No public visibility
- Admin can view all messages (future audit)
- Message deletion is permanent
- Rate limiting (future)
- Spam detection (future)
- Block user feature (future)
- Report message feature (future)
- New message notification
- Unread message count in notifications
- Push notifications
- Sender profile links
- Receiver profile links
- User dropdown for composition
- Filter by user_id (sent or received)
- Filter by is_read
- Order by created_at DESC
- Lazy loading for efficiency
- Pagination for large lists
- Message archiving
- Indexed fields (sender_id, receiver_id, is_read)
- Message search
- Conversation threading
- Be respectful and professional
- Keep messages concise
- Use clear subject lines (future)
- Avoid spam
- Regularly check inbox
- Delete old messages
- Mark important messages as unread (future)
- Archive important conversations (future)
- Don't share sensitive information
- Remember messages can be deleted
- Admin may audit messages (future)
- Report inappropriate messages (future)
- Message threads/conversations
- Message search
- Message archiving
- Star/favorite messages
- Message drafts
- Rich text editing
- File attachments
- Message forwarding
- Reply quoting
- Message encryption
- Message expiration
- Message scheduling
- Block user
- Mute user
- Report message
- Spam detection
- Auto-moderation
- Message analytics
- Typing indicators
- Read receipts
- Message delivery status
- Group messaging
- Broadcast messages (admin)
- Email notifications
- Push notifications
- SMS notifications
- Desktop notifications
- Mobile app integration