From 8d03e3465af4317502ba07a67c325dd96c273b4c Mon Sep 17 00:00:00 2001 From: Ivan Enderlin Date: Wed, 19 Jun 2024 14:29:22 +0200 Subject: [PATCH] feat(sdk): `room_list_service::Room::new` is now infallible. This patch makes `Room::new` infallible, i.e. it no longer returns a `Result` but `Self` directly. --- crates/matrix-sdk-ui/src/room_list_service/mod.rs | 5 ++++- .../matrix-sdk-ui/src/room_list_service/room.rs | 15 ++++----------- 2 files changed, 8 insertions(+), 12 deletions(-) diff --git a/crates/matrix-sdk-ui/src/room_list_service/mod.rs b/crates/matrix-sdk-ui/src/room_list_service/mod.rs index 50fa5137012..cd9e0eac6b0 100644 --- a/crates/matrix-sdk-ui/src/room_list_service/mod.rs +++ b/crates/matrix-sdk-ui/src/room_list_service/mod.rs @@ -433,7 +433,10 @@ impl RoomListService { return Ok(room.clone()); } - let room = Room::new(&self.client, room_id, &self.sliding_sync)?; + let room = Room::new( + self.client.get_room(room_id).ok_or_else(|| Error::RoomNotFound(room_id.to_owned()))?, + &self.sliding_sync, + ); // Save for later. rooms.push(room.clone()); diff --git a/crates/matrix-sdk-ui/src/room_list_service/room.rs b/crates/matrix-sdk-ui/src/room_list_service/room.rs index 52a70a4b803..58b6da3a5cf 100644 --- a/crates/matrix-sdk-ui/src/room_list_service/room.rs +++ b/crates/matrix-sdk-ui/src/room_list_service/room.rs @@ -17,7 +17,7 @@ use std::{ops::Deref, sync::Arc}; use async_once_cell::OnceCell as AsyncOnceCell; -use matrix_sdk::{Client, SlidingSync}; +use matrix_sdk::SlidingSync; use ruma::{api::client::sync::sync_events::v4::RoomSubscription, events::StateEventType, RoomId}; use super::Error; @@ -56,21 +56,14 @@ impl Deref for Room { impl Room { /// Create a new `Room`. - pub(super) fn new( - client: &Client, - room_id: &RoomId, - sliding_sync: &Arc, - ) -> Result { - let room = - client.get_room(room_id).ok_or_else(|| Error::RoomNotFound(room_id.to_owned()))?; - - Ok(Self { + pub(super) fn new(room: matrix_sdk::Room, sliding_sync: &Arc) -> Self { + Self { inner: Arc::new(RoomInner { sliding_sync: sliding_sync.clone(), room, timeline: AsyncOnceCell::new(), }), - }) + } } /// Get the room ID.