mirror of
https://github.com/zed-industries/zed.git
synced 2025-01-30 14:17:02 +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 gpui::{Entity, ModelHandle, WeakModelHandle};
|
||||
use crate::rpc::{self, Client};
|
||||
use anyhow::{anyhow, Result};
|
||||
use gpui::{
|
||||
AsyncAppContext, Entity, ModelContext, ModelHandle, MutableAppContext, WeakModelHandle,
|
||||
};
|
||||
use std::{
|
||||
collections::{HashMap, VecDeque},
|
||||
sync::Arc,
|
||||
};
|
||||
use zrpc::{proto::ChannelMessageSent, ForegroundRouter, Router, TypedEnvelope};
|
||||
|
||||
pub struct ChannelList {
|
||||
available_channels: Vec<ChannelDetails>,
|
||||
channels: HashMap<u64, WeakModelHandle<Channel>>,
|
||||
rpc: Arc<Client>,
|
||||
}
|
||||
|
||||
pub struct Channel {
|
||||
pub struct ChannelDetails {
|
||||
id: u64,
|
||||
name: String,
|
||||
}
|
||||
pub struct Channel {
|
||||
details: ChannelDetails,
|
||||
first_message_id: Option<u64>,
|
||||
messages: Option<VecDeque<ChannelMessage>>,
|
||||
rpc: Arc<Client>,
|
||||
|
@ -21,11 +29,46 @@ pub struct Channel {
|
|||
pub struct ChannelMessage {
|
||||
id: u64,
|
||||
}
|
||||
|
||||
enum Event {}
|
||||
|
||||
impl Entity for ChannelList {
|
||||
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