Skip to content

Commit 9436bd0

Browse files
authored
Merge pull request #16 from JrTimha/development
Merge Bugfixes
2 parents 1b1ece2 + daf3322 commit 9436bd0

4 files changed

Lines changed: 18 additions & 8 deletions

File tree

src/broadcast/notification.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,8 @@ pub enum NotificationEvent {
3838
/**
3939
* Sending this event to a newly invited user
4040
*/
41-
NewRoom {room: ChatRoomDto },
41+
#[serde(rename_all = "camelCase")]
42+
NewRoom {room: ChatRoomDto, created_by: User },
4243

4344
/**
4445
* Sending this event to a user who has left a room

src/lib.rs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,5 +12,4 @@ pub mod utils;
1212
pub mod errors;
1313
pub mod router;
1414
pub mod cache;
15-
1615
pub mod welcome;

src/rooms/room_service.rs

Lines changed: 15 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -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

src/user_relationship/user_service.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -212,6 +212,7 @@ impl UserService {
212212
}
213213
}
214214
state.user_repository.delete_relationship_state(&mut tx, relationship).await?;
215+
tx.commit().await?;
215216
Ok(())
216217
}
217218

0 commit comments

Comments
 (0)