Move profile details model into entities too

This commit is contained in:
Aleksei Voronov 2023-10-15 19:59:05 +02:00
parent e1baeffc6e
commit fddcf7272c
3 changed files with 23 additions and 16 deletions

View File

@ -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<AtpServiceWrapper<AuthenticateableXrpcClient>>,
session: Option<Arc<Mutex<Session>>>,
@ -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<Option<String>> {

View File

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

View File

@ -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<ProfileRecord> for ProfileDetails {
fn from(value: ProfileRecord) -> Self {
Self {
display_name: value.display_name.unwrap_or_default(),
description: value.description.unwrap_or_default()
}
}
}