Move file tournament; chat can see who is online

This commit is contained in:
2024-01-13 11:18:10 +01:00
parent 09f3c92153
commit a254e5a0c2
7 changed files with 54 additions and 39 deletions

View File

@ -133,6 +133,19 @@ class ChatNoticeConsumer(WebsocketConsumer):
self.channel_layer.users_channels.pop(user.pk)
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 receive(self, text_data=None, bytes_data=None):
if text_data == None:
@ -156,14 +169,17 @@ class ChatNoticeConsumer(WebsocketConsumer):
message_time: int = int(time.time() * 1000)
status = 200;
if targets == "all":
targets = list(self.channel_layer.users_channels.keys())
for target in targets:
if (self.channel_layer.users_channels.get(target) == None):
status = 404
channel = self.channel_layer.users_channels.get(target)
if (channel == None or target == user.pk):
if (channel == None):
status = 404
continue
async_to_sync(self.channel_layer.send)(self.channel_layer.users_channels.get(target), {
async_to_sync(self.channel_layer.send)(channel, {
'type':type_notice,
'author_id':user.pk,
'content':content,
@ -192,7 +208,7 @@ class ChatNoticeConsumer(WebsocketConsumer):
'time': event['time'],
}))
def online_user(self, event):
def online_users(self, event):
user = self.scope["user"]
if (user.is_anonymous or not user.is_authenticated):