Skip to content

Commit 8d03e34

Browse files
committed
feat(sdk): room_list_service::Room::new is now infallible.
This patch makes `Room::new` infallible, i.e. it no longer returns a `Result<Self, _>` but `Self` directly.
1 parent bd45c23 commit 8d03e34

File tree

2 files changed

+8
-12
lines changed

2 files changed

+8
-12
lines changed

crates/matrix-sdk-ui/src/room_list_service/mod.rs

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -433,7 +433,10 @@ impl RoomListService {
433433
return Ok(room.clone());
434434
}
435435

436-
let room = Room::new(&self.client, room_id, &self.sliding_sync)?;
436+
let room = Room::new(
437+
self.client.get_room(room_id).ok_or_else(|| Error::RoomNotFound(room_id.to_owned()))?,
438+
&self.sliding_sync,
439+
);
437440

438441
// Save for later.
439442
rooms.push(room.clone());

crates/matrix-sdk-ui/src/room_list_service/room.rs

Lines changed: 4 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@
1717
use std::{ops::Deref, sync::Arc};
1818

1919
use async_once_cell::OnceCell as AsyncOnceCell;
20-
use matrix_sdk::{Client, SlidingSync};
20+
use matrix_sdk::SlidingSync;
2121
use ruma::{api::client::sync::sync_events::v4::RoomSubscription, events::StateEventType, RoomId};
2222

2323
use super::Error;
@@ -56,21 +56,14 @@ impl Deref for Room {
5656

5757
impl Room {
5858
/// Create a new `Room`.
59-
pub(super) fn new(
60-
client: &Client,
61-
room_id: &RoomId,
62-
sliding_sync: &Arc<SlidingSync>,
63-
) -> Result<Self, Error> {
64-
let room =
65-
client.get_room(room_id).ok_or_else(|| Error::RoomNotFound(room_id.to_owned()))?;
66-
67-
Ok(Self {
59+
pub(super) fn new(room: matrix_sdk::Room, sliding_sync: &Arc<SlidingSync>) -> Self {
60+
Self {
6861
inner: Arc::new(RoomInner {
6962
sliding_sync: sliding_sync.clone(),
7063
room,
7164
timeline: AsyncOnceCell::new(),
7265
}),
73-
})
66+
}
7467
}
7568

7669
/// Get the room ID.

0 commit comments

Comments
 (0)