mirror of
https://github.com/zed-industries/zed.git
synced 2025-02-07 02:57:34 +00:00
WIP
This commit is contained in:
parent
ff822c9158
commit
5b599a32b8
1 changed files with 48 additions and 5 deletions
|
@ -1,18 +1,26 @@
|
||||||
use crate::rpc::Client;
|
use crate::rpc::{self, Client};
|
||||||
use gpui::{Entity, ModelHandle, WeakModelHandle};
|
use anyhow::{anyhow, Result};
|
||||||
|
use gpui::{
|
||||||
|
AsyncAppContext, Entity, ModelContext, ModelHandle, MutableAppContext, WeakModelHandle,
|
||||||
|
};
|
||||||
use std::{
|
use std::{
|
||||||
collections::{HashMap, VecDeque},
|
collections::{HashMap, VecDeque},
|
||||||
sync::Arc,
|
sync::Arc,
|
||||||
};
|
};
|
||||||
|
use zrpc::{proto::ChannelMessageSent, ForegroundRouter, Router, TypedEnvelope};
|
||||||
|
|
||||||
pub struct ChannelList {
|
pub struct ChannelList {
|
||||||
|
available_channels: Vec<ChannelDetails>,
|
||||||
channels: HashMap<u64, WeakModelHandle<Channel>>,
|
channels: HashMap<u64, WeakModelHandle<Channel>>,
|
||||||
rpc: Arc<Client>,
|
rpc: Arc<Client>,
|
||||||
}
|
}
|
||||||
|
|
||||||
pub struct Channel {
|
pub struct ChannelDetails {
|
||||||
id: u64,
|
id: u64,
|
||||||
name: String,
|
name: String,
|
||||||
|
}
|
||||||
|
pub struct Channel {
|
||||||
|
details: ChannelDetails,
|
||||||
first_message_id: Option<u64>,
|
first_message_id: Option<u64>,
|
||||||
messages: Option<VecDeque<ChannelMessage>>,
|
messages: Option<VecDeque<ChannelMessage>>,
|
||||||
rpc: Arc<Client>,
|
rpc: Arc<Client>,
|
||||||
|
@ -21,11 +29,46 @@ pub struct Channel {
|
||||||
pub struct ChannelMessage {
|
pub struct ChannelMessage {
|
||||||
id: u64,
|
id: u64,
|
||||||
}
|
}
|
||||||
|
|
||||||
enum Event {}
|
enum Event {}
|
||||||
|
|
||||||
impl Entity for ChannelList {
|
impl Entity for ChannelList {
|
||||||
type Event = Event;
|
type Event = Event;
|
||||||
}
|
}
|
||||||
|
|
||||||
impl ChannelList {}
|
impl ChannelList {
|
||||||
|
fn new(
|
||||||
|
rpc: Arc<rpc::Client>,
|
||||||
|
router: &mut ForegroundRouter,
|
||||||
|
cx: &mut ModelContext<Self>,
|
||||||
|
) -> Self {
|
||||||
|
// Subscribe to messages.
|
||||||
|
let this = cx.handle().downgrade();
|
||||||
|
rpc.on_message(
|
||||||
|
router,
|
||||||
|
|envelope, rpc, cx: &mut AsyncAppContext| async move {
|
||||||
|
cx.update(|cx| {
|
||||||
|
if let Some(this) = this.upgrade(cx) {
|
||||||
|
this.update(cx, |this, cx| this.receive_message(envelope, cx))
|
||||||
|
} else {
|
||||||
|
Err(anyhow!("can't upgrade ChannelList handle"))
|
||||||
|
}
|
||||||
|
})
|
||||||
|
},
|
||||||
|
cx,
|
||||||
|
);
|
||||||
|
|
||||||
|
Self {
|
||||||
|
available_channels: Default::default(),
|
||||||
|
channels: Default::default(),
|
||||||
|
rpc,
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
fn receive_message(
|
||||||
|
&mut self,
|
||||||
|
envelope: TypedEnvelope<ChannelMessageSent>,
|
||||||
|
cx: &mut ModelContext<Self>,
|
||||||
|
) -> Result<()> {
|
||||||
|
Ok(())
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
Loading…
Reference in a new issue