0.3.0
chat v3
This commit is contained in:
@@ -11,6 +11,6 @@ urlpatterns = [
|
||||
path('create_ticket/', create_ticket_ajax, name='create_ticket_ajax'),
|
||||
path('support_show_chat_by_ticket/', support_show_chat_by_ticket_ajax, name='support_show_chat_by_ticket_ajax'),
|
||||
path('send_msg/', send_msg_ajax, name='send_msg_ajax'),
|
||||
path('update_chat/', update_chat_ajax2, name='update_chat_ajax'),
|
||||
# path('update_chat/', update_chat_ajax2, name='update_chat_ajax'),
|
||||
path('show_chat_w_user/', show_chat_w_user_ajax, name='show_chat_w_user_ajax'),
|
||||
]
|
||||
@@ -0,0 +1,21 @@
|
||||
# Generated by Django 4.2.2 on 2023-08-11 23:21
|
||||
|
||||
from django.db import migrations
|
||||
|
||||
|
||||
class Migration(migrations.Migration):
|
||||
|
||||
dependencies = [
|
||||
('ChatServiceApp', '0003_msggroup_text'),
|
||||
]
|
||||
|
||||
operations = [
|
||||
migrations.AlterModelOptions(
|
||||
name='message',
|
||||
options={'verbose_name': 'Сообщение', 'verbose_name_plural': 'Сообщения'},
|
||||
),
|
||||
migrations.AlterModelOptions(
|
||||
name='msggroup',
|
||||
options={'verbose_name': 'Тикет', 'verbose_name_plural': 'Тикеты'},
|
||||
),
|
||||
]
|
||||
7
ChatServiceApp/websocket_urls.py
Normal file
7
ChatServiceApp/websocket_urls.py
Normal file
@@ -0,0 +1,7 @@
|
||||
from django.urls import re_path
|
||||
from .websocket_views import *
|
||||
|
||||
websocket_urlpatterns = [
|
||||
re_path(r'ws/socket-server/', ChatConsumer.as_asgi())
|
||||
|
||||
]
|
||||
38
ChatServiceApp/websocket_views.py
Normal file
38
ChatServiceApp/websocket_views.py
Normal file
@@ -0,0 +1,38 @@
|
||||
import json
|
||||
from channels.generic.websocket import WebsocketConsumer
|
||||
from asgiref.sync import async_to_sync
|
||||
|
||||
|
||||
class ChatConsumer(WebsocketConsumer):
|
||||
def connect(self):
|
||||
self.room_group_name = 'test'
|
||||
|
||||
async_to_sync(self.channel_layer.group_add)(
|
||||
self.room_group_name,
|
||||
self.channel_name
|
||||
)
|
||||
self.accept()
|
||||
|
||||
def receive(self, text_data):
|
||||
text_data_json = json.loads(text_data)
|
||||
message = text_data_json['message']
|
||||
sender = text_data_json['sender']
|
||||
|
||||
async_to_sync(self.channel_layer.group_send)(
|
||||
self.room_group_name,
|
||||
{
|
||||
'type': 'chat_message',
|
||||
'message': message,
|
||||
'sender': sender
|
||||
}
|
||||
)
|
||||
|
||||
def chat_message(self, event):
|
||||
message = event['message']
|
||||
sender = event['sender']
|
||||
|
||||
self.send(text_data=json.dumps({
|
||||
'type': 'chat',
|
||||
'message': message,
|
||||
'sender': sender
|
||||
}))
|
||||
Reference in New Issue
Block a user