Change summary
crates/channel/src/channel_store.rs | 5 +--
crates/channel/src/channel_store/channel_index.rs | 22 ++++++++++------
crates/collab_ui/src/collab_panel.rs | 3 +
3 files changed, 17 insertions(+), 13 deletions(-)
Detailed changes
@@ -146,13 +146,12 @@ impl ChannelStore {
})
}
- pub fn channel_at_index(&self, ix: usize) -> Option<(usize, &Arc<Channel>, &Arc<[ChannelId]>)> {
+ pub fn channel_at_index(&self, ix: usize) -> Option<(&Arc<Channel>, &Arc<[ChannelId]>)> {
let path = self.channel_index.get(ix)?;
let id = path.last().unwrap();
let channel = self.channel_for_id(*id).unwrap();
-
- Some((path.len() - 1, channel, path))
+ Some((channel, path))
}
pub fn channel_invitations(&self) -> &[Arc<Channel>] {
@@ -1,4 +1,4 @@
-use std::{ops::Deref, sync::Arc};
+use std::sync::Arc;
use collections::HashMap;
use rpc::proto;
@@ -25,6 +25,18 @@ impl ChannelIndex {
self.channels_by_id.clear();
}
+ pub fn len(&self) -> usize {
+ self.paths.len()
+ }
+
+ pub fn get(&self, idx: usize) -> Option<&ChannelPath> {
+ self.paths.get(idx)
+ }
+
+ pub fn iter(&self) -> impl Iterator<Item = &ChannelPath> {
+ self.paths.iter()
+ }
+
/// Remove the given edge from this index. This will not remove the channel
/// and may result in dangling channels.
pub fn delete_edge(&mut self, parent_id: ChannelId, channel_id: ChannelId) {
@@ -50,14 +62,6 @@ impl ChannelIndex {
}
}
-impl Deref for ChannelIndex {
- type Target = Vec<ChannelPath>;
-
- fn deref(&self) -> &Self::Target {
- &self.paths
- }
-}
-
/// A guard for ensuring that the paths index maintains its sort and uniqueness
/// invariants after a series of insertions
pub struct ChannelPathsUpsertGuard<'a> {
@@ -785,8 +785,9 @@ impl CollabPanel {
}
let mut collapse_depth = None;
for mat in matches {
- let (depth, channel, path) =
+ let (channel, path) =
channel_store.channel_at_index(mat.candidate_id).unwrap();
+ let depth = path.len() - 1;
let location: ChannelLocation<'_> = (channel.id, path).into();