Code at the speed of thought – Zed is a high-performance, multiplayer code editor from the creators of Atom and Tree-sitter.
Finish fixing up Avatar using URI
Juliafd6320b136ab
diff --git a/crates/client2/src/user.rs b/crates/client2/src/user.rsindex 766861fbf8e..b08d423cae0 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<Client>,- cx: &mut ModelContext<Self>,- ) -> Self {+ pub fn new(client: Arc<Client>, cx: &mut ModelContext<Self>) -> 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<Arc<ImageData>> {- 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.rsindex bae1779d74a..8967308dd33 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::<Vec<_>>(),+ .collect::<SmallVec<_>>(),};Some(result)diff --git a/crates/collab_ui2/src/notification_panel.rs b/crates/collab_ui2/src/notification_panel.rsindex 279c3cbd907..75c7cb34041 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.rsindex b277e6fe94a..53ff51d1cd8 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<Self>) -> 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.rsindex c7e667e2847..e130f09b166 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.rsindex 4162ee22563..33c8d716251 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 {