From b12c03074af1d9ec0c66aa55e52d60bf862bb231 Mon Sep 17 00:00:00 2001 From: Xamora Date: Mon, 27 Nov 2023 23:31:31 +0100 Subject: [PATCH] Chat advance --- chat/__init__.py | 0 chat/admin.py | 3 +++ chat/apps.py | 6 ++++++ {frontend => chat}/consumers.py | 0 chat/models.py | 3 +++ {frontend => chat}/routing.py | 0 chat/tests.py | 3 +++ chat/views.py | 3 +++ frontend/static/js/views/Chat.js | 2 +- trancendence/asgi.py | 4 ++-- 10 files changed, 21 insertions(+), 3 deletions(-) create mode 100644 chat/__init__.py create mode 100644 chat/admin.py create mode 100644 chat/apps.py rename {frontend => chat}/consumers.py (100%) create mode 100644 chat/models.py rename {frontend => chat}/routing.py (100%) create mode 100644 chat/tests.py create mode 100644 chat/views.py diff --git a/chat/__init__.py b/chat/__init__.py new file mode 100644 index 0000000..e69de29 diff --git a/chat/admin.py b/chat/admin.py new file mode 100644 index 0000000..8c38f3f --- /dev/null +++ b/chat/admin.py @@ -0,0 +1,3 @@ +from django.contrib import admin + +# Register your models here. diff --git a/chat/apps.py b/chat/apps.py new file mode 100644 index 0000000..2fe899a --- /dev/null +++ b/chat/apps.py @@ -0,0 +1,6 @@ +from django.apps import AppConfig + + +class ChatConfig(AppConfig): + default_auto_field = 'django.db.models.BigAutoField' + name = 'chat' diff --git a/frontend/consumers.py b/chat/consumers.py similarity index 100% rename from frontend/consumers.py rename to chat/consumers.py diff --git a/chat/models.py b/chat/models.py new file mode 100644 index 0000000..71a8362 --- /dev/null +++ b/chat/models.py @@ -0,0 +1,3 @@ +from django.db import models + +# Create your models here. diff --git a/frontend/routing.py b/chat/routing.py similarity index 100% rename from frontend/routing.py rename to chat/routing.py diff --git a/chat/tests.py b/chat/tests.py new file mode 100644 index 0000000..7ce503c --- /dev/null +++ b/chat/tests.py @@ -0,0 +1,3 @@ +from django.test import TestCase + +# Create your tests here. diff --git a/chat/views.py b/chat/views.py new file mode 100644 index 0000000..91ea44a --- /dev/null +++ b/chat/views.py @@ -0,0 +1,3 @@ +from django.shortcuts import render + +# Create your views here. diff --git a/frontend/static/js/views/Chat.js b/frontend/static/js/views/Chat.js index 0f2b71d..7d071b3 100644 --- a/frontend/static/js/views/Chat.js +++ b/frontend/static/js/views/Chat.js @@ -14,7 +14,7 @@ export default class extends AbstractView { if (data.type === 'chat') { let messages = document.getElementById('messages') - let username = data.username === null ? "NoName" : data.username; + let username = data.username === null || data.username.length <= 0 ? "NoName" : data.username; messages.insertAdjacentHTML('beforeend', `

${username}: ${data.message}

`) diff --git a/trancendence/asgi.py b/trancendence/asgi.py index 5608a42..a229228 100644 --- a/trancendence/asgi.py +++ b/trancendence/asgi.py @@ -10,7 +10,7 @@ https://docs.djangoproject.com/en/4.2/howto/deployment/asgi/ import os from channels.routing import ProtocolTypeRouter, URLRouter from channels.auth import AuthMiddlewareStack -import frontend.routing +import chat.routing from django.core.asgi import get_asgi_application @@ -20,7 +20,7 @@ application = ProtocolTypeRouter({ 'http':get_asgi_application(), 'websocket':AuthMiddlewareStack( URLRouter( - frontend.routing.websocket_urlpatterns + chat.routing.websocket_urlpatterns ) ) })