Finish fixing up Avatar using URI

Julia created

Change summary

crates/client2/src/user.rs                                         | 32 
crates/collab_ui2/src/collab_panel.rs                              |  3 
crates/collab_ui2/src/notification_panel.rs                        |  4 
crates/collab_ui2/src/notifications/incoming_call_notification.rs  |  9 
crates/collab_ui2/src/notifications/project_shared_notification.rs |  7 
crates/ui2/src/components/avatar.rs                                |  3 
6 files changed, 10 insertions(+), 48 deletions(-)

Detailed changes

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)))
-}

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)

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)

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!(

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()))

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 {