From af6e931da7ab88df95fc6d010f1ad87da6e5ce6b Mon Sep 17 00:00:00 2001 From: Antonio Scandurra Date: Wed, 8 Sep 2021 15:58:16 +0200 Subject: [PATCH] Start on a `Client::status` method that can be observed --- server/src/rpc.rs | 2 +- zed/src/channel.rs | 21 ++++----- zed/src/chat_panel.rs | 30 +++++++----- zed/src/rpc.rs | 105 +++++++++++++++++++++++++++++++----------- zrpc/src/peer.rs | 5 ++ 5 files changed, 111 insertions(+), 52 deletions(-) diff --git a/server/src/rpc.rs b/server/src/rpc.rs index 34f5f378d931e5ddbedca9f4e2a98a0709da329c..7562bdf74b7f687ed968bd97ed36f99c4978c4a9 100644 --- a/server/src/rpc.rs +++ b/server/src/rpc.rs @@ -1714,7 +1714,7 @@ mod tests { ) .detach(); client - .add_connection(user_id.to_proto(), client_conn, &cx.to_async()) + .set_connection(user_id.to_proto(), client_conn, &cx.to_async()) .await .unwrap(); (user_id, client) diff --git a/zed/src/channel.rs b/zed/src/channel.rs index 24997d49642648e5fc59c301270346cb75007a3b..38329c70d4bf39968df533b53ec8c22fa2c48d09 100644 --- a/zed/src/channel.rs +++ b/zed/src/channel.rs @@ -90,18 +90,15 @@ impl ChannelList { let _task = cx.spawn(|this, mut cx| { let rpc = rpc.clone(); async move { - let mut user_id = rpc.user_id(); + let mut status = rpc.status(); loop { - let available_channels = if user_id.recv().await.unwrap().is_some() { - Some( - rpc.request(proto::GetChannels {}) - .await - .context("failed to fetch available channels")? - .channels - .into_iter() - .map(Into::into) - .collect(), - ) + let status = status.recv().await.unwrap(); + let available_channels = if matches!(status, rpc::Status::Connected { .. }) { + let response = rpc + .request(proto::GetChannels {}) + .await + .context("failed to fetch available channels")?; + Some(response.channels.into_iter().map(Into::into).collect()) } else { None }; @@ -671,7 +668,7 @@ mod tests { cx.background().spawn(io).detach(); client - .add_connection(user_id, client_conn, &cx.to_async()) + .set_connection(user_id, client_conn, &cx.to_async()) .await .unwrap(); diff --git a/zed/src/chat_panel.rs b/zed/src/chat_panel.rs index 18b737b2d89eda1378e7eded84966de10add8511..ab38f64169731975c598dbac8975435a8b2520c9 100644 --- a/zed/src/chat_panel.rs +++ b/zed/src/chat_panel.rs @@ -3,7 +3,7 @@ use std::sync::Arc; use crate::{ channel::{Channel, ChannelEvent, ChannelList, ChannelMessage}, editor::Editor, - rpc::Client, + rpc::{self, Client}, theme, util::{ResultExt, TryFutureExt}, Settings, @@ -14,10 +14,10 @@ use gpui::{ keymap::Binding, platform::CursorStyle, views::{ItemType, Select, SelectStyle}, - AppContext, Entity, ModelHandle, MutableAppContext, RenderContext, Subscription, View, + AppContext, Entity, ModelHandle, MutableAppContext, RenderContext, Subscription, Task, View, ViewContext, ViewHandle, }; -use postage::watch; +use postage::{prelude::Stream, watch}; use time::{OffsetDateTime, UtcOffset}; const MESSAGE_LOADING_THRESHOLD: usize = 50; @@ -31,6 +31,7 @@ pub struct ChatPanel { channel_select: ViewHandle