Linting
Signed-off-by: Emmy D'Anello <emmy.danello@animath.fr>
This commit is contained in:
parent
a41c17576f
commit
ed5944e044
|
@ -3,7 +3,7 @@
|
||||||
|
|
||||||
from channels.generic.websocket import AsyncJsonWebsocketConsumer
|
from channels.generic.websocket import AsyncJsonWebsocketConsumer
|
||||||
from django.contrib.auth.models import User
|
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 registration.models import Registration
|
||||||
|
|
||||||
from .models import Channel, Message
|
from .models import Channel, Message
|
||||||
|
@ -92,8 +92,8 @@ class ChatConsumer(AsyncJsonWebsocketConsumer):
|
||||||
'write_access': await self.write_channels.acontains(channel),
|
'write_access': await self.write_channels.acontains(channel),
|
||||||
'unread_messages': channel.unread_messages,
|
'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()
|
.annotate(unread_messages=Count('messages', filter=~Q(messages__users_read=user))).all()
|
||||||
]
|
]
|
||||||
}
|
}
|
||||||
await self.send_json(message)
|
await self.send_json(message)
|
||||||
|
@ -159,10 +159,10 @@ class ChatConsumer(AsyncJsonWebsocketConsumer):
|
||||||
limit = min(limit, 200) # Fetch only maximum 200 messages at the time
|
limit = min(limit, 200) # Fetch only maximum 200 messages at the time
|
||||||
|
|
||||||
messages = Message.objects \
|
messages = Message.objects \
|
||||||
.filter(channel=channel) \
|
.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')))) \
|
.filter(pk=OuterRef('users_read')))) \
|
||||||
.order_by('-created_at')[offset:offset + limit].all()
|
.order_by('-created_at')[offset:offset + limit].all()
|
||||||
await self.send_json({
|
await self.send_json({
|
||||||
'type': 'fetch_messages',
|
'type': 'fetch_messages',
|
||||||
'channel_id': channel_id,
|
'channel_id': channel_id,
|
||||||
|
|
Loading…
Reference in New Issue