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}