Skip to content

Commit 2e0ed68

Browse files
committed
chore(spaces): converge on single naming scheme for all spaces related components on both the UI and the FFI crates
1 parent 59edb57 commit 2e0ed68

File tree

6 files changed

+84
-112
lines changed

6 files changed

+84
-112
lines changed

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1261,7 +1261,7 @@ impl Client {
12611261
SyncServiceBuilder::new((*self.inner).clone(), self.utd_hook_manager.get().cloned())
12621262
}
12631263

1264-
pub fn spaces_service(&self) -> Arc<SpaceService> {
1264+
pub fn space_service(&self) -> Arc<SpaceService> {
12651265
let inner = UISpaceService::new((*self.inner).clone());
12661266
Arc::new(SpaceService::new(inner))
12671267
}

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

Lines changed: 25 additions & 47 deletions
Original file line numberDiff line numberDiff line change
@@ -17,9 +17,8 @@ use std::{fmt::Debug, sync::Arc};
1717
use futures_util::{pin_mut, StreamExt};
1818
use matrix_sdk_common::{SendOutsideWasm, SyncOutsideWasm};
1919
use matrix_sdk_ui::spaces::{
20-
room_list::SpaceServiceRoomListPaginationState as UISpaceServiceRoomListPaginationState,
21-
SpaceService as UISpaceService, SpaceServiceRoom as UISpaceServiceRoom,
22-
SpaceServiceRoomList as UISpaceServiceRoomList,
20+
room_list::SpaceRoomListPaginationState, SpaceRoom as UISpaceRoom,
21+
SpaceRoomList as UISpaceRoomList, SpaceService as UISpaceService,
2322
};
2423
use ruma::RoomId;
2524

@@ -38,14 +37,14 @@ pub struct SpaceService {
3837
}
3938

4039
impl SpaceService {
41-
pub fn new(inner: UISpaceService) -> Self {
40+
pub(crate) fn new(inner: UISpaceService) -> Self {
4241
Self { inner }
4342
}
4443
}
4544

4645
#[matrix_sdk_ffi_macros::export]
4746
impl SpaceService {
48-
pub async fn joined_spaces(&self) -> Vec<SpaceServiceRoom> {
47+
pub async fn joined_spaces(&self) -> Vec<SpaceRoom> {
4948
self.inner.joined_spaces().await.into_iter().map(Into::into).collect()
5049
}
5150

@@ -77,51 +76,51 @@ impl SpaceService {
7776
pub async fn space_room_list(
7877
&self,
7978
space_id: String,
80-
) -> Result<Arc<SpaceServiceRoomList>, ClientError> {
79+
) -> Result<Arc<SpaceRoomList>, ClientError> {
8180
let space_id = RoomId::parse(space_id)?;
82-
Ok(Arc::new(SpaceServiceRoomList::new(self.inner.space_room_list(space_id))))
81+
Ok(Arc::new(SpaceRoomList::new(self.inner.space_room_list(space_id))))
8382
}
8483
}
8584

8685
#[derive(uniffi::Object)]
87-
pub struct SpaceServiceRoomList {
88-
inner: UISpaceServiceRoomList,
86+
pub struct SpaceRoomList {
87+
inner: UISpaceRoomList,
8988
}
9089

91-
impl SpaceServiceRoomList {
92-
pub fn new(inner: UISpaceServiceRoomList) -> Self {
90+
impl SpaceRoomList {
91+
fn new(inner: UISpaceRoomList) -> Self {
9392
Self { inner }
9493
}
9594
}
9695

9796
#[matrix_sdk_ffi_macros::export]
98-
impl SpaceServiceRoomList {
99-
pub fn pagination_state(&self) -> SpaceServiceRoomListPaginationState {
100-
self.inner.pagination_state().into()
97+
impl SpaceRoomList {
98+
pub fn pagination_state(&self) -> SpaceRoomListPaginationState {
99+
self.inner.pagination_state()
101100
}
102101

103102
pub fn subscribe_to_pagination_state_updates(
104103
&self,
105-
listener: Box<dyn SpaceServiceRoomListPaginationStateListener>,
104+
listener: Box<dyn SpaceRoomListPaginationStateListener>,
106105
) -> Arc<TaskHandle> {
107106
let pagination_state = self.inner.subscribe_to_pagination_state_updates();
108107

109108
Arc::new(TaskHandle::new(get_runtime_handle().spawn(async move {
110109
pin_mut!(pagination_state);
111110

112111
while let Some(state) = pagination_state.next().await {
113-
listener.on_update(state.into());
112+
listener.on_update(state);
114113
}
115114
})))
116115
}
117116

118-
pub fn rooms(&self) -> Vec<SpaceServiceRoom> {
117+
pub fn rooms(&self) -> Vec<SpaceRoom> {
119118
self.inner.rooms().into_iter().map(Into::into).collect()
120119
}
121120

122121
pub fn subscribe_to_room_update(
123122
&self,
124-
listener: Box<dyn SpaceServiceRoomListEntriesListener>,
123+
listener: Box<dyn SpaceRoomListEntriesListener>,
125124
) -> Arc<TaskHandle> {
126125
let entries_stream = self.inner.subscribe_to_room_updates();
127126

@@ -139,44 +138,23 @@ impl SpaceServiceRoomList {
139138
}
140139
}
141140

142-
#[derive(uniffi::Enum)]
143-
pub enum SpaceServiceRoomListPaginationState {
144-
Idle { end_reached: bool },
145-
Loading,
146-
}
147-
148-
impl From<UISpaceServiceRoomListPaginationState> for SpaceServiceRoomListPaginationState {
149-
fn from(state: UISpaceServiceRoomListPaginationState) -> Self {
150-
match state {
151-
UISpaceServiceRoomListPaginationState::Idle { end_reached } => {
152-
SpaceServiceRoomListPaginationState::Idle { end_reached }
153-
}
154-
UISpaceServiceRoomListPaginationState::Loading => {
155-
SpaceServiceRoomListPaginationState::Loading
156-
}
157-
}
158-
}
159-
}
160-
161141
#[matrix_sdk_ffi_macros::export(callback_interface)]
162-
pub trait SpaceServiceRoomListPaginationStateListener:
163-
SendOutsideWasm + SyncOutsideWasm + Debug
164-
{
165-
fn on_update(&self, pagination_state: SpaceServiceRoomListPaginationState);
142+
pub trait SpaceRoomListPaginationStateListener: SendOutsideWasm + SyncOutsideWasm + Debug {
143+
fn on_update(&self, pagination_state: SpaceRoomListPaginationState);
166144
}
167145

168146
#[matrix_sdk_ffi_macros::export(callback_interface)]
169-
pub trait SpaceServiceRoomListEntriesListener: SendOutsideWasm + SyncOutsideWasm + Debug {
170-
fn on_update(&self, rooms: Vec<SpaceServiceRoom>);
147+
pub trait SpaceRoomListEntriesListener: SendOutsideWasm + SyncOutsideWasm + Debug {
148+
fn on_update(&self, rooms: Vec<SpaceRoom>);
171149
}
172150

173151
#[matrix_sdk_ffi_macros::export(callback_interface)]
174152
pub trait SpaceServiceJoinedSpacesListener: SendOutsideWasm + SyncOutsideWasm + Debug {
175-
fn on_update(&self, rooms: Vec<SpaceServiceRoom>);
153+
fn on_update(&self, rooms: Vec<SpaceRoom>);
176154
}
177155

178156
#[derive(uniffi::Record)]
179-
pub struct SpaceServiceRoom {
157+
pub struct SpaceRoom {
180158
pub room_id: String,
181159
pub canonical_alias: Option<String>,
182160
pub name: Option<String>,
@@ -193,8 +171,8 @@ pub struct SpaceServiceRoom {
193171
pub heroes: Option<Vec<RoomHero>>,
194172
}
195173

196-
impl From<UISpaceServiceRoom> for SpaceServiceRoom {
197-
fn from(room: UISpaceServiceRoom) -> Self {
174+
impl From<UISpaceRoom> for SpaceRoom {
175+
fn from(room: UISpaceRoom) -> Self {
198176
Self {
199177
room_id: room.room_id.into(),
200178
canonical_alias: room.canonical_alias.map(|alias| alias.into()),

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

Lines changed: 13 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -17,30 +17,30 @@ use std::collections::{BTreeMap, BTreeSet};
1717
use ruma::OwnedRoomId;
1818

1919
#[derive(Debug)]
20-
struct SpaceServiceGraphNode {
20+
struct SpaceGraphNode {
2121
id: OwnedRoomId,
2222
parents: BTreeSet<OwnedRoomId>,
2323
children: BTreeSet<OwnedRoomId>,
2424
}
2525

26-
impl SpaceServiceGraphNode {
26+
impl SpaceGraphNode {
2727
fn new(id: OwnedRoomId) -> Self {
2828
Self { id, parents: BTreeSet::new(), children: BTreeSet::new() }
2929
}
3030
}
3131

3232
#[derive(Debug)]
33-
pub struct SpaceServiceGraph {
34-
nodes: BTreeMap<OwnedRoomId, SpaceServiceGraphNode>,
33+
pub struct SpaceGraph {
34+
nodes: BTreeMap<OwnedRoomId, SpaceGraphNode>,
3535
}
3636

37-
impl Default for SpaceServiceGraph {
37+
impl Default for SpaceGraph {
3838
fn default() -> Self {
3939
Self::new()
4040
}
4141
}
4242

43-
impl SpaceServiceGraph {
43+
impl SpaceGraph {
4444
pub fn new() -> Self {
4545
Self { nodes: BTreeMap::new() }
4646
}
@@ -54,15 +54,13 @@ impl SpaceServiceGraph {
5454
}
5555

5656
pub fn add_node(&mut self, node_id: OwnedRoomId) {
57-
self.nodes.entry(node_id.clone()).or_insert(SpaceServiceGraphNode::new(node_id));
57+
self.nodes.entry(node_id.clone()).or_insert(SpaceGraphNode::new(node_id));
5858
}
5959

6060
pub fn add_edge(&mut self, parent_id: OwnedRoomId, child_id: OwnedRoomId) {
61-
self.nodes
62-
.entry(parent_id.clone())
63-
.or_insert(SpaceServiceGraphNode::new(parent_id.clone()));
61+
self.nodes.entry(parent_id.clone()).or_insert(SpaceGraphNode::new(parent_id.clone()));
6462

65-
self.nodes.entry(child_id.clone()).or_insert(SpaceServiceGraphNode::new(child_id.clone()));
63+
self.nodes.entry(child_id.clone()).or_insert(SpaceGraphNode::new(child_id.clone()));
6664

6765
self.nodes.get_mut(&parent_id).unwrap().children.insert(child_id.clone());
6866
self.nodes.get_mut(&child_id).unwrap().parents.insert(parent_id);
@@ -124,7 +122,7 @@ mod tests {
124122

125123
#[test]
126124
fn test_add_edge_and_root_nodes() {
127-
let mut graph = SpaceServiceGraph::new();
125+
let mut graph = SpaceGraph::new();
128126

129127
let a = room_id!("!a:example.org").to_owned();
130128
let b = room_id!("!b:example.org").to_owned();
@@ -143,7 +141,7 @@ mod tests {
143141

144142
#[test]
145143
fn test_remove_cycles() {
146-
let mut graph = SpaceServiceGraph::new();
144+
let mut graph = SpaceGraph::new();
147145

148146
let a = room_id!("!a:example.org").to_owned();
149147
let b = room_id!("!b:example.org").to_owned();
@@ -163,7 +161,7 @@ mod tests {
163161

164162
#[test]
165163
fn test_disconnected_graph_roots() {
166-
let mut graph = SpaceServiceGraph::new();
164+
let mut graph = SpaceGraph::new();
167165

168166
let a = room_id!("!a:example.org").to_owned();
169167
let b = room_id!("!b:example.org").to_owned();
@@ -182,7 +180,7 @@ mod tests {
182180

183181
#[test]
184182
fn test_multiple_parents() {
185-
let mut graph = SpaceServiceGraph::new();
183+
let mut graph = SpaceGraph::new();
186184

187185
let a = room_id!("!a:example.org").to_owned();
188186
let b = room_id!("!b:example.org").to_owned();

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

Lines changed: 17 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -29,8 +29,8 @@ use ruma::{
2929
};
3030
use tracing::error;
3131

32-
use crate::spaces::graph::SpaceServiceGraph;
33-
pub use crate::spaces::{room::SpaceServiceRoom, room_list::SpaceServiceRoomList};
32+
use crate::spaces::graph::SpaceGraph;
33+
pub use crate::spaces::{room::SpaceRoom, room_list::SpaceRoomList};
3434

3535
pub mod graph;
3636
pub mod room;
@@ -39,7 +39,7 @@ pub mod room_list;
3939
pub struct SpaceService {
4040
client: Client,
4141

42-
joined_spaces: SharedObservable<Vec<SpaceServiceRoom>>,
42+
joined_spaces: SharedObservable<Vec<SpaceRoom>>,
4343

4444
room_update_handle: Mutex<Option<JoinHandle<()>>>,
4545
}
@@ -61,7 +61,7 @@ impl SpaceService {
6161
}
6262
}
6363

64-
pub fn subscribe_to_joined_spaces(&self) -> Subscriber<Vec<SpaceServiceRoom>> {
64+
pub fn subscribe_to_joined_spaces(&self) -> Subscriber<Vec<SpaceRoom>> {
6565
if self.room_update_handle.lock().is_none() {
6666
let client_clone = self.client.clone();
6767
let joined_spaces_clone = self.joined_spaces.clone();
@@ -89,7 +89,7 @@ impl SpaceService {
8989
self.joined_spaces.subscribe()
9090
}
9191

92-
pub async fn joined_spaces(&self) -> Vec<SpaceServiceRoom> {
92+
pub async fn joined_spaces(&self) -> Vec<SpaceRoom> {
9393
let spaces = Self::joined_spaces_for(&self.client).await;
9494

9595
if spaces != self.joined_spaces.get() {
@@ -99,18 +99,18 @@ impl SpaceService {
9999
spaces
100100
}
101101

102-
pub fn space_room_list(&self, space_id: OwnedRoomId) -> SpaceServiceRoomList {
103-
SpaceServiceRoomList::new(self.client.clone(), space_id)
102+
pub fn space_room_list(&self, space_id: OwnedRoomId) -> SpaceRoomList {
103+
SpaceRoomList::new(self.client.clone(), space_id)
104104
}
105105

106-
async fn joined_spaces_for(client: &Client) -> Vec<SpaceServiceRoom> {
106+
async fn joined_spaces_for(client: &Client) -> Vec<SpaceRoom> {
107107
let joined_spaces = client
108108
.joined_rooms()
109109
.into_iter()
110110
.filter_map(|room| room.is_space().then_some(room))
111111
.collect::<Vec<_>>();
112112

113-
let mut graph = SpaceServiceGraph::new();
113+
let mut graph = SpaceGraph::new();
114114

115115
for space in joined_spaces.iter() {
116116
graph.add_node(space.room_id().to_owned());
@@ -160,7 +160,7 @@ impl SpaceService {
160160
let room_id = room.room_id().to_owned();
161161

162162
if root_notes.contains(&&room_id) {
163-
Some(SpaceServiceRoom::new_from_known(
163+
Some(SpaceRoom::new_from_known(
164164
room.clone(),
165165
graph.children_of(&room_id).len() as u64,
166166
))
@@ -346,7 +346,7 @@ mod tests {
346346

347347
assert_eq!(
348348
space_service.joined_spaces().await,
349-
vec![SpaceServiceRoom::new_from_known(client.get_room(first_space_id).unwrap(), 0)]
349+
vec![SpaceRoom::new_from_known(client.get_room(first_space_id).unwrap(), 0)]
350350
);
351351

352352
// Join the second space
@@ -375,17 +375,17 @@ mod tests {
375375
assert_eq!(
376376
space_service.joined_spaces().await,
377377
vec![
378-
SpaceServiceRoom::new_from_known(client.get_room(first_space_id).unwrap(), 0),
379-
SpaceServiceRoom::new_from_known(client.get_room(second_space_id).unwrap(), 1)
378+
SpaceRoom::new_from_known(client.get_room(first_space_id).unwrap(), 0),
379+
SpaceRoom::new_from_known(client.get_room(second_space_id).unwrap(), 1)
380380
]
381381
);
382382

383383
// The subscriber yields new results when a space is joined
384384
assert_next_eq!(
385385
joined_spaces_subscriber,
386386
vec![
387-
SpaceServiceRoom::new_from_known(client.get_room(first_space_id).unwrap(), 0),
388-
SpaceServiceRoom::new_from_known(client.get_room(second_space_id).unwrap(), 1)
387+
SpaceRoom::new_from_known(client.get_room(first_space_id).unwrap(), 0),
388+
SpaceRoom::new_from_known(client.get_room(second_space_id).unwrap(), 1)
389389
]
390390
);
391391

@@ -394,7 +394,7 @@ mod tests {
394394
// and when one is left
395395
assert_next_eq!(
396396
joined_spaces_subscriber,
397-
vec![SpaceServiceRoom::new_from_known(client.get_room(first_space_id).unwrap(), 0)]
397+
vec![SpaceRoom::new_from_known(client.get_room(first_space_id).unwrap(), 0)]
398398
);
399399

400400
// but it doesn't when a non-space room gets joined
@@ -410,7 +410,7 @@ mod tests {
410410
assert_pending!(joined_spaces_subscriber);
411411
assert_eq!(
412412
space_service.joined_spaces().await,
413-
vec![SpaceServiceRoom::new_from_known(client.get_room(first_space_id).unwrap(), 0)]
413+
vec![SpaceRoom::new_from_known(client.get_room(first_space_id).unwrap(), 0)]
414414
);
415415
}
416416
}

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ use ruma::{
2020
};
2121

2222
#[derive(Debug, Clone, PartialEq)]
23-
pub struct SpaceServiceRoom {
23+
pub struct SpaceRoom {
2424
pub room_id: OwnedRoomId,
2525
pub canonical_alias: Option<OwnedRoomAliasId>,
2626
pub name: Option<String>,
@@ -37,7 +37,7 @@ pub struct SpaceServiceRoom {
3737
pub heroes: Option<Vec<RoomHero>>,
3838
}
3939

40-
impl SpaceServiceRoom {
40+
impl SpaceRoom {
4141
pub fn new_from_summary(
4242
summary: &RoomSummary,
4343
known_room: Option<Room>,

0 commit comments

Comments
 (0)