Skip to content

Commit 7a11db4

Browse files
committed
chore(spaces): simplify the SpaceGraph interfaces
Fix graph reference crap
1 parent aa27a64 commit 7a11db4

File tree

2 files changed

+14
-8
lines changed

2 files changed

+14
-8
lines changed

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

Lines changed: 11 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@
1414

1515
use std::collections::{BTreeMap, BTreeSet};
1616

17-
use ruma::OwnedRoomId;
17+
use ruma::{OwnedRoomId, RoomId};
1818

1919
#[derive(Debug)]
2020
struct SpaceGraphNode {
@@ -51,14 +51,20 @@ impl SpaceGraph {
5151

5252
/// Returns the root nodes of the graph, which are nodes without any
5353
/// parents.
54-
pub(super) fn root_nodes(&self) -> Vec<&OwnedRoomId> {
55-
self.nodes.values().filter(|node| node.parents.is_empty()).map(|node| &node.id).collect()
54+
pub(super) fn root_nodes(&self) -> Vec<&RoomId> {
55+
self.nodes
56+
.values()
57+
.filter(|node| node.parents.is_empty())
58+
.map(|node| node.id.as_ref())
59+
.collect()
5660
}
5761

5862
/// Returns the children of a given node. If the node does not exist, it
5963
/// returns an empty vector.
60-
pub(super) fn children_of(&self, node_id: &OwnedRoomId) -> Vec<&OwnedRoomId> {
61-
self.nodes.get(node_id).map_or(vec![], |node| node.children.iter().collect())
64+
pub(super) fn children_of(&self, node_id: &RoomId) -> Vec<&RoomId> {
65+
self.nodes
66+
.get(node_id)
67+
.map_or(vec![], |node| node.children.iter().map(|id| id.as_ref()).collect())
6268
}
6369

6470
/// Adds a node to the graph. If the node already exists, it does nothing.

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

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -229,12 +229,12 @@ impl SpaceService {
229229
joined_spaces
230230
.iter()
231231
.filter_map(|room| {
232-
let room_id = room.room_id().to_owned();
232+
let room_id = room.room_id();
233233

234-
if root_nodes.contains(&&room_id) {
234+
if root_nodes.contains(&room_id) {
235235
Some(SpaceRoom::new_from_known(
236236
room.clone(),
237-
graph.children_of(&room_id).len() as u64,
237+
graph.children_of(room_id).len() as u64,
238238
))
239239
} else {
240240
None

0 commit comments

Comments
 (0)