unique channel names (#8439)

Conrad Irwin created

Before this change duplicate channels were ordered arbitrarily, which
put the
collab channel in an inconsistent state.

Release Notes:

- Fixed duplicate channel names appearing in the collab sidebar.

Change summary

crates/channel/src/channel_store/channel_index.rs                | 9 +
crates/collab/migrations/20240226164505_unique_channel_names.sql | 3 
2 files changed, 9 insertions(+), 3 deletions(-)

Detailed changes

crates/channel/src/channel_store/channel_index.rs 🔗

@@ -94,14 +94,17 @@ impl<'a> Drop for ChannelPathsInsertGuard<'a> {
 fn channel_path_sorting_key<'a>(
     id: ChannelId,
     channels_by_id: &'a BTreeMap<ChannelId, Arc<Channel>>,
-) -> impl Iterator<Item = &str> {
+) -> impl Iterator<Item = (&str, u64)> {
     let (parent_path, name) = channels_by_id
         .get(&id)
         .map_or((&[] as &[_], None), |channel| {
-            (channel.parent_path.as_slice(), Some(channel.name.as_ref()))
+            (
+                channel.parent_path.as_slice(),
+                Some((channel.name.as_ref(), channel.id)),
+            )
         });
     parent_path
         .iter()
-        .filter_map(|id| Some(channels_by_id.get(id)?.name.as_ref()))
+        .filter_map(|id| Some((channels_by_id.get(id)?.name.as_ref(), *id)))
         .chain(name)
 }