Set up UI to allow dragging a channel to the root
This commit is contained in:
parent
42259a4007
commit
32367eba14
10 changed files with 107 additions and 58 deletions
|
@ -1205,37 +1205,37 @@ impl Database {
|
|||
pub async fn move_channel(
|
||||
&self,
|
||||
channel_id: ChannelId,
|
||||
new_parent_id: ChannelId,
|
||||
new_parent_id: Option<ChannelId>,
|
||||
admin_id: UserId,
|
||||
) -> Result<Option<MoveChannelResult>> {
|
||||
// check you're an admin of source and target (and maybe current channel)
|
||||
// change parent_path on current channel
|
||||
// change parent_path on all children
|
||||
|
||||
self.transaction(|tx| async move {
|
||||
let Some(new_parent_id) = new_parent_id else {
|
||||
return Err(anyhow!("not supported"))?;
|
||||
};
|
||||
|
||||
let new_parent = self.get_channel_internal(new_parent_id, &*tx).await?;
|
||||
self.check_user_is_channel_admin(&new_parent, admin_id, &*tx)
|
||||
.await?;
|
||||
let channel = self.get_channel_internal(channel_id, &*tx).await?;
|
||||
|
||||
self.check_user_is_channel_admin(&channel, admin_id, &*tx)
|
||||
.await?;
|
||||
self.check_user_is_channel_admin(&new_parent, admin_id, &*tx)
|
||||
.await?;
|
||||
|
||||
let previous_participants = self
|
||||
.get_channel_participant_details_internal(&channel, &*tx)
|
||||
.await?;
|
||||
|
||||
let old_path = format!("{}{}/", channel.parent_path, channel.id);
|
||||
let new_parent_path = format!("{}{}/", new_parent.parent_path, new_parent_id);
|
||||
let new_parent_path = format!("{}{}/", new_parent.parent_path, new_parent.id);
|
||||
let new_path = format!("{}{}/", new_parent_path, channel.id);
|
||||
|
||||
if old_path == new_path {
|
||||
return Ok(None);
|
||||
}
|
||||
|
||||
let mut channel = channel.into_active_model();
|
||||
channel.parent_path = ActiveValue::Set(new_parent_path);
|
||||
channel.save(&*tx).await?;
|
||||
let mut model = channel.into_active_model();
|
||||
model.parent_path = ActiveValue::Set(new_parent_path);
|
||||
model.update(&*tx).await?;
|
||||
|
||||
let descendent_ids =
|
||||
ChannelId::find_by_statement::<QueryIds>(Statement::from_sql_and_values(
|
||||
|
@ -1250,7 +1250,7 @@ impl Database {
|
|||
.all(&*tx)
|
||||
.await?;
|
||||
|
||||
let participants_to_update: HashMap<UserId, ChannelsForUser> = self
|
||||
let participants_to_update: HashMap<_, _> = self
|
||||
.participants_to_notify_for_channel_change(&new_parent, &*tx)
|
||||
.await?
|
||||
.into_iter()
|
||||
|
|
|
@ -424,7 +424,7 @@ async fn test_db_channel_moving_bugs(db: &Arc<Database>) {
|
|||
|
||||
// Move to same parent should be a no-op
|
||||
assert!(db
|
||||
.move_channel(projects_id, zed_id, user_id)
|
||||
.move_channel(projects_id, Some(zed_id), user_id)
|
||||
.await
|
||||
.unwrap()
|
||||
.is_none());
|
||||
|
|
|
@ -2476,7 +2476,7 @@ async fn move_channel(
|
|||
session: Session,
|
||||
) -> Result<()> {
|
||||
let channel_id = ChannelId::from_proto(request.channel_id);
|
||||
let to = ChannelId::from_proto(request.to);
|
||||
let to = request.to.map(ChannelId::from_proto);
|
||||
|
||||
let result = session
|
||||
.db()
|
||||
|
|
|
@ -1016,7 +1016,7 @@ async fn test_channel_link_notifications(
|
|||
client_a
|
||||
.channel_store()
|
||||
.update(cx_a, |channel_store, cx| {
|
||||
channel_store.move_channel(vim_channel, active_channel, cx)
|
||||
channel_store.move_channel(vim_channel, Some(active_channel), cx)
|
||||
})
|
||||
.await
|
||||
.unwrap();
|
||||
|
@ -1051,7 +1051,7 @@ async fn test_channel_link_notifications(
|
|||
client_a
|
||||
.channel_store()
|
||||
.update(cx_a, |channel_store, cx| {
|
||||
channel_store.move_channel(helix_channel, vim_channel, cx)
|
||||
channel_store.move_channel(helix_channel, Some(vim_channel), cx)
|
||||
})
|
||||
.await
|
||||
.unwrap();
|
||||
|
@ -1424,7 +1424,7 @@ async fn test_channel_moving(
|
|||
client_a
|
||||
.channel_store()
|
||||
.update(cx_a, |channel_store, cx| {
|
||||
channel_store.move_channel(channel_d_id, channel_b_id, cx)
|
||||
channel_store.move_channel(channel_d_id, Some(channel_b_id), cx)
|
||||
})
|
||||
.await
|
||||
.unwrap();
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue