"type": "sc:Boolean",
"id": "pt:commentsEnabled"
},
- "moderators": "as:moderators"
+ "moderators": "as:moderators",
+ "matrixUserId": {
+ "type": "sc:Text",
+ "id": "as:alsoKnownAs"
+ },
}))?;
Ok(vec![
AnyBase::from(context()),
pub(crate) mod context;
-pub(crate) mod group_extensions;
+pub(crate) mod group_extension;
pub(crate) mod page_extension;
+pub(crate) mod person_extension;
pub(crate) mod signatures;
--- /dev/null
+use activitystreams::unparsed::UnparsedMutExt;
+use activitystreams_ext::UnparsedExtension;
+use lemmy_utils::LemmyError;
+use serde::{Deserialize, Serialize};
+
+/// Activitystreams extension to allow (de)serializing additional Person field
+/// `also_known_as` (used for Matrix profile link).
+#[derive(Clone, Debug, Default, Deserialize, Serialize)]
+#[serde(rename_all = "camelCase")]
+pub struct PersonExtension {
+ pub matrix_user_id: Option<String>,
+}
+
+impl PersonExtension {
+ pub fn new(matrix_user_id: Option<String>) -> Result<PersonExtension, LemmyError> {
+ Ok(PersonExtension { matrix_user_id })
+ }
+}
+
+impl<U> UnparsedExtension<U> for PersonExtension
+where
+ U: UnparsedMutExt,
+{
+ type Error = serde_json::Error;
+
+ fn try_from_unparsed(unparsed_mut: &mut U) -> Result<Self, Self::Error> {
+ Ok(PersonExtension {
+ matrix_user_id: unparsed_mut.remove("matrix_user_id")?,
+ })
+ }
+
+ fn try_into_unparsed(self, unparsed_mut: &mut U) -> Result<(), Self::Error> {
+ unparsed_mut.insert("matrix_user_id", self.matrix_user_id)?;
+ Ok(())
+ }
+}
pub mod routes;
use crate::extensions::{
- group_extensions::GroupExtension,
+ group_extension::GroupExtension,
page_extension::PageExtension,
+ person_extension::PersonExtension,
signatures::{PublicKey, PublicKeyExtension},
};
use activitystreams::{
/// Activitystreams type for community
type GroupExt = Ext2<actor::ApActor<ApObject<actor::Group>>, GroupExtension, PublicKeyExtension>;
/// Activitystreams type for person
-type PersonExt = Ext1<actor::ApActor<ApObject<actor::Person>>, PublicKeyExtension>;
+type PersonExt = Ext2<actor::ApActor<ApObject<actor::Person>>, PersonExtension, PublicKeyExtension>;
/// Activitystreams type for post
type PageExt = Ext1<ApObject<Page>, PageExtension>;
type NoteExt = ApObject<Note>;
use crate::{
- extensions::{context::lemmy_context, group_extensions::GroupExtension},
+ extensions::{context::lemmy_context, group_extension::GroupExtension},
fetcher::{community::fetch_community_mods, person::get_or_fetch_and_upsert_person},
generate_moderators_url,
objects::{
use crate::{
- extensions::context::lemmy_context,
+ extensions::{context::lemmy_context, person_extension::PersonExtension},
objects::{
check_object_domain,
get_source_markdown_value,
object::{ApObject, Image, Tombstone},
prelude::*,
};
-use activitystreams_ext::Ext1;
+use activitystreams_ext::Ext2;
use anyhow::Context;
use lemmy_api_structs::blocking;
use lemmy_db_queries::{ApubObject, DbPool};
..Default::default()
});
- Ok(Ext1::new(ap_actor, self.get_public_key_ext()?))
+ 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<Tombstone, LemmyError> {
unimplemented!()
local: Some(false),
admin: Some(false),
private_key: None,
- public_key: Some(Some(person.ext_one.public_key.to_owned().public_key_pem)),
+ public_key: Some(Some(person.ext_two.public_key.to_owned().public_key_pem)),
last_refreshed_at: Some(naive_now()),
inbox_url: Some(person.inner.inbox()?.to_owned().into()),
shared_inbox_url: Some(shared_inbox),
- matrix_user_id: None, // TODO
+ matrix_user_id: Some(person.ext_one.matrix_user_id.to_owned()),
})
}
}