Signed-off-by: Emmy D'Anello <emmy.danello@animath.fr>
This commit is contained in:
Emmy D'Anello 2024-04-29 00:03:25 +02:00
parent a41c17576f
commit ed5944e044
Signed by: ynerant
GPG Key ID: 3A75C55819C8CF85
1 changed files with 7 additions and 7 deletions

View File

@ -3,7 +3,7 @@
from channels.generic.websocket import AsyncJsonWebsocketConsumer
from django.contrib.auth.models import User
from django.db.models import Exists, OuterRef, Count, Q
from django.db.models import Count, Exists, OuterRef, Q
from registration.models import Registration
from .models import Channel, Message
@ -92,7 +92,7 @@ class ChatConsumer(AsyncJsonWebsocketConsumer):
'write_access': await self.write_channels.acontains(channel),
'unread_messages': channel.unread_messages,
}
async for channel in self.read_channels.prefetch_related('invited') \
async for channel in self.read_channels.prefetch_related('invited')
.annotate(unread_messages=Count('messages', filter=~Q(messages__users_read=user))).all()
]
}
@ -160,7 +160,7 @@ class ChatConsumer(AsyncJsonWebsocketConsumer):
messages = Message.objects \
.filter(channel=channel) \
.annotate(read=Exists(User.objects.filter(pk=self.scope['user'].pk) \
.annotate(read=Exists(User.objects.filter(pk=self.scope['user'].pk)
.filter(pk=OuterRef('users_read')))) \
.order_by('-created_at')[offset:offset + limit].all()
await self.send_json({