From a459742801f1784815b932b9488201c26e34b30d Mon Sep 17 00:00:00 2001 From: rizwanisready Date: Fri, 21 Jun 2024 17:49:18 +0530 Subject: [PATCH] refactored consumers.py --- chat/consumers.py | 19 +------------------ 1 file changed, 1 insertion(+), 18 deletions(-) diff --git a/chat/consumers.py b/chat/consumers.py index 9bf2a3f..a38567a 100644 --- a/chat/consumers.py +++ b/chat/consumers.py @@ -1,18 +1,10 @@ -from channels.generic.websocket import AsyncWebsocketConsumer, WebsocketConsumer +from channels.generic.websocket import AsyncWebsocketConsumer import json -import django -django.setup() - -from accounts.models import IAmPrincipal from channels.exceptions import StopConsumer -from asgiref.sync import async_to_sync, sync_to_async from django.utils import timezone from chat.models import ChatGroup, ChatMessage from channels.db import database_sync_to_async -from django.db import close_old_connections -from rest_framework_simplejwt.tokens import AccessToken from rest_framework_simplejwt.authentication import JWTAuthentication -import threading class ChatConsumer(AsyncWebsocketConsumer): @@ -26,15 +18,6 @@ class ChatConsumer(AsyncWebsocketConsumer): print("token_key: ", token_key) self.user = await self.get_user_async(token_key) print("self.user: ", self.user) - # Start the thread to get the user object - # user_thread = threading.Thread(target=self.get_user_async, args=(token_key,)) - # user_thread.start() - - # # Wait for the thread to finish and assign the user object to the scope - # user_thread.join() - # self.scope["user"] = self.user - # print("User: ", self.scope["user"]) - # print("self.user: ", self.user) # Join room group await self.channel_layer.group_add(self.room_name, self.channel_name)