Django
- Fix live chat resquest
This commit is contained in:
@ -6,7 +6,7 @@
|
||||
# By: edbernar <edbernar@student.42angouleme. +#+ +:+ +#+ #
|
||||
# +#+#+#+#+#+ +#+ #
|
||||
# Created: 2024/08/04 13:44:11 by edbernar #+# #+# #
|
||||
# Updated: 2024/08/29 21:33:48 by tomoron ### ########.fr #
|
||||
# Updated: 2024/08/30 15:57:02 by edbernar ### ########.fr #
|
||||
# #
|
||||
# **************************************************************************** #
|
||||
|
||||
@ -26,7 +26,7 @@ def sendPrivateMessage(socket, content):
|
||||
dest = User.objects.filter(id=content["to"])
|
||||
if(not dest.exists()):
|
||||
socket.sendError("User not found", 9008)
|
||||
return;
|
||||
return
|
||||
user = User.objects.filter(id=socket.scope["session"]["id"])
|
||||
if(int(content["to"]) == user[0].id):
|
||||
socket.sendError("Invalid message sent", 9009)
|
||||
@ -41,8 +41,14 @@ def sendPrivateMessage(socket, content):
|
||||
"content": content["content"],
|
||||
"date": new_msg.date.strftime("%H:%M:%S %d/%m/%Y")
|
||||
}}
|
||||
if(content["to"] in socket.onlinePlayers):
|
||||
socket.onlinePlayers[content["to"]].send(text_data=json.dumps(jsonVar))
|
||||
socket.send(text_data=json.dumps(jsonVar))
|
||||
if(content["to"] in socket.onlinePlayers):
|
||||
jsonVar = {"type": "new_private_message", "content": {
|
||||
"from": new_msg.sender.id,
|
||||
"channel": new_msg.sender.id,
|
||||
"content": content["content"],
|
||||
"date": new_msg.date.strftime("%H:%M:%S %d/%m/%Y")
|
||||
}}
|
||||
socket.onlinePlayers[content["to"]].send(text_data=json.dumps(jsonVar))
|
||||
except Exception as e:
|
||||
socket.sendError("Invalid message sent", 9009, e)
|
||||
|
@ -5,3 +5,15 @@ INSERT INTO "server_user" ("username", "mail", "password", "id42", "pfp") VALUES
|
||||
INSERT INTO "server_message" ("date", "sender_id", "to_id", "content") VALUES
|
||||
('2024-08-25 18:10:54.27476+00', 1, 2, 'coucou'),
|
||||
('2024-08-25 18:11:25.987857+00', 2, 1, 'coucou les musulmans moi je mange la glace');
|
||||
|
||||
INSERT INTO "server_message" ("date", "sender_id", "to_id", "content") VALUES
|
||||
('2024-08-25 18:10:54.27476+00', 3, 2, 'bonsoir'),
|
||||
('2024-08-25 18:11:25.987857+00', 2, 3, 'non');
|
||||
|
||||
INSERT INTO "server_message" ("date", "sender_id", "to_id", "content") VALUES
|
||||
('2024-08-25 18:10:54.27476+00', 1, 3, 'bonsoir3'),
|
||||
('2024-08-25 18:11:25.987857+00', 3, 1, 'non3');
|
||||
|
||||
INSERT INTO "server_message" ("date", "sender_id", "to_id", "content") VALUES
|
||||
('2024-08-25 18:10:54.27476+00', 4, 3, 'bonsoir3'),
|
||||
('2024-08-25 18:11:25.987857+00', 3, 4, 'non3');
|
Reference in New Issue
Block a user