remove error in console, and search work with unlog user

This commit is contained in:
2024-01-14 17:50:34 +01:00
parent 131e599d17
commit 11392c22c4
5 changed files with 42 additions and 16 deletions

View File

@ -107,8 +107,8 @@ class ChatNoticeConsumer(WebsocketConsumer):
def connect(self):
user = self.scope["user"]
if (user.is_anonymous or not user.is_authenticated):
return
#if (user.is_anonymous or not user.is_authenticated):
#return
if (self.channel_layer == None):
return
@ -125,6 +125,18 @@ class ChatNoticeConsumer(WebsocketConsumer):
self.accept()
message_time: int = int(time.time() * 1000)
targets = list(self.channel_layer.users_channels.keys())
for target in targets:
channel = self.channel_layer.users_channels.get(target)
if (channel == None or target == user.pk):
continue
async_to_sync(self.channel_layer.send)(channel, {
'type':"online_users",
'author_id':user.pk,
'time':message_time,
})
def disconnect(self, code):
user = self.scope["user"]
@ -152,8 +164,8 @@ class ChatNoticeConsumer(WebsocketConsumer):
return
user = self.scope["user"]
if (user.is_anonymous or not user.is_authenticated):
return
#if (user.is_anonymous or not user.is_authenticated):
#return
text_data_json = json.loads(text_data)
@ -170,6 +182,8 @@ class ChatNoticeConsumer(WebsocketConsumer):
message_time: int = int(time.time() * 1000)
status = 200;
#print("receive" + str(user.pk))
if targets == "all":
targets = list(self.channel_layer.users_channels.keys())
@ -211,8 +225,10 @@ class ChatNoticeConsumer(WebsocketConsumer):
def online_users(self, event):
user = self.scope["user"]
if (user.is_anonymous or not user.is_authenticated):
return
#if (user.is_anonymous or not user.is_authenticated):
#return
#print("online_users" + str(user.pk))
event['content'] = self.channel_layer.users_channels