From fd6320b136ab8d84a360ae3a5d3746ccd5467018 Mon Sep 17 00:00:00 2001 From: Julia Date: Tue, 12 Dec 2023 11:49:04 -0500 Subject: [PATCH] Finish fixing up Avatar using URI --- crates/client2/src/user.rs | 32 ++----------------- crates/collab_ui2/src/collab_panel.rs | 3 +- crates/collab_ui2/src/notification_panel.rs | 4 +-- .../incoming_call_notification.rs | 9 +----- .../project_shared_notification.rs | 7 +--- crates/ui2/src/components/avatar.rs | 3 +- 6 files changed, 10 insertions(+), 48 deletions(-) diff --git a/crates/client2/src/user.rs b/crates/client2/src/user.rs index 766861fbf8..b08d423cae 100644 --- a/crates/client2/src/user.rs +++ b/crates/client2/src/user.rs @@ -2,13 +2,12 @@ use super::{proto, Client, Status, TypedEnvelope}; use anyhow::{anyhow, Context, Result}; use collections::{hash_map::Entry, HashMap, HashSet}; use feature_flags::FeatureFlagAppExt; -use futures::{channel::mpsc, AsyncReadExt, Future, StreamExt}; -use gpui::{AsyncAppContext, EventEmitter, ImageData, Model, ModelContext, SharedString, Task}; +use futures::{channel::mpsc, Future, StreamExt}; +use gpui::{AsyncAppContext, EventEmitter, Model, ModelContext, SharedString, Task}; use postage::{sink::Sink, watch}; use rpc::proto::{RequestMessage, UsersResponse}; use std::sync::{Arc, Weak}; use text::ReplicaId; -use util::http::HttpClient; use util::TryFutureExt as _; pub type UserId = u64; @@ -111,10 +110,7 @@ enum UpdateContacts { } impl UserStore { - pub fn new( - client: Arc, - cx: &mut ModelContext, - ) -> Self { + pub fn new(client: Arc, cx: &mut ModelContext) -> Self { let (mut current_user_tx, current_user_rx) = watch::channel(); let (update_contacts_tx, mut update_contacts_rx) = mpsc::unbounded(); let rpc_subscriptions = vec![ @@ -696,25 +692,3 @@ impl Collaborator { }) } } - -// todo!("we probably don't need this now that we fetch") -async fn fetch_avatar(http: &dyn HttpClient, url: &str) -> Result> { - let mut response = http - .get(url, Default::default(), true) - .await - .map_err(|e| anyhow!("failed to send user avatar request: {}", e))?; - - if !response.status().is_success() { - return Err(anyhow!("avatar request failed {:?}", response.status())); - } - - let mut body = Vec::new(); - response - .body_mut() - .read_to_end(&mut body) - .await - .map_err(|e| anyhow!("failed to read user avatar response body: {}", e))?; - let format = image::guess_format(&body)?; - let image = image::load_from_memory_with_format(&body, format)?.into_bgra8(); - Ok(Arc::new(ImageData::new(image))) -} diff --git a/crates/collab_ui2/src/collab_panel.rs b/crates/collab_ui2/src/collab_panel.rs index bae1779d74..8967308dd3 100644 --- a/crates/collab_ui2/src/collab_panel.rs +++ b/crates/collab_ui2/src/collab_panel.rs @@ -19,6 +19,7 @@ mod contact_finder; use contact_finder::ContactFinder; use menu::{Cancel, Confirm, SelectNext, SelectPrev}; use rpc::proto::{self, PeerId}; +use smallvec::SmallVec; use theme::{ActiveTheme, ThemeSettings}; // use context_menu::{ContextMenu, ContextMenuItem}; // use db::kvp::KEY_VALUE_STORE; @@ -2543,7 +2544,7 @@ impl CollabPanel { } else { None }) - .collect::>(), + .collect::>(), }; Some(result) diff --git a/crates/collab_ui2/src/notification_panel.rs b/crates/collab_ui2/src/notification_panel.rs index 279c3cbd90..75c7cb3404 100644 --- a/crates/collab_ui2/src/notification_panel.rs +++ b/crates/collab_ui2/src/notification_panel.rs @@ -221,7 +221,7 @@ impl NotificationPanel { Some( h_stack() - .children(actor.map(|actor| Avatar::from(actor.avatar.clone()))) + .children(actor.map(|actor| Avatar::new(actor.avatar_uri.clone()))) .child( v_stack().child(Label::new(text)).child( h_stack() @@ -675,7 +675,7 @@ impl Render for NotificationToast { h_stack() .id("notification_panel_toast") - .children(user.and_then(|user| Some(img(user.avatar.clone()?)))) + .children(user.map(|user| Avatar::new(user.avatar_uri.clone()))) .child(Label::new(self.text.clone())) .child( IconButton::new("close", Icon::Close) diff --git a/crates/collab_ui2/src/notifications/incoming_call_notification.rs b/crates/collab_ui2/src/notifications/incoming_call_notification.rs index b277e6fe94..53ff51d1cd 100644 --- a/crates/collab_ui2/src/notifications/incoming_call_notification.rs +++ b/crates/collab_ui2/src/notifications/incoming_call_notification.rs @@ -114,14 +114,7 @@ impl IncomingCallNotification { } fn render_caller(&self, cx: &mut ViewContext) -> impl Element { h_stack() - .children( - self.state - .call - .calling_user - .avatar - .as_ref() - .map(|avatar| Avatar::data(avatar.clone())), - ) + .child(Avatar::new(self.state.call.calling_user.avatar_uri.clone())) .child( v_stack() .child(Label::new(format!( diff --git a/crates/collab_ui2/src/notifications/project_shared_notification.rs b/crates/collab_ui2/src/notifications/project_shared_notification.rs index c7e667e284..e130f09b16 100644 --- a/crates/collab_ui2/src/notifications/project_shared_notification.rs +++ b/crates/collab_ui2/src/notifications/project_shared_notification.rs @@ -119,12 +119,7 @@ impl ProjectSharedNotification { fn render_owner(&self) -> impl Element { h_stack() - .children( - self.owner - .avatar - .clone() - .map(|avatar| Avatar::data(avatar.clone())), - ) + .child(Avatar::new(self.owner.avatar_uri.clone())) .child( v_stack() .child(Label::new(self.owner.github_login.clone())) diff --git a/crates/ui2/src/components/avatar.rs b/crates/ui2/src/components/avatar.rs index 4162ee2256..33c8d71625 100644 --- a/crates/ui2/src/components/avatar.rs +++ b/crates/ui2/src/components/avatar.rs @@ -1,6 +1,5 @@ use crate::prelude::*; -use gpui::{img, Div, Hsla, ImageData, ImageSource, Img, IntoElement, Styled}; -use std::sync::Arc; +use gpui::{img, Div, Hsla, ImageSource, Img, IntoElement, Styled}; #[derive(Debug, Default, PartialEq, Clone)] pub enum Shape {