From 7b6a8ba57b0f7bd60c7bb8aa8c756abb08fee7ec Mon Sep 17 00:00:00 2001 From: Xamora Date: Mon, 27 Nov 2023 15:47:00 +0100 Subject: [PATCH] Minor Edit and clear one file --- frontend/consumers.py | 1 + frontend/static/js/views/Chat.js | 4 +++- frontend/templates/chat.html | 24 ------------------------ 3 files changed, 4 insertions(+), 25 deletions(-) delete mode 100644 frontend/templates/chat.html diff --git a/frontend/consumers.py b/frontend/consumers.py index f3e4e6e..a86a0c7 100644 --- a/frontend/consumers.py +++ b/frontend/consumers.py @@ -31,6 +31,7 @@ class ChatConsumer(WebsocketConsumer): self.send(text_data=json.dumps({ 'type':'chat', + 'username':self.scope["user"].pk, 'message':message })) diff --git a/frontend/static/js/views/Chat.js b/frontend/static/js/views/Chat.js index cbde8e7..c620d9c 100644 --- a/frontend/static/js/views/Chat.js +++ b/frontend/static/js/views/Chat.js @@ -14,8 +14,9 @@ export default class extends AbstractView { if (data.type === 'chat') { let messages = document.getElementById('messages') + let username = data.username === null ? "NoName" : data.username; messages.insertAdjacentHTML('beforeend', ` -

${data.message}

+

${username}: ${data.message}

`) } @@ -32,6 +33,7 @@ export default class extends AbstractView { })) form.reset() }) + } async getHtml() { diff --git a/frontend/templates/chat.html b/frontend/templates/chat.html deleted file mode 100644 index 39b695c..0000000 --- a/frontend/templates/chat.html +++ /dev/null @@ -1,24 +0,0 @@ - - - - - Chat - - -

Chat

- -
- -
- - -