diff --git a/crates/apub/src/extensions/person_extension.rs b/crates/apub/src/extensions/person_extension.rs index 4294bc8f8..248adcc43 100644 --- a/crates/apub/src/extensions/person_extension.rs +++ b/crates/apub/src/extensions/person_extension.rs @@ -9,18 +9,11 @@ use serde::{Deserialize, Serialize}; #[serde(rename_all = "camelCase")] pub struct PersonExtension { pub matrix_user_id: Option, - pub bot_account: bool, } impl PersonExtension { - pub fn new( - matrix_user_id: Option, - bot_account: bool, - ) -> Result { - Ok(PersonExtension { - matrix_user_id, - bot_account, - }) + pub fn new(matrix_user_id: Option) -> Result { + Ok(PersonExtension { matrix_user_id }) } } @@ -33,13 +26,11 @@ where fn try_from_unparsed(unparsed_mut: &mut U) -> Result { Ok(PersonExtension { matrix_user_id: unparsed_mut.remove("matrix_user_id")?, - bot_account: unparsed_mut.remove("bot_account")?, }) } fn try_into_unparsed(self, unparsed_mut: &mut U) -> Result<(), Self::Error> { unparsed_mut.insert("matrix_user_id", self.matrix_user_id)?; - unparsed_mut.insert("bot_account", self.bot_account)?; Ok(()) } } diff --git a/crates/apub/src/lib.rs b/crates/apub/src/lib.rs index 8dd35ea3d..7271dc7b6 100644 --- a/crates/apub/src/lib.rs +++ b/crates/apub/src/lib.rs @@ -46,11 +46,18 @@ use url::{ParseError, Url}; /// Activitystreams type for community type GroupExt = Ext2>, GroupExtension, PublicKeyExtension>; /// Activitystreams type for person -type PersonExt = Ext2>, PersonExtension, PublicKeyExtension>; +type PersonExt = + Ext2>>, PersonExtension, PublicKeyExtension>; /// Activitystreams type for post pub type PageExt = Ext1, PageExtension>; pub type NoteExt = ApObject; +#[derive(Clone, Copy, Debug, serde::Deserialize, serde::Serialize, PartialEq)] +pub enum UserTypes { + Person, + Service, +} + pub static APUB_JSON_CONTENT_TYPE: &str = "application/activity+json"; /// Checks if the ID is allowed for sending or receiving. diff --git a/crates/apub/src/objects/person.rs b/crates/apub/src/objects/person.rs index ead0ee1b4..7622b4608 100644 --- a/crates/apub/src/objects/person.rs +++ b/crates/apub/src/objects/person.rs @@ -10,11 +10,12 @@ use crate::{ }, ActorType, PersonExt, + UserTypes, }; use activitystreams::{ - actor::{ApActor, Endpoints, Person}, - object::{ApObject, Image, Tombstone}, - prelude::*, + actor::{Actor, ApActor, ApActorExt, Endpoints}, + base::{BaseExt, ExtendsExt}, + object::{ApObject, Image, Object, ObjectExt, Tombstone}, }; use activitystreams_ext::Ext2; use anyhow::Context; @@ -38,7 +39,16 @@ impl ToApub for DbPerson { type ApubType = PersonExt; async fn to_apub(&self, _pool: &DbPool) -> Result { - let mut person = ApObject::new(Person::new()); + let object = Object::::new_none_type(); + let mut actor = Actor(object); + let kind = if self.bot_account { + UserTypes::Service + } else { + UserTypes::Person + }; + actor.set_kind(kind); + let mut person = ApObject::new(actor); + person .set_many_contexts(lemmy_context()?) .set_id(self.actor_id.to_owned().into_inner()) @@ -78,8 +88,7 @@ impl ToApub for DbPerson { ..Default::default() }); - let person_ext = - PersonExtension::new(self.matrix_user_id.to_owned(), self.bot_account.to_owned())?; + let person_ext = PersonExtension::new(self.matrix_user_id.to_owned())?; Ok(Ext2::new(ap_actor, person_ext, self.get_public_key_ext()?)) } fn to_tombstone(&self) -> Result { @@ -133,6 +142,8 @@ impl FromApubToForm for PersonForm { _request_counter: &mut i32, _mod_action_allowed: bool, ) -> Result { + dbg!(person); + dbg!(person.inner.is_kind(&UserTypes::Service)); let avatar = match person.icon() { Some(any_image) => Some( Image::from_any_base(any_image.as_one().context(location_info!())?.clone())? @@ -194,7 +205,7 @@ impl FromApubToForm for PersonForm { bio: Some(bio), local: Some(false), admin: Some(false), - bot_account: Some(person.ext_one.bot_account), + bot_account: Some(person.inner.is_kind(&UserTypes::Service)), private_key: None, public_key: Some(Some(person.ext_two.public_key.to_owned().public_key_pem)), last_refreshed_at: Some(naive_now()), diff --git a/docker/dev/volume_mount.dockerfile b/docker/dev/volume_mount.dockerfile index d848e0ea6..00d9c4735 100644 --- a/docker/dev/volume_mount.dockerfile +++ b/docker/dev/volume_mount.dockerfile @@ -24,7 +24,6 @@ RUN apt-get update -y RUN apt-get install -y libpq-dev # Copy resources -COPY config/defaults.hjson /config/defaults.hjson COPY --from=rust /app/lemmy_server /app/lemmy EXPOSE 8536