From 3d09cef472bf54b80188d7980e5d11c794295b78 Mon Sep 17 00:00:00 2001 From: JrTimha Date: Wed, 18 Feb 2026 21:39:08 +0100 Subject: [PATCH 1/2] add `created_by` field to `NewRoom` notification event and ensure proper user retrieval in room-related operations --- src/broadcast/notification.rs | 3 ++- src/lib.rs | 1 - src/rooms/room_service.rs | 21 +++++++++++++++------ 3 files changed, 17 insertions(+), 8 deletions(-) diff --git a/src/broadcast/notification.rs b/src/broadcast/notification.rs index f5663fe..4b54ca9 100644 --- a/src/broadcast/notification.rs +++ b/src/broadcast/notification.rs @@ -38,7 +38,8 @@ pub enum NotificationEvent { /** * Sending this event to a newly invited user */ - NewRoom {room: ChatRoomDto }, + #[serde(rename_all = "camelCase")] + NewRoom {room: ChatRoomDto, created_by: User }, /** * Sending this event to a user who has left a room diff --git a/src/lib.rs b/src/lib.rs index f41afc9..9b1ff93 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -12,5 +12,4 @@ pub mod utils; pub mod errors; pub mod router; pub mod cache; - pub mod welcome; \ No newline at end of file diff --git a/src/rooms/room_service.rs b/src/rooms/room_service.rs index ad117f1..e5b1430 100644 --- a/src/rooms/room_service.rs +++ b/src/rooms/room_service.rs @@ -85,6 +85,9 @@ impl RoomService { pub async fn create_room(state: Arc, client_id: Uuid, new_room: NewRoom) -> Result { let room_entity = state.room_repository.insert_room(new_room.clone()).await?; + let creator_entity = state.user_repository.find_user_by_id(&client_id).await?.ok_or_else(|| { + AppError::NotFound("UserID not found.".to_string()) + })?; let users = new_room.invited_users; if room_entity.room_type == RoomType::Single { @@ -104,12 +107,12 @@ impl RoomService { let broadcast = BroadcastChannel::get(); broadcast.send_event(Notification { - body: crate::broadcast::NotificationEvent::NewRoom {room: participator_room.to_dto()}, + body: crate::broadcast::NotificationEvent::NewRoom {room: participator_room.to_dto(), created_by: creator_entity.clone()}, created_at: Utc::now() }, other_user).await; broadcast.send_event(Notification { - body: crate::broadcast::NotificationEvent::NewRoom {room: creator_room.to_dto()}, + body: crate::broadcast::NotificationEvent::NewRoom {room: creator_room.to_dto(), created_by: creator_entity}, created_at: Utc::now() }, &client_id).await; @@ -122,7 +125,7 @@ impl RoomService { BroadcastChannel::get().send_event_to_all( users, Notification { - body: crate::broadcast::NotificationEvent::NewRoom {room: room_dto.clone()}, + body: crate::broadcast::NotificationEvent::NewRoom {room: room_dto.clone(), created_by: creator_entity.clone()}, created_at: Utc::now() } ).await; @@ -159,11 +162,17 @@ impl RoomService { } pub async fn invite_to_room(state: Arc, client_id: Uuid, room_id: Uuid, user_id: Uuid) -> Result<(), AppError> { - let (room, users) = tokio::try_join!( //executing 2 queries async + let (room, users, creator) = tokio::try_join!( //executing 3 queries async state.room_repository.select_room(&room_id), - state.room_repository.select_joined_user_in_room(&room_id) + state.room_repository.select_joined_user_in_room(&room_id), + state.user_repository.find_user_by_id(&client_id) )?; + let creator_entity = creator.ok_or_else(|| { + AppError::NotFound("UserID not found.".to_string()) + })?; + + if room.room_type == RoomType::Single { return Err(AppError::ValidationError("Private rooms doesn't allow invites!.".to_string())) }; @@ -204,7 +213,7 @@ impl RoomService { BroadcastChannel::get().send_event( Notification { - body: crate::broadcast::NotificationEvent::NewRoom {room: room_for_user.to_dto()}, + body: crate::broadcast::NotificationEvent::NewRoom {room: room_for_user.to_dto(), created_by: creator_entity}, created_at: Utc::now() }, &user.id From 8344ec90ed9e0c2366f10c9412918e475a9d0d0b Mon Sep 17 00:00:00 2001 From: timvosskuehler Date: Thu, 19 Feb 2026 23:22:13 +0100 Subject: [PATCH 2/2] Fixed: missing transaction commit in delete_relationship_state function --- src/user_relationship/user_service.rs | 1 + 1 file changed, 1 insertion(+) diff --git a/src/user_relationship/user_service.rs b/src/user_relationship/user_service.rs index 86fb6c1..f7f7513 100644 --- a/src/user_relationship/user_service.rs +++ b/src/user_relationship/user_service.rs @@ -212,6 +212,7 @@ impl UserService { } } state.user_repository.delete_relationship_state(&mut tx, relationship).await?; + tx.commit().await?; Ok(()) }