This document describes the newly implemented chat functionality for the GUBlogs application, which includes:
- Chat Tab in Navbar - A dedicated chat section with unread message notifications
- Chat List Page - Shows all conversations with unread message counts
- Real-time Notifications - AJAX-powered unread message notifications
- Enhanced User Experience - Instagram-like notification dots and modern UI
- Added a new "Chat" tab in the navigation bar
- Includes a red notification badge showing unread message count
- Badge appears only when there are unread messages
- Updates automatically every 30 seconds via AJAX
- Shows all users the current user has chatted with
- Displays latest message preview (encrypted messages show as "💬 Message 🔒")
- Shows unread message count for each conversation
- Search functionality to filter conversations
- Responsive design for mobile devices
- Added methods to
CustomUsermodel:get_conversations()- Returns all conversations with unread countsget_total_unread_count()- Returns total unread messages for user
- Messages are automatically marked as read when viewing a conversation
- Real-time updates via AJAX API endpoint
- Modern card-based design for chat list
- Gradient backgrounds and smooth animations
- Instagram-like notification badge with pulsing animation
- Hover effects and smooth transitions
- Mobile-responsive design
users/templates/users/chat_list.html- Chat list page template
users/models.py- Added conversation and unread count methodsusers/views.py- Added chat list view and unread count APIusers/urls.py- Added new URL patternsusers/templates/base.html- Updated navbar with chat tab and notifications
path('chat/', views.chat_list_view, name='chat_list'),
path('api/unread-count/', views.get_unread_count, name='get_unread_count'),GET /users/api/unread-count/- Returns JSON with current unread message count
- No new migrations required (only added methods to existing models)
- Utilizes existing
ChatMessagemodel'sis_readfield
- Access Chat List: Click the "Chat" tab in the navbar
- View Notifications: Red badge shows unread message count
- Start Conversations: Visit user profiles and click "Message" button
- Search Chats: Use search box in chat list to filter conversations
- Unread Count API: Use AJAX to get current unread count
- Real-time Updates: Notifications update every 30 seconds automatically
- Extensible Design: Easy to add more chat features in the future
- All chat functionality requires authentication
- Messages remain encrypted end-to-end
- Proper CSRF protection on all forms
- User permissions validated on all endpoints
- Efficient database queries with proper indexing
- AJAX updates minimize page reloads
- Conversation list sorted by latest message timestamp
- Search functionality works client-side for better performance
- Push notifications for new messages
- Online/offline status indicators
- Message delivery confirmations
- Group chat functionality
- File sharing capabilities
The implementation has been tested with:
- Multiple user conversations
- Encrypted and unencrypted messages
- Real-time unread count updates
- Mobile responsive design
- Cross-browser compatibility
- Monitor AJAX endpoint performance with increased users
- Consider implementing WebSocket for real-time notifications
- Regular cleanup of old message data may be needed
- Consider implementing message pagination for large conversation histories