From cacef6e029c662073b1d33a1f399b0b92d013f3e Mon Sep 17 00:00:00 2001 From: alemi Date: Thu, 21 Mar 2024 02:50:48 +0100 Subject: [PATCH] fix: oops mixed preferred_username and name --- src/model/mod.rs | 4 ++-- src/model/user.rs | 26 +++++++++++++------------- 2 files changed, 15 insertions(+), 15 deletions(-) diff --git a/src/model/mod.rs b/src/model/mod.rs index 4ef7afd3..9e700225 100644 --- a/src/model/mod.rs +++ b/src/model/mod.rs @@ -15,9 +15,9 @@ pub async fn faker(db: &sea_orm::DatabaseConnection, domain: String) -> Result<( let root = user::Model { id: format!("{domain}/users/root"), - name: "root".into(), + name: Some("Administrator".into()), domain: crate::activitypub::domain(&domain), - preferred_username: Some("Administrator".to_string()), + preferred_username: "root".to_string(), summary: Some("hello world! i'm manually generated but served dynamically from db!".to_string()), following: None, followers: None, diff --git a/src/model/user.rs b/src/model/user.rs index 706a5872..2f958a5a 100644 --- a/src/model/user.rs +++ b/src/model/user.rs @@ -12,13 +12,13 @@ pub struct Model { pub id: String, pub domain: String, pub actor_type: ActorType, + pub preferred_username: String, - pub name: String, + pub name: Option, pub summary: Option, pub image: Option, pub icon: Option, - pub preferred_username: Option, pub inbox: Option, pub shared_inbox: Option, pub outbox: Option, @@ -74,11 +74,11 @@ impl crate::activitystream::Base for Model { crate::activitystream::object() .set_id(Some(&self.id)) .set_actor_type(Some(self.actor_type)) - .set_name(Some(&self.name)) + .set_name(self.name.as_deref()) .set_summary(self.summary.as_deref()) .set_icon(self.icon()) .set_image(self.image()) - .set_preferred_username(self.preferred_username.as_deref()) + .set_preferred_username(Some(&self.preferred_username)) .set_inbox(self.inbox()) .set_outbox(self.outbox()) .set_following(self.following()) @@ -92,7 +92,7 @@ impl crate::activitystream::Base for Model { impl crate::activitystream::object::Object for Model { fn name(&self) -> Option<&str> { - Some(&self.name) + self.name.as_deref() } fn summary(&self) -> Option<&str> { @@ -132,23 +132,23 @@ impl crate::activitystream::object::actor::Actor for Model { } fn preferred_username(&self) -> Option<&str> { - self.preferred_username.as_deref() + Some(&self.preferred_username) } fn inbox(&self) -> Node { - Node::link(self.inbox.clone().unwrap_or(format!("https://{}/users/{}/inbox", self.domain, self.name))) + Node::link(self.inbox.clone().unwrap_or(format!("https://{}/users/{}/inbox", self.domain, self.preferred_username))) } fn outbox(&self) -> Node { - Node::link(self.outbox.clone().unwrap_or(format!("https://{}/users/{}/outbox", self.domain, self.name))) + Node::link(self.outbox.clone().unwrap_or(format!("https://{}/users/{}/outbox", self.domain, self.preferred_username))) } fn following(&self) -> Node { - Node::link(self.following.clone().unwrap_or(format!("https://{}/users/{}/following", self.domain, self.name))) + Node::link(self.following.clone().unwrap_or(format!("https://{}/users/{}/following", self.domain, self.preferred_username))) } fn followers(&self) -> Node { - Node::link(self.following.clone().unwrap_or(format!("https://{}/users/{}/followers", self.domain, self.name))) + Node::link(self.following.clone().unwrap_or(format!("https://{}/users/{}/followers", self.domain, self.preferred_username))) } fn public_key(&self) -> Node { @@ -164,11 +164,11 @@ impl crate::activitystream::object::actor::Actor for Model { impl Model { pub fn new(object: &impl Actor) -> Result { let ap_id = object.id().ok_or(super::FieldError("id"))?.to_string(); - let (domain, name) = activitypub::split_id(&ap_id); + let (domain, preferred_username) = activitypub::split_id(&ap_id); Ok(Model { - id: ap_id, name, domain, + id: ap_id, preferred_username, domain, actor_type: object.actor_type().ok_or(super::FieldError("type"))?, - preferred_username: object.preferred_username().map(|x| x.to_string()), + name: object.name().map(|x| x.to_string()), summary: object.summary().map(|x| x.to_string()), icon: object.icon().id().map(|x| x.to_string()), image: object.image().id().map(|x| x.to_string()),