Real-time group chat rooms with public and private options in Mirage
Mirage’s chat room feature enables real-time group conversations with support for both public and private rooms, password protection, and temporary message storage.
Discover and join existing chat rooms to participate in conversations.
Public Rooms
Private Rooms
Your Rooms
Browse the list of public rooms and join with a single click:
app/routes/chat.py:195-225
@chat_bp.route('/api/rooms', methods=['GET'])def list_rooms(): # Get all public rooms c.execute('SELECT id, name FROM rooms WHERE is_private=0') rooms = c.fetchall() # Check which rooms user is already in c.execute('SELECT room_id FROM room_members WHERE username=?', (user[0],)) user_rooms_set = {r[0] for r in c.fetchall()} data = [] for room_id, name in rooms: data.append({ 'room_id': room_id, 'name': name, 'joined': room_id in user_rooms_set })
Join private rooms using the room name and password:
app/routes/chat.py:103-109
# Verify password for private roomsif is_private: if not password: return jsonify({'error': 'password required'}), 403 if stored_hash != hash_pw(password): return jsonify({'error': 'wrong password'}), 403
Private room passwords are hashed before comparison for security
View all rooms you’re a member of:
app/routes/chat.py:252-281
@chat_bp.route('/api/user_rooms', methods=['GET'])def user_rooms(): # Get all rooms the user is a member of c.execute('''SELECT r.id, r.name, r.is_private FROM rooms r JOIN room_members rm ON r.id = rm.room_id WHERE rm.username=?''', (username,)) rooms = c.fetchall()
Participate in room conversations with real-time messaging.
Message Flow
Compose your message (text content)
System verifies you’re a room member
Message is stored in memory with timestamp
All room members can see the message instantly
Messages expire after the configured lifespan
app/routes/chat.py:126-167
@chat_bp.route('/api/send_room_message', methods=['POST'])def send_room_message(): data = request.get_json() token = request.headers.get('Authorization') room_id = data.get('room_id') message = data.get('message', '').strip() # Verify user is in the room c.execute('SELECT id FROM room_members WHERE room_id=? AND username=?', (room_id, user[0])) if not c.fetchone(): return jsonify({'error': 'you are not in this room'}), 403 # Create message with timestamp message_data = { 'username': user[0], 'message': message, 'created_at': time.time(), 'room_id': room_id } # Add to message queue messages.append(message_data) # Clean old messages (keep only recent ones) now = time.time() messages[:] = [m for m in messages if now - m['created_at'] < MESSAGE_LIFESPAN] if len(messages) > MAX_MESSAGES: messages.pop(0)
View the message history for any room you’re a member of.
app/routes/chat.py:169-193
@chat_bp.route('/api/get_room_messages', methods=['GET'])def get_room_messages(): token = request.headers.get('Authorization') room_id = request.args.get('room_id') # Verify user is in the room c.execute('SELECT id FROM room_members WHERE room_id=? AND username=?', (room_id, user[0])) if not c.fetchone(): return jsonify({'error': 'you are not in this room'}), 403 # Filter messages for this room filtered = [m for m in messages if str(m.get('room_id')) == str(room_id)] return jsonify({'messages': filtered}), 200
View who’s in a room and manage your room memberships.
View Members
See all current members of any room you’ve joined
app/routes/chat.py:227-250
@chat_bp.route('/api/room_members/<int:room_id>', methods=['GET'])def get_room_members(room_id): c.execute('SELECT username FROM room_members WHERE room_id=?', (room_id,)) members = c.fetchall() members_list = [m[0] for m in members] return jsonify({'members': members_list}), 200
Auto-Join on Create
Room creators are automatically added as the first member when the room is created
CREATE TABLE IF NOT EXISTS rooms ( id INTEGER PRIMARY KEY AUTOINCREMENT, name TEXT UNIQUE NOT NULL, is_private INTEGER DEFAULT 0, password_hash TEXT, created_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP)CREATE TABLE IF NOT EXISTS room_members ( id INTEGER PRIMARY KEY AUTOINCREMENT, room_id INTEGER NOT NULL, username TEXT NOT NULL, joined_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP, FOREIGN KEY(room_id) REFERENCES rooms(id), FOREIGN KEY(username) REFERENCES users(username))