1 use activitystreams::unparsed::UnparsedMutExt;
2 use activitystreams_ext::UnparsedExtension;
3 use lemmy_utils::LemmyError;
4 use serde::{Deserialize, Serialize};
6 /// Activitystreams extension to allow (de)serializing additional Person field
7 /// `also_known_as` (used for Matrix profile link).
8 #[derive(Clone, Debug, Default, Deserialize, Serialize)]
9 #[serde(rename_all = "camelCase")]
10 pub struct PersonExtension {
11 pub matrix_user_id: Option<String>,
14 impl PersonExtension {
15 pub fn new(matrix_user_id: Option<String>) -> Result<PersonExtension, LemmyError> {
16 Ok(PersonExtension { matrix_user_id })
20 impl<U> UnparsedExtension<U> for PersonExtension
24 type Error = serde_json::Error;
26 fn try_from_unparsed(unparsed_mut: &mut U) -> Result<Self, Self::Error> {
28 matrix_user_id: unparsed_mut.remove("matrix_user_id")?,
32 fn try_into_unparsed(self, unparsed_mut: &mut U) -> Result<(), Self::Error> {
33 unparsed_mut.insert("matrix_user_id", self.matrix_user_id)?;