diff --git a/zed/src/channel.rs b/zed/src/channel.rs index c846999e8e..2ec8b8c2ac 100644 --- a/zed/src/channel.rs +++ b/zed/src/channel.rs @@ -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, channels: HashMap>, rpc: Arc, } -pub struct Channel { +pub struct ChannelDetails { id: u64, name: String, +} +pub struct Channel { + details: ChannelDetails, first_message_id: Option, messages: Option>, rpc: Arc, @@ -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, + router: &mut ForegroundRouter, + cx: &mut ModelContext, + ) -> 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, + cx: &mut ModelContext, + ) -> Result<()> { + Ok(()) + } +}