Chat advance

This commit is contained in:
Xamora 2023-11-27 23:31:31 +01:00
parent 8bce7d33ca
commit b12c03074a
10 changed files with 21 additions and 3 deletions

0
chat/__init__.py Normal file
View File

3
chat/admin.py Normal file
View File

@ -0,0 +1,3 @@
from django.contrib import admin
# Register your models here.

6
chat/apps.py Normal file
View File

@ -0,0 +1,6 @@
from django.apps import AppConfig
class ChatConfig(AppConfig):
default_auto_field = 'django.db.models.BigAutoField'
name = 'chat'

3
chat/models.py Normal file
View File

@ -0,0 +1,3 @@
from django.db import models
# Create your models here.

3
chat/tests.py Normal file
View File

@ -0,0 +1,3 @@
from django.test import TestCase
# Create your tests here.

3
chat/views.py Normal file
View File

@ -0,0 +1,3 @@
from django.shortcuts import render
# Create your views here.

View File

@ -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', `
<div><p>${username}: ${data.message}</p></div>
`)

View File

@ -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
)
)
})