From b277ea97a9944a84439c248bae9da80bc8b67768 Mon Sep 17 00:00:00 2001 From: Felix Ableitner Date: Mon, 15 Apr 2024 12:43:00 +0200 Subject: [PATCH 1/2] Testing and minor fix for federation with Discourse --- .../apub/assets/discourse/objects/group.json | 22 ++++++++++++++++++ .../apub/assets/discourse/objects/page.json | 13 +++++++++++ .../apub/assets/discourse/objects/person.json | 23 +++++++++++++++++++ crates/apub/src/protocol/objects/mod.rs | 8 +++++++ crates/apub/src/protocol/objects/page.rs | 2 +- 5 files changed, 67 insertions(+), 1 deletion(-) create mode 100644 crates/apub/assets/discourse/objects/group.json create mode 100644 crates/apub/assets/discourse/objects/page.json create mode 100644 crates/apub/assets/discourse/objects/person.json diff --git a/crates/apub/assets/discourse/objects/group.json b/crates/apub/assets/discourse/objects/group.json new file mode 100644 index 000000000..eb32e479f --- /dev/null +++ b/crates/apub/assets/discourse/objects/group.json @@ -0,0 +1,22 @@ +{ + "id": "https://socialhub.activitypub.rocks/ap/actor/797217cf18c0e819dfafc52425590146", + "type": "Group", + "updated": "2024-04-05T12:49:51Z", + "url": "https://socialhub.activitypub.rocks/c/meeting/threadiverse-wg/88", + "name": "Threadiverse Working Group (SocialHub)", + "inbox": "https://socialhub.activitypub.rocks/ap/actor/797217cf18c0e819dfafc52425590146/inbox", + "outbox": "https://socialhub.activitypub.rocks/ap/actor/797217cf18c0e819dfafc52425590146/outbox", + "followers": "https://socialhub.activitypub.rocks/ap/actor/797217cf18c0e819dfafc52425590146/followers", + "preferredUsername": "threadiverse-wg", + "publicKey": { + "id": "https://socialhub.activitypub.rocks/ap/actor/797217cf18c0e819dfafc52425590146#main-key", + "owner": "https://socialhub.activitypub.rocks/ap/actor/797217cf18c0e819dfafc52425590146", + "publicKeyPem": "-----BEGIN PUBLIC KEY-----\nMIIBIjANBgkqhkiG9w0BAQEFAAOCAQ8AMIIBCgKCAQEApJi4iAcW6bPiHVCxT9p0\n8DVnrDDO4QtLNy7bpRFdMFifmmmXprsuAi9D2MSwbhH49V54HtIkxBpKd2IR/UD8\nmhMDY4CNI9FHpjqLw0wtkzxcqF9urSqhn0/vWX+9oxyhIgQS5KMiIkYDMJiAc691\niEcZ8LCran23xIGl6Dk54Nr3TqTMLcjDhzQYUJbxMrLq5/knWqOKG3IF5OxK+9ZZ\n1wxDF872eJTxJLkmpag+WYNtHzvB2SGTp8j5IF1/pZ9J1c3cpYfaeolTch/B/GQn\najCB4l27U52rIIObxJqFXSY8wHyd0aAmNmxzPZ7cduRlBDhmI40cAmnCV1YQPvpk\nDwIDAQAB\n-----END PUBLIC KEY-----\n" + }, + "icon": { + "type": "Image", + "mediaType": "image/png", + "url": "https://socialhub.activitypub.rocks/uploads/default/original/1X/8faac84234dc73d074dadaa2bcf24dc746b8647f.png" + }, + "@context": "https://www.w3.org/ns/activitystreams" + } \ No newline at end of file diff --git a/crates/apub/assets/discourse/objects/page.json b/crates/apub/assets/discourse/objects/page.json new file mode 100644 index 000000000..8bdca11e8 --- /dev/null +++ b/crates/apub/assets/discourse/objects/page.json @@ -0,0 +1,13 @@ +{ +"id": "https://socialhub.activitypub.rocks/ap/object/1899f65c062200daec50a4c89ed76dc9", +"type": "Note", +"audience": "https://socialhub.activitypub.rocks/ap/actor/797217cf18c0e819dfafc52425590146", +"published": "2024-04-13T14:36:19Z", +"updated": "2024-04-13T14:36:19Z", +"url": "https://socialhub.activitypub.rocks/t/our-next-meeting/4079/1", +"attributedTo": "https://socialhub.activitypub.rocks/ap/actor/495843076e9e469fbd35ccf467ae9fb1", +"name": "Our next meeting", +"context": "https://socialhub.activitypub.rocks/ap/collection/8850f6e85b57c490da915a5dfbbd5045", +"content": "

Last Meeting

\n

Recording

\nhttps://us06web.zoom.us/rec/share/4hGBTvgXJPlu8UkjkkxVARypNg5DH0eeaKlIBv71D4G3lokYyrCrg7cqBCJmL109.FsHYTZDlVvZXrgcn?startTime=1712254114000\nPasscode: z+1*4pUB\n

Minutes

\nTo refresh your memory, you can read the minutes of last week's meeting ("assets/mobilizon/objects/person.json")?; Ok(()) } + + #[test] + fn test_parse_object_discourse() -> LemmyResult<()> { + test_json::("assets/discourse/objects/group.json")?; + test_json::("assets/discourse/objects/page.json")?; + test_json::("assets/discourse/objects/person.json")?; + Ok(()) + } } diff --git a/crates/apub/src/protocol/objects/page.rs b/crates/apub/src/protocol/objects/page.rs index acfd8f5fd..4d70744cf 100644 --- a/crates/apub/src/protocol/objects/page.rs +++ b/crates/apub/src/protocol/objects/page.rs @@ -42,7 +42,7 @@ pub struct Page { pub(crate) kind: PageType, pub(crate) id: ObjectId, pub(crate) attributed_to: AttributedTo, - #[serde(deserialize_with = "deserialize_one_or_many")] + #[serde(deserialize_with = "deserialize_one_or_many", default)] pub(crate) to: Vec, // If there is inReplyTo field this is actually a comment and must not be parsed #[serde(deserialize_with = "deserialize_not_present", default)] From d97c956dd5cada6ab702223bf8d04c59f3b51da0 Mon Sep 17 00:00:00 2001 From: Felix Ableitner Date: Mon, 15 Apr 2024 12:50:46 +0200 Subject: [PATCH 2/2] prettier --- .../apub/assets/discourse/objects/group.json | 30 ++++++------- .../apub/assets/discourse/objects/page.json | 24 +++++----- .../apub/assets/discourse/objects/person.json | 44 +++++++++---------- 3 files changed, 49 insertions(+), 49 deletions(-) diff --git a/crates/apub/assets/discourse/objects/group.json b/crates/apub/assets/discourse/objects/group.json index eb32e479f..5ed2c8c05 100644 --- a/crates/apub/assets/discourse/objects/group.json +++ b/crates/apub/assets/discourse/objects/group.json @@ -1,22 +1,22 @@ { - "id": "https://socialhub.activitypub.rocks/ap/actor/797217cf18c0e819dfafc52425590146", - "type": "Group", - "updated": "2024-04-05T12:49:51Z", - "url": "https://socialhub.activitypub.rocks/c/meeting/threadiverse-wg/88", - "name": "Threadiverse Working Group (SocialHub)", - "inbox": "https://socialhub.activitypub.rocks/ap/actor/797217cf18c0e819dfafc52425590146/inbox", - "outbox": "https://socialhub.activitypub.rocks/ap/actor/797217cf18c0e819dfafc52425590146/outbox", - "followers": "https://socialhub.activitypub.rocks/ap/actor/797217cf18c0e819dfafc52425590146/followers", - "preferredUsername": "threadiverse-wg", - "publicKey": { + "id": "https://socialhub.activitypub.rocks/ap/actor/797217cf18c0e819dfafc52425590146", + "type": "Group", + "updated": "2024-04-05T12:49:51Z", + "url": "https://socialhub.activitypub.rocks/c/meeting/threadiverse-wg/88", + "name": "Threadiverse Working Group (SocialHub)", + "inbox": "https://socialhub.activitypub.rocks/ap/actor/797217cf18c0e819dfafc52425590146/inbox", + "outbox": "https://socialhub.activitypub.rocks/ap/actor/797217cf18c0e819dfafc52425590146/outbox", + "followers": "https://socialhub.activitypub.rocks/ap/actor/797217cf18c0e819dfafc52425590146/followers", + "preferredUsername": "threadiverse-wg", + "publicKey": { "id": "https://socialhub.activitypub.rocks/ap/actor/797217cf18c0e819dfafc52425590146#main-key", "owner": "https://socialhub.activitypub.rocks/ap/actor/797217cf18c0e819dfafc52425590146", "publicKeyPem": "-----BEGIN PUBLIC KEY-----\nMIIBIjANBgkqhkiG9w0BAQEFAAOCAQ8AMIIBCgKCAQEApJi4iAcW6bPiHVCxT9p0\n8DVnrDDO4QtLNy7bpRFdMFifmmmXprsuAi9D2MSwbhH49V54HtIkxBpKd2IR/UD8\nmhMDY4CNI9FHpjqLw0wtkzxcqF9urSqhn0/vWX+9oxyhIgQS5KMiIkYDMJiAc691\niEcZ8LCran23xIGl6Dk54Nr3TqTMLcjDhzQYUJbxMrLq5/knWqOKG3IF5OxK+9ZZ\n1wxDF872eJTxJLkmpag+WYNtHzvB2SGTp8j5IF1/pZ9J1c3cpYfaeolTch/B/GQn\najCB4l27U52rIIObxJqFXSY8wHyd0aAmNmxzPZ7cduRlBDhmI40cAmnCV1YQPvpk\nDwIDAQAB\n-----END PUBLIC KEY-----\n" - }, - "icon": { + }, + "icon": { "type": "Image", "mediaType": "image/png", "url": "https://socialhub.activitypub.rocks/uploads/default/original/1X/8faac84234dc73d074dadaa2bcf24dc746b8647f.png" - }, - "@context": "https://www.w3.org/ns/activitystreams" - } \ No newline at end of file + }, + "@context": "https://www.w3.org/ns/activitystreams" +} diff --git a/crates/apub/assets/discourse/objects/page.json b/crates/apub/assets/discourse/objects/page.json index 8bdca11e8..c020ce9f5 100644 --- a/crates/apub/assets/discourse/objects/page.json +++ b/crates/apub/assets/discourse/objects/page.json @@ -1,13 +1,13 @@ { -"id": "https://socialhub.activitypub.rocks/ap/object/1899f65c062200daec50a4c89ed76dc9", -"type": "Note", -"audience": "https://socialhub.activitypub.rocks/ap/actor/797217cf18c0e819dfafc52425590146", -"published": "2024-04-13T14:36:19Z", -"updated": "2024-04-13T14:36:19Z", -"url": "https://socialhub.activitypub.rocks/t/our-next-meeting/4079/1", -"attributedTo": "https://socialhub.activitypub.rocks/ap/actor/495843076e9e469fbd35ccf467ae9fb1", -"name": "Our next meeting", -"context": "https://socialhub.activitypub.rocks/ap/collection/8850f6e85b57c490da915a5dfbbd5045", -"content": "

Last Meeting

\n

Recording

\n
https://us06web.zoom.us/rec/share/4hGBTvgXJPlu8UkjkkxVARypNg5DH0eeaKlIBv71D4G3lokYyrCrg7cqBCJmL109.FsHYTZDlVvZXrgcn?startTime=1712254114000\nPasscode: z+1*4pUB\n

Minutes

\nTo refresh your memory, you can read the minutes of last week's meeting Last Meeting\n

Recording

\n
https://us06web.zoom.us/rec/share/4hGBTvgXJPlu8UkjkkxVARypNg5DH0eeaKlIBv71D4G3lokYyrCrg7cqBCJmL109.FsHYTZDlVvZXrgcn?startTime=1712254114000\nPasscode: z+1*4pUB\n

Minutes

\nTo refresh your memory, you can read the minutes of last week's meeting