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');
|
@ -6,7 +6,7 @@
|
||||
/* By: edbernar <edbernar@student.42angouleme. +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2024/08/04 19:21:10 by edbernar #+# #+# */
|
||||
/* Updated: 2024/08/26 15:57:20 by edbernar ### ########.fr */
|
||||
/* Updated: 2024/08/30 16:36:37 by edbernar ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
|
@ -6,7 +6,7 @@
|
||||
/* By: edbernar <edbernar@student.42angouleme. +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2024/08/04 15:15:49 by edbernar #+# #+# */
|
||||
/* Updated: 2024/08/24 23:45:05 by edbernar ### ########.fr */
|
||||
/* Updated: 2024/08/30 15:47:44 by edbernar ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
@ -16,6 +16,7 @@ import { userMeInfo } from "/static/javascript/typeResponse/typeLogin.js";
|
||||
|
||||
function typeNewPrivateMessage(content)
|
||||
{
|
||||
console.log(content);
|
||||
messageList.push(content);
|
||||
if (infoPanel.isOpen && infoPanel.id === content.channel)
|
||||
{
|
||||
|
@ -6,7 +6,7 @@
|
||||
/* By: edbernar <edbernar@student.42angouleme. +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2024/08/02 01:56:15 by edbernar #+# #+# */
|
||||
/* Updated: 2024/08/03 14:36:20 by edbernar ### ########.fr */
|
||||
/* Updated: 2024/08/30 16:34:29 by edbernar ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
@ -28,7 +28,7 @@ function typePrivateListUser(list) {
|
||||
userListAvailable = true;
|
||||
if (userListResolve)
|
||||
{
|
||||
userListResolve();
|
||||
userListResolve(userList);
|
||||
userListResolve = null;
|
||||
}
|
||||
}
|
||||
|
@ -6,7 +6,7 @@
|
||||
/* By: edbernar <edbernar@student.42angouleme. +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2024/07/31 22:17:24 by edbernar #+# #+# */
|
||||
/* Updated: 2024/08/26 14:48:48 by edbernar ### ########.fr */
|
||||
/* Updated: 2024/08/30 15:42:51 by edbernar ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
@ -52,6 +52,7 @@ socket.onmessage = (event) => {
|
||||
}
|
||||
else
|
||||
{
|
||||
console.log(response);
|
||||
try {
|
||||
functionResponse[typeResponse.indexOf(response.type)](response.content);
|
||||
} catch {
|
||||
|
Reference in New Issue
Block a user