mirror of
https://github.com/LemmyNet/lemmy.git
synced 2024-10-01 01:36:12 -04:00
Merge pull request #1522 from LemmyNet/move_matrix_and_admin_to_person_nutomic
Federate Matrix ID (fixes #1438)
This commit is contained in:
commit
0b5438d3fd
@ -14,7 +14,11 @@ pub(crate) fn lemmy_context() -> Result<Vec<AnyBase>, LemmyError> {
|
||||
"type": "sc:Boolean",
|
||||
"id": "pt:commentsEnabled"
|
||||
},
|
||||
"moderators": "as:moderators"
|
||||
"moderators": "as:moderators",
|
||||
"matrixUserId": {
|
||||
"type": "sc:Text",
|
||||
"id": "as:alsoKnownAs"
|
||||
},
|
||||
}))?;
|
||||
Ok(vec![
|
||||
AnyBase::from(context()),
|
||||
|
@ -1,4 +1,5 @@
|
||||
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;
|
||||
|
36
crates/apub/src/extensions/person_extension.rs
Normal file
36
crates/apub/src/extensions/person_extension.rs
Normal file
@ -0,0 +1,36 @@
|
||||
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(())
|
||||
}
|
||||
}
|
@ -11,8 +11,9 @@ pub mod objects;
|
||||
pub mod routes;
|
||||
|
||||
use crate::extensions::{
|
||||
group_extensions::GroupExtension,
|
||||
group_extension::GroupExtension,
|
||||
page_extension::PageExtension,
|
||||
person_extension::PersonExtension,
|
||||
signatures::{PublicKey, PublicKeyExtension},
|
||||
};
|
||||
use activitystreams::{
|
||||
@ -46,7 +47,7 @@ use url::{ParseError, Url};
|
||||
/// 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>;
|
||||
|
@ -1,5 +1,5 @@
|
||||
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::{
|
||||
|
@ -1,5 +1,5 @@
|
||||
use crate::{
|
||||
extensions::context::lemmy_context,
|
||||
extensions::{context::lemmy_context, person_extension::PersonExtension},
|
||||
objects::{
|
||||
check_object_domain,
|
||||
get_source_markdown_value,
|
||||
@ -16,7 +16,7 @@ use activitystreams::{
|
||||
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};
|
||||
@ -77,7 +77,8 @@ impl ToApub for DbPerson {
|
||||
..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!()
|
||||
@ -192,11 +193,11 @@ impl FromApubToForm<PersonExt> for PersonForm {
|
||||
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()),
|
||||
})
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user