diff --git a/src/auth.rs b/src/auth.rs index 43bedaa..f246419 100644 --- a/src/auth.rs +++ b/src/auth.rs @@ -67,6 +67,7 @@ mod tests { #[test] fn remote_sign_out_clears_session_and_adds_toast() { let mut session = SessionIdentity::Authenticated(crate::session::AuthenticatedIdentity { + avatar: None, did: Did::new_owned("did:plc:alice").unwrap(), handle: Handle::new_owned("alice.test").unwrap(), display_name: None, diff --git a/src/session.rs b/src/session.rs index 79d7abe..28c4de1 100644 --- a/src/session.rs +++ b/src/session.rs @@ -1,5 +1,5 @@ use jacquard_common::deps::smol_str::{SmolStr, ToSmolStr}; -use jacquard_common::types::string::{Did, Handle}; +use jacquard_common::types::string::{Did, Handle, UriValue}; use polymodel_api::space_polymodel::actor::ProfileView; use polymodel_api::space_polymodel::actor::get_session::{GetSessionOutput, SessionView}; #[derive(Clone, Debug, Default, PartialEq, Eq)] @@ -11,6 +11,7 @@ pub enum SessionIdentity { #[derive(Clone, Debug, PartialEq, Eq)] pub struct AuthenticatedIdentity { + pub avatar: Option, pub did: Did, pub handle: Handle, pub display_name: Option, @@ -21,7 +22,9 @@ impl SessionIdentity { match output.value { SessionView::SessionUnauthenticated(_) => Self::Anonymous, SessionView::SessionAuthenticated(session) => { + let avatar = session.profile.avatar.clone(); Self::Authenticated(AuthenticatedIdentity { + avatar, did: session.did, handle: session.handle, display_name: profile_display_name(&session.profile), @@ -106,6 +109,44 @@ mod tests { assert_eq!(identity.label(), "Alice Maker"); } #[test] + fn authenticated_get_session_retains_avatar() { + let output = GetSessionOutput { + value: SessionView::SessionAuthenticated(Box::new(SessionAuthenticated { + did: Did::new_owned("did:plc:bob").unwrap(), + handle: Handle::new_owned("bob.test").unwrap(), + profile: ProfileView { + avatar: Some(UriValue::new_owned("https://cdn.example/bob.jpg").unwrap()), + default_license: None, + indexed_at: None, + description: None, + did: Did::new_owned("did:plc:bob").unwrap(), + display_name: None, + handle: "bob.test".into(), + pronouns: None, + thing_count: None, + extra_data: None, + links: None, + printers: None, + record: jacquard::Data::Null, + total_likes: None, + }, + extra_data: None, + authenticated: true, + })), + extra_data: None, + }; + + match SessionIdentity::from_get_session(output) { + SessionIdentity::Authenticated(identity) => { + assert_eq!( + identity.avatar.as_ref().map(AsRef::as_ref), + Some("https://cdn.example/bob.jpg") + ); + } + _ => panic!("expected authenticated identity"), + } + } + #[test] fn get_session_json_decodes_unauthenticated_union_arm() { let output: GetSessionOutput = serde_json::from_str(r#"{"$type":"space.polymodel.actor.getSession#sessionUnauthenticated","authenticated":false}"#).unwrap(); assert_eq!(