diff --git a/src/common/set_roles.rs b/src/common/set_roles.rs index 908e6d6..52836e1 100644 --- a/src/common/set_roles.rs +++ b/src/common/set_roles.rs @@ -363,28 +363,31 @@ pub mod committee { } let mut channel_names = vec![]; + let mut positions = vec![]; for role in roles_db.values() { // save these to db db_role_set(db, role).await; - // pull out teh channel names if re_order { - channel_names.push((role.name_channel.to_owned(), role.id_channel)); + let channel_id = role.id_channel.to_owned(); + if let Some(channel) = channels.get_mut(&channel_id) { + // record the position of each of teh C&S channels + positions.push(channel.position); + + // pull out teh channel names + channel_names.push((role.name_channel.to_owned(), channel_id)); + } } } if re_order { + // sort by the position and name + positions.sort(); channel_names.sort_by_key(|(name, _)| name.to_owned()); - // get a list of all teh new positions let mut new_positions = vec![]; for (i, (_, id)) in channel_names.iter().enumerate() { - if let Some(channel) = channels.get_mut(id) { - let position_new = i as u64; - if position_new != channel.position as u64 { - new_positions.push((channel.id.to_owned(), position_new)); - } - } + new_positions.push((id.to_owned(), positions[i] as u64)); } if !new_positions.is_empty() {