Improve database and RPC API for moving and linking channels, improve test legibility

This commit is contained in:
Mikayla 2023-09-09 18:20:14 -07:00
parent 439f627d9a
commit cda54b8b5f
No known key found for this signature in database
8 changed files with 521 additions and 531 deletions

View file

@ -133,7 +133,7 @@ impl ChannelStore {
}
pub fn index_of_channel(&self, channel_id: ChannelId) -> Option<usize> {
self.channel_paths
self.channel_index
.iter()
.position(|path| path.ends_with(&[channel_id]))
}
@ -327,11 +327,43 @@ impl ChannelStore {
})
}
pub fn link_channel(
&mut self,
channel_id: ChannelId,
to: ChannelId,
cx: &mut ModelContext<Self>,
) -> Task<Result<()>> {
let client = self.client.clone();
cx.spawn(|_, _| async move {
let _ = client
.request(proto::LinkChannel { channel_id, to })
.await?;
Ok(())
})
}
pub fn unlink_channel(
&mut self,
channel_id: ChannelId,
from: Option<ChannelId>,
cx: &mut ModelContext<Self>,
) -> Task<Result<()>> {
let client = self.client.clone();
cx.spawn(|_, _| async move {
let _ = client
.request(proto::UnlinkChannel { channel_id, from })
.await?;
Ok(())
})
}
pub fn move_channel(
&mut self,
channel_id: ChannelId,
from_parent: Option<ChannelId>,
to: Option<ChannelId>,
from: Option<ChannelId>,
to: ChannelId,
cx: &mut ModelContext<Self>,
) -> Task<Result<()>> {
let client = self.client.clone();
@ -339,7 +371,7 @@ impl ChannelStore {
let _ = client
.request(proto::MoveChannel {
channel_id,
from_parent,
from,
to,
})
.await?;
@ -802,6 +834,4 @@ impl ChannelStore {
anyhow::Ok(())
}))
}
}