Finish fixing up Avatar using URI

This commit is contained in:
Julia 2023-12-12 11:49:04 -05:00
parent 44d40625fe
commit fd6320b136
6 changed files with 10 additions and 48 deletions

View file

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

View file

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

View file

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

View file

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

View file

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

View file

@ -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 {