diff --git a/src/services/bluesky/client.rs b/src/services/bluesky/client.rs index cc50af1..4907c98 100644 --- a/src/services/bluesky/client.rs +++ b/src/services/bluesky/client.rs @@ -13,16 +13,10 @@ use futures::StreamExt; use log::error; use tokio_tungstenite::{connect_async, tungstenite}; -use super::entities::Session; +use super::entities::{ProfileDetails, Session}; use super::internals::xrpc::AuthenticateableXrpcClient; use super::streaming::{handle_message, CommitProcessor}; -#[derive(Debug)] -pub struct ProfileDetails { - pub display_name: String, - pub description: String, -} - pub struct Bluesky { client: AtpServiceClient>, session: Option>>, @@ -150,15 +144,10 @@ impl Bluesky { Err(e) => return Err(e.into()), }; - let profile = match profile_data.value { - Record::AppBskyActorProfile(profile) => profile, - _ => return Err(anyhow!("Big bad, no such profile")), - }; - - Ok(Some(ProfileDetails { - display_name: profile.display_name.unwrap_or_default(), - description: profile.description.unwrap_or_default(), - })) + match profile_data.value { + Record::AppBskyActorProfile(profile) => Ok(Some(ProfileDetails::from(*profile))), + _ => Err(anyhow!("Wrong type of record")), + } } pub async fn resolve_handle(&self, handle: &str) -> Result> { diff --git a/src/services/bluesky/entities.rs b/src/services/bluesky/entities.rs index e734a80..e2b101b 100644 --- a/src/services/bluesky/entities.rs +++ b/src/services/bluesky/entities.rs @@ -2,8 +2,10 @@ mod follow; mod like; mod post; mod session; +mod profile; pub use follow::FollowRecord; pub use like::LikeRecord; pub use post::PostRecord; pub use session::Session; +pub use profile::ProfileDetails; diff --git a/src/services/bluesky/entities/profile.rs b/src/services/bluesky/entities/profile.rs new file mode 100644 index 0000000..372c46f --- /dev/null +++ b/src/services/bluesky/entities/profile.rs @@ -0,0 +1,16 @@ +use atrium_api::app::bsky::actor::profile::Record as ProfileRecord; + +#[derive(Debug)] +pub struct ProfileDetails { + pub display_name: String, + pub description: String, +} + +impl From for ProfileDetails { + fn from(value: ProfileRecord) -> Self { + Self { + display_name: value.display_name.unwrap_or_default(), + description: value.description.unwrap_or_default() + } + } +}