Add hover styles to channels matching the current selection

Fix chat desync from moving / linking channels
This commit is contained in:
Mikayla 2023-09-19 17:48:43 -07:00
parent d5f0ce0e20
commit ac65e7590c
No known key found for this signature in database
8 changed files with 284 additions and 94 deletions

View file

@ -146,17 +146,26 @@ impl ChannelStore {
})
}
/// Returns the number of unique channels in the store
pub fn channel_count(&self) -> usize {
self.channel_index.len()
self.channel_index.by_id().len()
}
/// Returns the index of a channel ID in the list of unique channels
pub fn index_of_channel(&self, channel_id: ChannelId) -> Option<usize> {
self.channel_index
.iter()
.position(|path| path.ends_with(&[channel_id]))
.by_id()
.keys()
.position(|id| *id == channel_id)
}
pub fn channels(&self) -> impl '_ + Iterator<Item = (usize, &Arc<Channel>)> {
/// Returns an iterator over all unique channels
pub fn channels(&self) -> impl '_ + Iterator<Item = &Arc<Channel>> {
self.channel_index.by_id().values()
}
/// Iterate over all entries in the channel DAG
pub fn channel_dag_entries(&self) -> impl '_ + Iterator<Item = (usize, &Arc<Channel>)> {
self.channel_index.iter().map(move |path| {
let id = path.last().unwrap();
let channel = self.channel_for_id(*id).unwrap();
@ -164,7 +173,7 @@ impl ChannelStore {
})
}
pub fn channel_at_index(&self, ix: usize) -> Option<(&Arc<Channel>, &ChannelPath)> {
pub fn channel_dag_entry_at(&self, ix: usize) -> Option<(&Arc<Channel>, &ChannelPath)> {
let path = self.channel_index.get(ix)?;
let id = path.last().unwrap();
let channel = self.channel_for_id(*id).unwrap();
@ -172,6 +181,10 @@ impl ChannelStore {
Some((channel, path))
}
pub fn channel_at(&self, ix: usize) -> Option<&Arc<Channel>> {
self.channel_index.by_id().values().nth(ix)
}
pub fn channel_invitations(&self) -> &[Arc<Channel>] {
&self.channel_invitations
}

View file

@ -1,7 +1,7 @@
use std::{ops::Deref, sync::Arc};
use crate::{Channel, ChannelId};
use collections::HashMap;
use collections::BTreeMap;
use rpc::proto;
use super::ChannelPath;
@ -9,11 +9,11 @@ use super::ChannelPath;
#[derive(Default, Debug)]
pub struct ChannelIndex {
paths: Vec<ChannelPath>,
channels_by_id: HashMap<ChannelId, Arc<Channel>>,
channels_by_id: BTreeMap<ChannelId, Arc<Channel>>,
}
impl ChannelIndex {
pub fn by_id(&self) -> &HashMap<ChannelId, Arc<Channel>> {
pub fn by_id(&self) -> &BTreeMap<ChannelId, Arc<Channel>> {
&self.channels_by_id
}
@ -53,7 +53,7 @@ impl Deref for ChannelIndex {
#[derive(Debug)]
pub struct ChannelPathsInsertGuard<'a> {
paths: &'a mut Vec<ChannelPath>,
channels_by_id: &'a mut HashMap<ChannelId, Arc<Channel>>,
channels_by_id: &'a mut BTreeMap<ChannelId, Arc<Channel>>,
}
impl<'a> ChannelPathsInsertGuard<'a> {
@ -155,7 +155,7 @@ impl<'a> Drop for ChannelPathsInsertGuard<'a> {
fn channel_path_sorting_key<'a>(
path: &'a [ChannelId],
channels_by_id: &'a HashMap<ChannelId, Arc<Channel>>,
channels_by_id: &'a BTreeMap<ChannelId, Arc<Channel>>,
) -> impl 'a + Iterator<Item = Option<&'a str>> {
path.iter()
.map(|id| Some(channels_by_id.get(id)?.name.as_str()))

View file

@ -181,7 +181,7 @@ async fn test_channel_messages(cx: &mut TestAppContext) {
// Join a channel and populate its existing messages.
let channel = channel_store.update(cx, |store, cx| {
let channel_id = store.channels().next().unwrap().1.id;
let channel_id = store.channel_dag_entries().next().unwrap().1.id;
store.open_channel_chat(channel_id, cx)
});
let join_channel = server.receive::<proto::JoinChannelChat>().await.unwrap();
@ -363,7 +363,7 @@ fn assert_channels(
) {
let actual = channel_store.read_with(cx, |store, _| {
store
.channels()
.channel_dag_entries()
.map(|(depth, channel)| {
(
depth,