@@ -85,6 +85,9 @@ impl RoomService {
8585
8686 pub async fn create_room ( state : Arc < AppState > , client_id : Uuid , new_room : NewRoom ) -> Result < ChatRoomDto , AppError > {
8787 let room_entity = state. room_repository . insert_room ( new_room. clone ( ) ) . await ?;
88+ let creator_entity = state. user_repository . find_user_by_id ( & client_id) . await ?. ok_or_else ( || {
89+ AppError :: NotFound ( "UserID not found." . to_string ( ) )
90+ } ) ?;
8891 let users = new_room. invited_users ;
8992
9093 if room_entity. room_type == RoomType :: Single {
@@ -104,12 +107,12 @@ impl RoomService {
104107 let broadcast = BroadcastChannel :: get ( ) ;
105108
106109 broadcast. send_event ( Notification {
107- body : crate :: broadcast:: NotificationEvent :: NewRoom { room : participator_room. to_dto ( ) } ,
110+ body : crate :: broadcast:: NotificationEvent :: NewRoom { room : participator_room. to_dto ( ) , created_by : creator_entity . clone ( ) } ,
108111 created_at : Utc :: now ( )
109112 } , other_user) . await ;
110113
111114 broadcast. send_event ( Notification {
112- body : crate :: broadcast:: NotificationEvent :: NewRoom { room : creator_room. to_dto ( ) } ,
115+ body : crate :: broadcast:: NotificationEvent :: NewRoom { room : creator_room. to_dto ( ) , created_by : creator_entity } ,
113116 created_at : Utc :: now ( )
114117 } , & client_id) . await ;
115118
@@ -122,7 +125,7 @@ impl RoomService {
122125 BroadcastChannel :: get ( ) . send_event_to_all (
123126 users,
124127 Notification {
125- body : crate :: broadcast:: NotificationEvent :: NewRoom { room : room_dto. clone ( ) } ,
128+ body : crate :: broadcast:: NotificationEvent :: NewRoom { room : room_dto. clone ( ) , created_by : creator_entity . clone ( ) } ,
126129 created_at : Utc :: now ( )
127130 }
128131 ) . await ;
@@ -159,11 +162,17 @@ impl RoomService {
159162 }
160163
161164 pub async fn invite_to_room ( state : Arc < AppState > , client_id : Uuid , room_id : Uuid , user_id : Uuid ) -> Result < ( ) , AppError > {
162- let ( room, users) = tokio:: try_join!( //executing 2 queries async
165+ let ( room, users, creator ) = tokio:: try_join!( //executing 3 queries async
163166 state. room_repository. select_room( & room_id) ,
164- state. room_repository. select_joined_user_in_room( & room_id)
167+ state. room_repository. select_joined_user_in_room( & room_id) ,
168+ state. user_repository. find_user_by_id( & client_id)
165169 ) ?;
166170
171+ let creator_entity = creator. ok_or_else ( || {
172+ AppError :: NotFound ( "UserID not found." . to_string ( ) )
173+ } ) ?;
174+
175+
167176 if room. room_type == RoomType :: Single {
168177 return Err ( AppError :: ValidationError ( "Private rooms doesn't allow invites!." . to_string ( ) ) )
169178 } ;
@@ -204,7 +213,7 @@ impl RoomService {
204213
205214 BroadcastChannel :: get ( ) . send_event (
206215 Notification {
207- body : crate :: broadcast:: NotificationEvent :: NewRoom { room : room_for_user. to_dto ( ) } ,
216+ body : crate :: broadcast:: NotificationEvent :: NewRoom { room : room_for_user. to_dto ( ) , created_by : creator_entity } ,
208217 created_at : Utc :: now ( )
209218 } ,
210219 & user. id
0 commit comments