Skip to content

Commit

Permalink
Merge pull request #452 from zed-industries/no-message-order
Browse files Browse the repository at this point in the history
Relax ordering constraints for low-priority messages
  • Loading branch information
as-cii committed Feb 17, 2022
2 parents 90576cf + 985d216 commit 4a6713a
Show file tree
Hide file tree
Showing 36 changed files with 2,802 additions and 1,421 deletions.
26 changes: 15 additions & 11 deletions crates/chat_panel/src/chat_panel.rs
Original file line number Diff line number Diff line change
Expand Up @@ -325,17 +325,21 @@ impl ChatPanel {
enum SignInPromptLabel {}

Align::new(
MouseEventHandler::new::<SignInPromptLabel, _, _, _>(0, cx, |mouse_state, _| {
Label::new(
"Sign in to use chat".to_string(),
if mouse_state.hovered {
theme.chat_panel.hovered_sign_in_prompt.clone()
} else {
theme.chat_panel.sign_in_prompt.clone()
},
)
.boxed()
})
MouseEventHandler::new::<SignInPromptLabel, _, _, _>(
cx.view_id(),
cx,
|mouse_state, _| {
Label::new(
"Sign in to use chat".to_string(),
if mouse_state.hovered {
theme.chat_panel.hovered_sign_in_prompt.clone()
} else {
theme.chat_panel.sign_in_prompt.clone()
},
)
.boxed()
},
)
.with_cursor_style(CursorStyle::PointingHand)
.on_click(move |cx| {
let rpc = rpc.clone();
Expand Down
17 changes: 15 additions & 2 deletions crates/client/src/channel.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ use super::{
Client, Status, Subscription, TypedEnvelope,
};
use anyhow::{anyhow, Context, Result};
use futures::lock::Mutex;
use gpui::{
AsyncAppContext, Entity, ModelContext, ModelHandle, MutableAppContext, Task, WeakModelHandle,
};
Expand Down Expand Up @@ -40,6 +41,7 @@ pub struct Channel {
next_pending_message_id: usize,
user_store: ModelHandle<UserStore>,
rpc: Arc<Client>,
outgoing_messages_lock: Arc<Mutex<()>>,
rng: StdRng,
_subscription: Subscription,
}
Expand Down Expand Up @@ -178,14 +180,17 @@ impl Entity for Channel {
}

impl Channel {
pub fn init(rpc: &Arc<Client>) {
rpc.add_entity_message_handler(Self::handle_message_sent);
}

pub fn new(
details: ChannelDetails,
user_store: ModelHandle<UserStore>,
rpc: Arc<Client>,
cx: &mut ModelContext<Self>,
) -> Self {
let _subscription =
rpc.add_entity_message_handler(details.id, cx, Self::handle_message_sent);
let _subscription = rpc.add_model_for_remote_entity(details.id, cx);

{
let user_store = user_store.clone();
Expand Down Expand Up @@ -214,6 +219,7 @@ impl Channel {
details,
user_store,
rpc,
outgoing_messages_lock: Default::default(),
messages: Default::default(),
loaded_all_messages: false,
next_pending_message_id: 0,
Expand Down Expand Up @@ -259,13 +265,16 @@ impl Channel {
);
let user_store = self.user_store.clone();
let rpc = self.rpc.clone();
let outgoing_messages_lock = self.outgoing_messages_lock.clone();
Ok(cx.spawn(|this, mut cx| async move {
let outgoing_message_guard = outgoing_messages_lock.lock().await;
let request = rpc.request(proto::SendChannelMessage {
channel_id,
body,
nonce: Some(nonce.into()),
});
let response = request.await?;
drop(outgoing_message_guard);
let message = ChannelMessage::from_proto(
response.message.ok_or_else(|| anyhow!("invalid message"))?,
&user_store,
Expand Down Expand Up @@ -589,10 +598,14 @@ mod tests {

#[gpui::test]
async fn test_channel_messages(mut cx: TestAppContext) {
cx.foreground().forbid_parking();

let user_id = 5;
let http_client = FakeHttpClient::new(|_| async move { Ok(Response::new(404)) });
let mut client = Client::new(http_client.clone());
let server = FakeServer::for_client(user_id, &mut client, &cx).await;

Channel::init(&client);
let user_store = cx.add_model(|cx| UserStore::new(client.clone(), http_client, cx));

let channel_list = cx.add_model(|cx| ChannelList::new(user_store, client.clone(), cx));
Expand Down
Loading

0 comments on commit 4a6713a

Please sign in to comment.