def handle_disconnection(): # handles disconnection from the server print("DISCONNECT") db = Database() msg = {"name": session[NAME_KEY], "message": " has left the chat"} db.insert_message(session[NAME_KEY], " has left the chat") result = db.get_messages_by_name(1, session[NAME_KEY]) result = trim_seconds_from_message(result) socketio.emit("message response", result)
def handle_event(json, methods=["GET", "POST"]): if len(json["name"]) >= 2: db = Database() db.insert_message(json["name"], json["message"]) result = db.get_messages_by_name( 1, json["name"] ) # getting the last message from the database( the one that was just inserted above) result = trim_seconds_from_message(result) socketio.emit("message response", result) # sending it back to the clients