1
0
mirror of https://gitlab.com/animath/si/plateforme.git synced 2025-05-17 10:52:47 +00:00

Compare commits

..

33 Commits

Author SHA1 Message Date
Emmy D'Anello
f817c71043
Linting
Signed-off-by: Emmy D'Anello <emmy.danello@animath.fr>
2024-04-29 00:03:25 +02:00
Emmy D'Anello
9aa002b359
Store last visited channel in local storage
Signed-off-by: Emmy D'Anello <emmy.danello@animath.fr>
2024-04-28 23:56:41 +02:00
Emmy D'Anello
ed6ab57a9a
Add sort by unread messages option
Signed-off-by: Emmy D'Anello <emmy.danello@animath.fr>
2024-04-28 23:54:00 +02:00
Emmy D'Anello
519688d997
Store what messages are read
Signed-off-by: Emmy D'Anello <emmy.danello@animath.fr>
2024-04-28 23:25:15 +02:00
Emmy D'Anello
d19eb3d3fd
Improve context menus
Signed-off-by: Emmy D'Anello <emmy.danello@animath.fr>
2024-04-28 20:25:00 +02:00
Emmy D'Anello
b820306e2e
Automatically create appropriated channels when tournaments/pools/participations are updated
Signed-off-by: Emmy D'Anello <emmy.danello@animath.fr>
2024-04-28 17:04:34 +02:00
Emmy D'Anello
756f2074b3
Editing and deleting is working
Signed-off-by: Emmy D'Anello <emmy.danello@animath.fr>
2024-04-28 16:56:30 +02:00
Emmy D'Anello
6385e53425
Users can only edit & delete their own messages (except for admin users)
Signed-off-by: Emmy D'Anello <emmy.danello@animath.fr>
2024-04-28 16:36:54 +02:00
Emmy D'Anello
32b816a4de
Add popovers to edit and delete messages
Signed-off-by: Emmy D'Anello <emmy.danello@animath.fr>
2024-04-28 16:28:39 +02:00
Emmy D'Anello
41ccbcb277
Only give the focus to a private channel if it wasn't previously created
Signed-off-by: Emmy D'Anello <emmy.danello@animath.fr>
2024-04-28 15:37:45 +02:00
Emmy D'Anello
2438bb9bcc
Manage private chats
Signed-off-by: Emmy D'Anello <emmy.danello@animath.fr>
2024-04-28 15:35:32 +02:00
Emmy D'Anello
ddd2280ae4
Reset retry delay to 1 second when a connection has succeeded
Signed-off-by: Emmy D'Anello <emmy.danello@animath.fr>
2024-04-28 15:09:52 +02:00
Emmy D'Anello
4958628e40
Extend session cookie age from 3 hours to 2 weeks
Signed-off-by: Emmy D'Anello <emmy.danello@animath.fr>
2024-04-28 15:04:15 +02:00
Emmy D'Anello
731d309305
Add script to create channels per tournament, pools and teams. Put channels in categories
Signed-off-by: Emmy D'Anello <emmy.danello@animath.fr>
2024-04-28 13:50:04 +02:00
Emmy D'Anello
af9dcebca9
Open channels list by swiping
Signed-off-by: Emmy D'Anello <emmy.danello@animath.fr>
2024-04-28 12:55:25 +02:00
Emmy D'Anello
9c118c7142
Add specific login and logout pages for chat
Signed-off-by: Emmy D'Anello <emmy.danello@animath.fr>
2024-04-28 11:57:25 +02:00
Emmy D'Anello
14878fce86
Improve mobile chat
Signed-off-by: Emmy D'Anello <emmy.danello@animath.fr>
2024-04-27 23:20:15 +02:00
Emmy D'Anello
13f6b1972f
Notifications use the PNG logo
Signed-off-by: Emmy D'Anello <emmy.danello@animath.fr>
2024-04-27 20:37:23 +02:00
Emmy D'Anello
59f5667f52
Automatically scroll to bottom
Signed-off-by: Emmy D'Anello <emmy.danello@animath.fr>
2024-04-27 20:23:55 +02:00
Emmy D'Anello
be6e5b03c9
Chat is restricted to authenticated users
Signed-off-by: Emmy D'Anello <emmy.danello@animath.fr>
2024-04-27 19:24:01 +02:00
Emmy D'Anello
363ed35fa1
Simplify chat views
Signed-off-by: Emmy D'Anello <emmy.danello@animath.fr>
2024-04-27 19:12:11 +02:00
Emmy D'Anello
a50e865ef0
Add feature to install chat on the home screen
Signed-off-by: Emmy D'Anello <emmy.danello@animath.fr>
2024-04-27 19:11:03 +02:00
Emmy D'Anello
badbb2567e
Add fullscreen mode for chat
Signed-off-by: Emmy D'Anello <emmy.danello@animath.fr>
2024-04-27 16:16:57 +02:00
Emmy D'Anello
39085a6303
Fill channel selector using JavaScript
Signed-off-by: Emmy D'Anello <emmy.danello@animath.fr>
2024-04-27 14:50:25 +02:00
Emmy D'Anello
bb137509e1
Properly sort messages and add fetch previous messages ability
Signed-off-by: Emmy D'Anello <emmy.danello@animath.fr>
2024-04-27 14:12:08 +02:00
Emmy D'Anello
727aa8b6d6
Fetching last messages is working
Signed-off-by: Emmy D'Anello <emmy.danello@animath.fr>
2024-04-27 13:27:27 +02:00
Emmy D'Anello
ee15ea04d5
Send messages
Signed-off-by: Emmy D'Anello <emmy.danello@animath.fr>
2024-04-27 12:59:50 +02:00
Emmy D'Anello
c20554e01a
Setup chat UI
Signed-off-by: Emmy D'Anello <emmy.danello@animath.fr>
2024-04-27 12:08:10 +02:00
Emmy D'Anello
4026fe53c3
Allow to impersonate user on draw interface
Signed-off-by: Emmy D'Anello <emmy.danello@animath.fr>
2024-04-27 09:55:33 +02:00
Emmy D'Anello
1abe463575
Manage channels permissions
Signed-off-by: Emmy D'Anello <emmy.danello@animath.fr>
2024-04-27 09:53:55 +02:00
Emmy D'Anello
5b0081a531
Permissions are strings, not integers
Signed-off-by: Emmy D'Anello <emmy.danello@animath.fr>
2024-04-27 09:00:23 +02:00
Emmy D'Anello
06c82a239d
Initialize chat interface
Signed-off-by: Emmy D'Anello <emmy.danello@animath.fr>
2024-04-27 08:57:01 +02:00
Emmy D'Anello
f8725cf8a9
Prepare models for new chat feature
Signed-off-by: Emmy D'Anello <emmy.danello@animath.fr>
2024-04-27 08:49:50 +02:00
3 changed files with 8 additions and 8 deletions

View File

@ -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 Count, F, 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
@ -93,9 +93,7 @@ class ChatConsumer(AsyncJsonWebsocketConsumer):
'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(total_messages=Count('messages', distinct=True)) .annotate(unread_messages=Count('messages', filter=~Q(messages__users_read=user))).all()
.annotate(read_messages=Count('messages', filter=Q(messages__users_read=user), distinct=True))
.annotate(unread_messages=F('total_messages') - F('read_messages')).all()
] ]
} }
await self.send_json(message) await self.send_json(message)
@ -162,7 +160,8 @@ class ChatConsumer(AsyncJsonWebsocketConsumer):
messages = Message.objects \ messages = Message.objects \
.filter(channel=channel) \ .filter(channel=channel) \
.annotate(read=Count('users_read', filter=Q(users_read=self.scope['user']))) \ .annotate(read=Exists(User.objects.filter(pk=self.scope['user'].pk)
.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',
@ -174,7 +173,7 @@ class ChatConsumer(AsyncJsonWebsocketConsumer):
'author_id': message.author_id, 'author_id': message.author_id,
'author': await message.aget_author_name(), 'author': await message.aget_author_name(),
'content': message.content, 'content': message.content,
'read': message.read > 0, 'read': message.read,
} }
async for message in messages async for message in messages
])) ]))
@ -240,6 +239,7 @@ class ChatConsumer(AsyncJsonWebsocketConsumer):
'content': message['content']}) 'content': message['content']})
async def chat_edit_message(self, message) -> None: async def chat_edit_message(self, message) -> None:
print(message)
await self.send_json({'type': 'edit_message', 'id': message['id'], 'channel_id': message['channel_id'], await self.send_json({'type': 'edit_message', 'id': message['id'], 'channel_id': message['channel_id'],
'content': message['content']}) 'content': message['content']})

View File

@ -157,7 +157,6 @@ function fetchPreviousMessages() {
} }
function receiveFetchedMessages(data) { function receiveFetchedMessages(data) {
console.log(data)
let channel_id = data['channel_id'] let channel_id = data['channel_id']
let new_messages = data['messages'] let new_messages = data['messages']
@ -190,6 +189,7 @@ function updateUnreadBadges(unreadMessages) {
for (let channel of Object.values(channels)) { for (let channel of Object.values(channels)) {
let unreadMessagesChannel = unreadMessages[channel['id']] || 0 let unreadMessagesChannel = unreadMessages[channel['id']] || 0
console.log(channel, unreadMessagesChannel)
channel.unread_messages = unreadMessagesChannel channel.unread_messages = unreadMessagesChannel
let unreadBadge = document.getElementById(`unread-messages-${channel['id']}`) let unreadBadge = document.getElementById(`unread-messages-${channel['id']}`)

View File

@ -391,7 +391,7 @@ class TeamAuthorizationsView(LoginRequiredMixin, View):
tournament = Tournament.objects.get(pk=kwargs["tournament_id"]) tournament = Tournament.objects.get(pk=kwargs["tournament_id"])
if user.registration.is_admin or user.registration.is_volunteer \ if user.registration.is_admin or user.registration.is_volunteer \
and (user.registration in tournament.organizers.all() and (user.registration in tournament.organizers
or (team is not None and team.participation.final or (team is not None and team.participation.final
and user.registration in Tournament.final_tournament().organizers)): and user.registration in Tournament.final_tournament().organizers)):
return super().dispatch(request, *args, **kwargs) return super().dispatch(request, *args, **kwargs)