Change Person, Instance types (#2200)

This commit is contained in:
Nutomic 2022-04-12 17:10:35 +00:00 committed by GitHub
parent 2180bd0369
commit bbd739af9b
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
6 changed files with 86 additions and 6 deletions

View file

@ -0,0 +1,70 @@
{
"@context": [
"https://www.w3.org/ns/activitystreams",
"https://w3id.org/security/v1",
{
"vcard": "http://www.w3.org/2006/vcard/ns#",
"dfrn": "http://purl.org/macgirvin/dfrn/1.0/",
"diaspora": "https://diasporafoundation.org/ns/",
"litepub": "http://litepub.social/ns#",
"toot": "http://joinmastodon.org/ns#",
"schema": "http://schema.org#",
"manuallyApprovesFollowers": "as:manuallyApprovesFollowers",
"sensitive": "as:sensitive",
"Hashtag": "as:Hashtag",
"directMessage": "litepub:directMessage",
"discoverable": "toot:discoverable",
"PropertyValue": "schema:PropertyValue",
"value": "schema:value"
}
],
"id": "https://poliverso.org/profile/informapirata",
"diaspora:guid": "0477a01e-8161-2935-9a73-393807834700",
"type": "Organization",
"following": "https://poliverso.org/following/informapirata",
"followers": "https://poliverso.org/followers/informapirata",
"inbox": "https://poliverso.org/inbox/informapirata",
"outbox": "https://poliverso.org/outbox/informapirata",
"preferredUsername": "informapirata",
"name": "Informa Pirata",
"vcard:hasAddress": {
"@type": "vcard:Home",
"vcard:country-name": "Italy",
"vcard:region": "Lazio",
"vcard:locality": ""
},
"summary": "Politica Pirata: informazione su #whistleblowing #dirittidigitali #sovranitàdigitale #copyright #privacy #cyberwarfare #pirati #Europa #opensource #opendata <br>➡️➡️ http://T.ME/PPINFORMA",
"url": "https://poliverso.org/profile/informapirata",
"manuallyApprovesFollowers": false,
"discoverable": true,
"publicKey": {
"id": "https://poliverso.org/profile/informapirata#main-key",
"owner": "https://poliverso.org/profile/informapirata",
"publicKeyPem": "-----BEGIN PUBLIC KEY-----\nMIICIjANBgkqhkiG9w0BAQEFAAOCAg8AMIICCgKCAgEA09bPyftct7KNf4hm+rmG\n1aX4HmJbAdiXkmxo3g7iJG21Vvd3+OQeKnjpLc0n9s9rKMrpy8FQj+E7FaVYIGcP\n/f8McmSb4ezFeNkVNKGm+Y7swpeAAmh0MBWfDD+j3WHznD+OLABhWZlnfhIxW1aD\nD6mN9mkITvLAut8vJVTaciGzjfv6AndHVerVPV8lw5gXCmvX/+NZUOjjLQVND3fL\n8fZiJjJ3NSQ1tAx0m38PVMHZGw2492gkbKxzkW6c/QyMRAOrKP2+kJQ/6O2sn/ZK\n7MtHzMQ4eUjGc0ZLWQlCqQ4oVbVTcPgwHW1+no3928fzhU95zi5oAI08wfJ5wo86\nAnPv4fnUL/gyGff/ytZ/kGhNv+jVlSbMYxiDslRoD2Zp+L1P5Ypw6iemR1rMivL4\nJMxx2FoYGD1xzKBqNcJ2cDRQ5VQGwhBs/U6XyRMrRTzhDoe5dHr49MjHGuYkUzhq\naYPgku+zA7hfjvZA982kK2jAMXPoTLoUrY7T6beanYwfFIxd++fNHxTSexrhwx7P\nqn7v+pi0WTA8Cxor4N+ICCXxVvpO7s5VERVugiJofKZhFXiE2S02S2jVoGCRtEKw\n9/iignMld/IQSojz8N+77KMYGuVT9eG9Io/mF4MjCLluNNRXklt55dz55vOHPBxg\nll83LwyA3eELfylUNV75DcsCAwEAAQ==\n-----END PUBLIC KEY-----\n"
},
"endpoints": {
"sharedInbox": "https://poliverso.org/inbox"
},
"icon": {
"type": "Image",
"url": "https://poliverso.org/photo/profile/informapirata.png?ts=1630486460",
"mediaType": "image/png"
},
"attachment": [
{
"type": "PropertyValue",
"name": "Telegram",
"value": "http://T.ME/PPINFORMA"
},
{
"type": "PropertyValue",
"name": "Mastodon",
"value": "<a href=\"https://mastodon.uno/@informapirata\" target=\"_blank\" rel=\"noopener noreferrer\">https://mastodon.uno/@informapirata</a>"
}
],
"generator": {
"type": "Service",
"name": "Friendica 'Siberian Iris' 2022.03-1452",
"url": "https://poliverso.org"
}
}

View file

@ -1,9 +1,12 @@
use crate::{ use crate::{
check_is_apub_id_valid, check_is_apub_id_valid,
objects::{read_from_string_or_source_opt, verify_image_domain_matches}, objects::{read_from_string_or_source_opt, verify_image_domain_matches},
protocol::{objects::instance::Instance, ImageObject, Source}, protocol::{
objects::instance::{Instance, InstanceType},
ImageObject,
Source,
},
}; };
use activitystreams_kinds::actor::ServiceType;
use chrono::NaiveDateTime; use chrono::NaiveDateTime;
use lemmy_api_common::blocking; use lemmy_api_common::blocking;
use lemmy_apub_lib::{ use lemmy_apub_lib::{
@ -73,7 +76,7 @@ impl ApubObject for ApubSite {
#[tracing::instrument(skip_all)] #[tracing::instrument(skip_all)]
async fn into_apub(self, _data: &Self::DataType) -> Result<Self::ApubType, LemmyError> { async fn into_apub(self, _data: &Self::DataType) -> Result<Self::ApubType, LemmyError> {
let instance = Instance { let instance = Instance {
kind: ServiceType::Service, kind: InstanceType::Service,
id: ObjectId::new(self.actor_id()), id: ObjectId::new(self.actor_id()),
name: self.name.clone(), name: self.name.clone(),
content: self.sidebar.as_ref().map(|d| markdown_to_html(d)), content: self.sidebar.as_ref().map(|d| markdown_to_html(d)),

View file

@ -2,19 +2,24 @@ use crate::{
objects::instance::ApubSite, objects::instance::ApubSite,
protocol::{ImageObject, Source}, protocol::{ImageObject, Source},
}; };
use activitystreams_kinds::actor::ServiceType;
use chrono::{DateTime, FixedOffset}; use chrono::{DateTime, FixedOffset};
use lemmy_apub_lib::{object_id::ObjectId, signatures::PublicKey, values::MediaTypeHtml}; use lemmy_apub_lib::{object_id::ObjectId, signatures::PublicKey, values::MediaTypeHtml};
use serde::{Deserialize, Serialize}; use serde::{Deserialize, Serialize};
use serde_with::skip_serializing_none; use serde_with::skip_serializing_none;
use url::Url; use url::Url;
#[derive(Clone, Copy, Debug, Deserialize, Serialize, PartialEq)]
pub enum InstanceType {
Application,
Service,
}
#[skip_serializing_none] #[skip_serializing_none]
#[derive(Clone, Debug, Deserialize, Serialize)] #[derive(Clone, Debug, Deserialize, Serialize)]
#[serde(rename_all = "camelCase")] #[serde(rename_all = "camelCase")]
pub struct Instance { pub struct Instance {
#[serde(rename = "type")] #[serde(rename = "type")]
pub(crate) kind: ServiceType, pub(crate) kind: InstanceType,
pub(crate) id: ObjectId<ApubSite>, pub(crate) id: ObjectId<ApubSite>,
// site name // site name
pub(crate) name: String, pub(crate) name: String,

View file

@ -71,7 +71,8 @@ mod tests {
#[test] #[test]
fn test_parse_object_friendica() { fn test_parse_object_friendica() {
test_json::<Person>("assets/friendica/objects/person.json").unwrap(); test_json::<Person>("assets/friendica/objects/person_1.json").unwrap();
test_json::<Person>("assets/friendica/objects/person_2.json").unwrap();
test_json::<Page>("assets/friendica/objects/page_1.json").unwrap(); test_json::<Page>("assets/friendica/objects/page_1.json").unwrap();
test_json::<Page>("assets/friendica/objects/page_2.json").unwrap(); test_json::<Page>("assets/friendica/objects/page_2.json").unwrap();
test_json::<Note>("assets/friendica/objects/note.json").unwrap(); test_json::<Note>("assets/friendica/objects/note.json").unwrap();

View file

@ -12,6 +12,7 @@ use url::Url;
pub enum UserTypes { pub enum UserTypes {
Person, Person,
Service, Service,
Organization,
} }
#[skip_serializing_none] #[skip_serializing_none]