2020 ProjectChat ,
2121 ProjectChatMessage ,
2222)
23+ from chats .serializers import (
24+ ProjectChatMessageListSerializer ,
25+ DirectChatMessageListSerializer ,
26+ )
2327from chats .utils import (
2428 get_user_channel_cache_key ,
2529 create_message ,
@@ -350,7 +354,7 @@ async def __process_delete_project_message_event(self, event: Event, room_name:
350354 await self .channel_layer .group_send (
351355 room_name ,
352356 {
353- "type" : EventType .NEW_MESSAGE ,
357+ "type" : EventType .DELETE_MESSAGE ,
354358 "content" : {"message_id" : event .content ["message_id" ]},
355359 },
356360 )
@@ -420,26 +424,19 @@ async def __process_edit_direct_message_event(self, event):
420424 msg .text = event .content ["text" ]
421425 msg .is_edited = True
422426 await sync_to_async (msg .save )()
423- author = await sync_to_async (lambda : (UserDetailSerializer (self .user )).data )()
424- content = {
425- "type" : EventType .EDIT_MESSAGE ,
426- "content" : {
427- "message_id" : msg .id ,
428- "chat_id" : msg .chat_id ,
429- "author" : author ,
430- "text" : msg .text ,
431- "created_at" : msg .created_at .timestamp (),
432- "is_edited" : msg .is_edited ,
433- },
434- }
427+ content = await sync_to_async (
428+ lambda : (DirectChatMessageListSerializer (msg )).data
429+ )()
430+
435431 # send message to user's channel
436432 other_user_channel = cache .get (get_user_channel_cache_key (other_user ), None )
437- await self .channel_layer .send (self .channel_name , content )
438433
439- if other_user_channel is None :
440- return
434+ if other_user_channel :
435+ await self . channel_layer . send ( other_user_channel , content )
441436
442- await self .channel_layer .send (other_user_channel , content )
437+ await self .channel_layer .send (
438+ self .channel_name , {"type" : EventType .EDIT_MESSAGE , "content" : content }
439+ )
443440
444441 async def __process_edit_project_message_event (self , event , room_name ):
445442 chat_id = event .content ["chat_id" ]
@@ -455,6 +452,7 @@ async def __process_edit_project_message_event(self, event, room_name):
455452 message = await sync_to_async (ProjectChatMessage .objects .get )(
456453 pk = event .content ["message_id" ]
457454 )
455+
458456 message_author = await sync_to_async (lambda : message .author )()
459457 if message_author != self .user :
460458 raise UserNotMessageAuthorException (
@@ -463,15 +461,10 @@ async def __process_edit_project_message_event(self, event, room_name):
463461 message .text = event .content ["text" ]
464462 message .is_edited = True
465463 await sync_to_async (message .save )()
466- author = await sync_to_async (lambda : (UserDetailSerializer (self .user )).data )()
467- content = {
468- "message_id" : message .id ,
469- "chat_id" : message .chat_id ,
470- "author" : author ,
471- "text" : message .text ,
472- "created_at" : message .created_at .timestamp (),
473- "is_edited" : message .is_edited ,
474- }
464+
465+ content = await sync_to_async (
466+ lambda : (ProjectChatMessageListSerializer (message )).data
467+ )()
475468 await self .channel_layer .group_send (
476469 room_name ,
477470 {"type" : EventType .EDIT_MESSAGE , "content" : content },
0 commit comments