Created new chat table in scheme.sql, Added chat.py with 3 methods (incomplete)

This commit is contained in:
white
2025-01-23 13:10:22 +00:00
parent 233e2df781
commit 33111ea077
3 changed files with 75 additions and 12 deletions

View File

@@ -0,0 +1,48 @@
from flask import Blueprint
from blueprints.utils import login_required
from database.database import Database
chat_bp = Blueprint("chat", __name__)
@login_required
def chat():
"""
Works with react, takes the chat entered by a logged in user and stores in database
"""
return {}
def get_all_chat():
"""
Returns a dictionary to be passed to the server.
Output structure in the following format: `{(chatter, message), ...}` for all chats.
Rans once when a user first logs into a stream
"""
# Connect to the database
db = Database()
cursor = db.create_connection()
# Returns list of tuples: (chatter_id, message)
all_chats = cursor.execute("""SELECT ?, ? FROM chat
ORDER BY ?;""", ("chatter_id", "message", "time_sent")).fetchall()
# Create JSON output of chat_history to pass through NGINX proxy
chat_history = {}
for chat in all_chats:
chat_history[chat[0]] = chat[1]
# Pass the chat history to the proxy
return chat_history
def get_recent_chat():
"""
Run periodically to return new chat messages on a stream a user has already loaded in to.
"""
return {}