WARNING: THIS SITE IS A MIRROR OF GITHUB.COM / IT CANNOT LOGIN OR REGISTER ACCOUNTS / THE CONTENTS ARE PROVIDED AS-IS / THIS SITE ASSUMES NO RESPONSIBILITY FOR ANY DISPLAYED CONTENT OR LINKS / IF YOU FOUND SOMETHING MAY NOT GOOD FOR EVERYONE, CONTACT ADMIN AT ilovescratch@foxmail.com
Skip to content

Commit 7988010

Browse files
committed
change: made the ffi function use Result, added a test and the changelog entries
1 parent 8815968 commit 7988010

File tree

4 files changed

+47
-4
lines changed

4 files changed

+47
-4
lines changed

bindings/matrix-sdk-ffi/CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ All notable changes to this project will be documented in this file.
88

99
### Features
1010

11+
- Add `SpaceService::space_room_for_id` to get a space given its id from the space graph if available.
1112
- Add `QrCodeData::to_bytes()` to allow generation of a QR code.
1213
([#5939](https://github.com/matrix-org/matrix-rust-sdk/pull/5939))
1314
- [**breaking**]: The new Latest Event API replaces the old API.

bindings/matrix-sdk-ffi/src/spaces.rs

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -110,9 +110,12 @@ impl SpaceService {
110110

111111
/// Returns the corresponding `SpaceRoom` for the given room ID, or `None`
112112
/// if it isn't known.
113-
pub async fn space_room_with_id(&self, room_id: String) -> Option<SpaceRoom> {
114-
let room_id = RoomId::parse(room_id.as_str()).ok()?;
115-
self.inner.space_room_with_id(&room_id).await.map(Into::into)
113+
pub async fn space_room_for_id(
114+
&self,
115+
room_id: String,
116+
) -> Result<Option<SpaceRoom>, ClientError> {
117+
let room_id = RoomId::parse(room_id.as_str())?;
118+
Ok(self.inner.space_room_for_id(&room_id).await.map(Into::into))
116119
}
117120

118121
pub async fn add_child_to_space(

crates/matrix-sdk-ui/CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ All notable changes to this project will be documented in this file.
88

99
### Features
1010

11+
- Add `SpaceService::space_room_for_id` to get a space given its id from the space graph if available.
1112
- [**breaking**]: The new Latest Event API replaces the old API. All the
1213
`new_` prefixes have been removed. The following methods are removed:
1314
`EventTimelineItem::from_latest_event`, and `Timeline::latest_event`. See the

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

Lines changed: 39 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -259,7 +259,7 @@ impl SpaceService {
259259

260260
/// Returns the corresponding `SpaceRoom` for the given room ID, or `None`
261261
/// if it isn't known.
262-
pub async fn space_room_with_id(&self, room_id: &RoomId) -> Option<SpaceRoom> {
262+
pub async fn space_room_for_id(&self, room_id: &RoomId) -> Option<SpaceRoom> {
263263
let graph = &self.space_state.lock().await.graph;
264264

265265
if graph.has_node(room_id)
@@ -908,6 +908,44 @@ mod tests {
908908
);
909909
}
910910

911+
#[async_test]
912+
async fn test_space_room_for_id() {
913+
let server = MatrixMockServer::new().await;
914+
let client = server.client_builder().build().await;
915+
let user_id = client.user_id().unwrap();
916+
let factory = EventFactory::new();
917+
918+
server.mock_room_state_encryption().plain().mount().await;
919+
920+
let space_id = room_id!("!single_space:example.org");
921+
922+
add_space_rooms(
923+
vec![MockSpaceRoomParameters {
924+
room_id: space_id,
925+
order: None,
926+
parents: vec![],
927+
children: vec![],
928+
power_level: None,
929+
}],
930+
&client,
931+
&server,
932+
&factory,
933+
user_id,
934+
)
935+
.await;
936+
937+
let space_service = SpaceService::new(client.clone());
938+
939+
// Ensure internal state is populated.
940+
_ = space_service.joined_spaces().await;
941+
942+
let found = space_service.space_room_for_id(&space_id).await;
943+
assert!(found.is_some());
944+
945+
let expected = SpaceRoom::new_from_known(&client.get_room(space_id).unwrap(), 0);
946+
assert_eq!(found.unwrap(), expected);
947+
}
948+
911949
#[async_test]
912950
async fn test_add_child_to_space() {
913951
// Given a space and child room where the user is admin of both.

0 commit comments

Comments
 (0)