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

- -
- -
- - -