11from chats .models import DirectChatMessage , DirectChat
22from chats .websockets_settings import Event , EventType
33from asgiref .sync import sync_to_async
4- from chats .exceptions import WrongChatIdException , UserNotMessageAuthorException
4+ from chats .exceptions import (
5+ WrongChatIdException ,
6+ UserNotMessageAuthorException ,
7+ UserIsNotAuthor ,
8+ )
59from django .core .cache import cache
610from chats .utils import (
711 get_user_channel_cache_key ,
@@ -80,7 +84,7 @@ async def process_read_message_event(self, event: Event, room_name: str):
8084 msg = await sync_to_async (DirectChatMessage .objects .get )(
8185 pk = event .content ["message_id" ]
8286 )
83- if msg .chat_id != chat_id or msg .author_id != other_user :
87+ if msg .chat_id != chat_id or msg .author_id != other_user . id :
8488 raise WrongChatIdException (
8589 "Some of chat/message ids are wrong, you can't access this message"
8690 )
@@ -106,6 +110,10 @@ async def process_delete_message_event(self, event: Event, room_name: str):
106110 message_id = event .content ["message_id" ]
107111
108112 message = await sync_to_async (DirectChatMessage .objects .get )(pk = message_id )
113+
114+ if self .user .id != message .author_id :
115+ raise UserIsNotAuthor (f"User { self .user .id } is not author { message .text } " )
116+
109117 message .is_deleted = True
110118 await sync_to_async (message .save )()
111119
0 commit comments