]> Untitled Git - lemmy.git/commitdiff
Breaking apub changes (#1859)
authorNutomic <me@nutomic.com>
Fri, 22 Oct 2021 16:21:26 +0000 (16:21 +0000)
committerGitHub <noreply@github.com>
Fri, 22 Oct 2021 16:21:26 +0000 (12:21 -0400)
* Remove CommentInReplyToMigration

* Remove compat for RemovePostCommentOrCommunity

* Remove PublicUrlMigration

* Change type of pm to ChatMessage from Pleroma, make pm.to array

* Use person.summary instead of person.content for pleroma compat

* Also change group.content to summary

* Rewrite apub object test json to serve as nice examples

* Also add test case for parsing pleroma private message

30 files changed:
api_tests/src/comment.spec.ts
api_tests/src/post.spec.ts
crates/apub/assets/lemmy-comment.json
crates/apub/assets/lemmy-community.json
crates/apub/assets/lemmy-person.json
crates/apub/assets/lemmy-post.json
crates/apub/assets/lemmy-private-message.json
crates/apub/assets/pleroma-comment.json
crates/apub/assets/pleroma-private-message.json [new file with mode: 0644]
crates/apub/src/activities/comment/create_or_update.rs
crates/apub/src/activities/community/add_mod.rs
crates/apub/src/activities/community/announce.rs
crates/apub/src/activities/community/block_user.rs
crates/apub/src/activities/community/remove_mod.rs
crates/apub/src/activities/community/undo_block_user.rs
crates/apub/src/activities/community/update.rs
crates/apub/src/activities/deletion/delete.rs
crates/apub/src/activities/deletion/undo_delete.rs
crates/apub/src/activities/mod.rs
crates/apub/src/activities/post/create_or_update.rs
crates/apub/src/activities/undo_remove.rs [deleted file]
crates/apub/src/activities/voting/undo_vote.rs
crates/apub/src/activities/voting/vote.rs
crates/apub/src/migrations.rs
crates/apub/src/objects/comment.rs
crates/apub/src/objects/community.rs
crates/apub/src/objects/mod.rs
crates/apub/src/objects/person.rs
crates/apub/src/objects/post.rs
crates/apub/src/objects/private_message.rs

index 7ded279933ed4475620972c0e77bdb58ed7f259e..2915d26120f18666cf5080f0a38be833c4f4211e 100644 (file)
@@ -389,7 +389,6 @@ test('Fetch in_reply_tos: A is unsubbed from B, B makes a post, and some embedde
 
 test('Report a comment', async () => {
   let betaCommunity = (await resolveBetaCommunity(beta)).community;
-  console.log(betaCommunity);
   let postRes = (await createPost(beta, betaCommunity.community.id)).post_view.post;
   expect(postRes).toBeDefined();
   let commentRes = (await createComment(beta, postRes.id)).comment_view.comment;
index 5e78dc5187d1ba9f54bd420cfd4e4dce8dd1917d..64c54eec0b9cec83eb441a85fc42b8c361ffaa5b 100644 (file)
@@ -358,7 +358,6 @@ test('Enforce community ban for federated user', async () => {
 
 test('Report a post', async () => {
   let betaCommunity = (await resolveBetaCommunity(beta)).community;
-  console.log(betaCommunity);
   let postRes = await createPost(beta, betaCommunity.community.id);
   expect(postRes.post_view.post).toBeDefined();
 
index 4781c9e0f49756cdb2fdc05295be32b4d3e26af2..c40e893c80b3951923e807c0a81a7096d16eee29 100644 (file)
     },
     "https://w3id.org/security/v1"
   ],
-  "attributedTo": "https://lemmy.ml/u/nutomic",
-  "content": "While I very much get and respect the general sentiment, I think from the perspective of a Central European non-English person in a country with a significant number of, also non-English speaking Nazis, the current approach of filtering slurs based on an English regex is fatally flawed. You can happily use Lemmy to create a hostile far right community where everyone is easily able to use whatever hurtful slurs they want as long as they are not the few specifically blocked English ones. \n\nOn the other hand you create a situation where people feel the need to question the choice of software of their community because they read about censorship or whatever to be used in Lemmy and might stay away and move to other software even though the would maybe never be affected by the slur-filter as the number is not so large and the overlap with other languages not very big.\n\nSo I would argue that this specific implementation of a slur-filter just doesn't achieve what it aims to achieve and should be fundamentally rethought, maybe as configurable per instance.",
-  "id": "https://lemmy.ml/comment/38741",
-  "inReplyTo": [
-    "https://lemmy.ml/post/55143"
-  ],
+  "id": "https://enterprise.lemmy.ml/comment/38741",
+  "type": "Note",
+  "attributedTo": "https://enterprise.lemmy.ml/u/picard",
+  "to": ["https://www.w3.org/ns/activitystreams#Public"],
+  "inReplyTo": "https://enterprise.lemmy.ml/post/55143",
+  "content": "first comment!",
   "mediaType": "text/html",
-  "published": "2021-03-01T13:42:43.966208+00:00",
   "source": {
-    "content": "While I very much get and respect the general sentiment, I think from the perspective of a Central European non-English person in a country with a significant number of, also non-English speaking Nazis, the current approach of filtering slurs based on an English regex is fatally flawed. You can happily use Lemmy to create a hostile far right community where everyone is easily able to use whatever hurtful slurs they want as long as they are not the few specifically blocked English ones. \n\nOn the other hand you create a situation where people feel the need to question the choice of software of their community because they read about censorship or whatever to be used in Lemmy and might stay away and move to other software even though the would maybe never be affected by the slur-filter as the number is not so large and the overlap with other languages not very big.\n\nSo I would argue that this specific implementation of a slur-filter just doesn't achieve what it aims to achieve and should be fundamentally rethought, maybe as configurable per instance.",
+    "content": "first comment!",
     "mediaType": "text/markdown"
   },
-  "to": ["https://www.w3.org/ns/activitystreams#Public"],
-  "type": "Note",
+  "published": "2021-03-01T13:42:43.966208+00:00",
   "updated": "2021-03-01T13:43:03.955787+00:00"
 }
index e0f3c6809ad441cd7a4804d49e75ce98009beb34..3f56ed8ee5d4572e7d59e3e9b1215fcb2343d02b 100644 (file)
     },
     "https://w3id.org/security/v1"
   ],
-  "content": "<p>Lemmy Announcements</p>\n<hr />\n<p>Feel free to announce new communities here.</p>\n<p>Other than that, this is <em>reserved for admin use only</em>.</p>\n",
-  "endpoints": {
-    "sharedInbox": "https://lemmy.ml/inbox"
+  "id": "https://enterprise.lemmy.ml/c/tenforward",
+  "type": "Group",
+  "preferredUsername": "main",
+  "name": "Ten Forward",
+  "summary": "<p>Lounge and recreation facility</p>\n<hr />\n<p>Welcome to the <a href=\"https://memory-alpha.fandom.com/wiki/USS_Enterprise_(NCC-1701-D)\">Enterprise</a>!.</p>\n",
+  "source": {
+    "content": "Lounge and recreation facility\n\n---\n\nWelcome to the [Enterprise](https://memory-alpha.fandom.com/wiki/USS_Enterprise_(NCC-1701-D))!.",
+    "mediaType": "text/markdown"
   },
-  "followers": "https://lemmy.ml/c/announcements/followers",
+  "sensitive": false,
   "icon": {
     "type": "Image",
-    "url": "https://lemmy.ml/pictrs/image/waqyZwLAy4.webp"
+    "url": "https://enterprise.lemmy.ml/pictrs/image/waqyZwLAy4.webp"
+  },
+  "image": {
+    "type": "Image",
+    "url": "https://enterprise.lemmy.ml/pictrs/image/Wt8zoMcCmE.jpg"
   },
-  "id": "https://lemmy.ml/c/announcements",
-  "inbox": "https://lemmy.ml/c/announcements/inbox",
-  "mediaType": "text/html",
-  "moderators": "https://lemmy.ml/c/announcements/moderators",
-  "name": "Announcements",
-  "outbox": "https://lemmy.ml/c/announcements/outbox",
-  "preferredUsername": "announcements",
+  "inbox": "https://enterprise.lemmy.ml/c/tenforward/inbox",
+  "followers": "https://enterprise.lemmy.ml/c/tenforward/followers",
+  "moderators": "https://enterprise.lemmy.ml/c/tenforward/moderators",
+  "endpoints": {
+    "sharedInbox": "https://enterprise.lemmy.ml/inbox"
+  },
+  "outbox": "https://enterprise.lemmy.ml/c/tenforward/outbox",
   "publicKey": {
-    "id": "https://lemmy.ml/c/announcements#main-key",
-    "owner": "https://lemmy.ml/c/announcements",
+    "id": "https://enterprise.lemmy.ml/c/tenforward#main-key",
+    "owner": "https://enterprise.lemmy.ml/c/tenforward",
     "publicKeyPem": "-----BEGIN PUBLIC KEY-----\nMIIBIjANBgkqhkiG9w0BAQEFAAOCAQ8AMIIBCgKCAQEAzRjKTNtvDCmugplwEh+g\nx1bhKm6BHUZfXfpscgMMm7tXFswSDzUQirMgfkxa9ubfr1PDFKffA2vQ9x6CyuO/\n70xTafdOHyV1tSqzgKz0ZvFZ/VCOo6qy1mYWVkrtBm/fKzM+87MdkKYB/zI4VyEJ\nLfLQgjwxBAEYUH3CBG71U0gO0TwbimWNN0vqlfp0QfThNe1WYObF88ZVzMLgFbr7\nRHBItZjlZ/d8foPDidlIR3l2dJjy0EsD8F9JM340jtX7LXqFmU4j1AQKNHTDLnUF\nwYVhzuQGNJ504l5LZkFG54XfIFT7dx2QwuuM9bSnfPv/98RYrq1Si6tCkxEt1cVe\n4wIDAQAB\n-----END PUBLIC KEY-----\n"
   },
   "published": "2019-06-02T16:43:50.799554+00:00",
-  "sensitive": false,
-  "source": {
-    "content": "Lemmy Announcements\n\n---\n\nFeel free to announce new communities here.\n\nOther than that, this is *reserved for admin use only*.",
-    "mediaType": "text/markdown"
-  },
-  "type": "Group",
   "updated": "2021-03-10T17:18:10.498868+00:00"
 }
index 6514b6e917416a7d3c288e4356a155f30fec6720..25c9351774127be13787ea298b3bc46096c56198 100644 (file)
     },
     "https://w3id.org/security/v1"
   ],
-  "content": "<p>Lemmy maintainer. Interested in politics, video games, and many other things.</p>\n",
-  "endpoints": {
-    "sharedInbox": "https://lemmy.ml/inbox"
+  "id": "https://enterprise.lemmy.ml/u/picard",
+  "type": "Person",
+  "preferredUsername": "picard",
+  "name": "Jean-Luc Picard",
+  "summary": "<p>Captain of the starship <strong>Enterprise</strong>.</p>\n",
+  "source": {
+    "content": "Captain of the starship **Enterprise**.",
+    "mediaType": "text/markdown"
   },
   "icon": {
     "type": "Image",
-    "url": "https://lemmy.ml/pictrs/image/ed9ej7.jpg"
+    "url": "https://enterprise.lemmy.ml/pictrs/image/ed9ej7.jpg"
   },
-  "id": "https://lemmy.ml/u/nutomic",
-  "inbox": "https://lemmy.ml/u/nutomic/inbox",
-  "mediaType": "text/html",
-  "outbox": "https://lemmy.ml/u/nutomic/outbox",
-  "preferredUsername": "nutomic",
-  "publicKey": {
-    "id": "https://lemmy.ml/u/nutomic#main-key",
-    "owner": "https://lemmy.ml/u/nutomic",
-    "publicKeyPem": "-----BEGIN PUBLIC KEY-----\nMIIBIjANBgkqhkiG9w0BAQEFAAOCAQ8AMIIBCgKCAQEA0lP99/s5Vv+XbPdkeqIJ\nwoD4GFnHmBnBHdEKChEUWfWj1TtioC/rGNoXFQeXQA3Amhy4nxSceiDnUgwkkuQY\nv0MtIW58NzgknEavtllxL+LSds5pg3gANaDIk8UiWTkqXTg0GnlJMpCK1Chen0l/\nszL6DEvUyTSuS5ZYDXFgewF89Pe7U0S15V5U2Harv7AgJYDyxmUL0D1pGuUCRqcE\nl5MTHJjrXeNnH1w2g8aly8YlO/Cr0L51rFg/lBF23vni7ZLv8HbmWh6YpaAf1R8h\nE45zKR7OHqymdjzrg1ITBwovefpwMkVgnJ+Wdr4HPnFlBSkXPoZeM11+Z8L0anzA\nXwIDAQAB\n-----END PUBLIC KEY-----\n"
+  "image": {
+    "type": "Image",
+    "url": "https://enterprise.lemmy.ml/pictrs/image/XenaYI5hTn.png"
   },
-  "published": "2020-01-17T01:38:22.348392+00:00",
-  "source": {
-    "content": "Lemmy maintainer. Interested in politics, video games, and many other things.",
-    "mediaType": "text/markdown"
+  "inbox": "https://enterprise.lemmy.ml/u/picard/inbox",
+  "outbox": "https://enterprise.lemmy.ml/u/picard/outbox",
+  "endpoints": {
+    "sharedInbox": "https://enterprise.lemmy.ml/inbox"
   },
-  "type": "Person",
-  "updated": "2021-08-13T00:11:15.941990+00:00"
+  "published": "2020-01-17T01:38:22.348392+00:00",
+  "updated": "2021-08-13T00:11:15.941990+00:00",
+  "publicKey": {
+    "id": "https://enterprise.lemmy.ml/u/picard#main-key",
+    "owner": "https://enterprise.lemmy.ml/u/picard",
+    "publicKeyPem": "-----BEGIN PUBLIC KEY-----\nMIIBIjANBgkqhkiG9w0BAQEFAAOCAQ8AMIIBCgKCAQEA0lP99/s5Vv+XbPdkeqIJ\nwoD4GFnHmBnBHdEKChEUWfWj1TtioC/rGNoXFQeXQA3Amhy4nxSceiDnUgwkkuQY\nv0MtIW58NzgknEavtllxL+LSds5pg3gANaDIk8UiWTkqXTg0GnlJMpCK1Chen0l/\nszL6DEvUyTSuS5ZYDXFgewF89Pe7U0S15V5U2Harv7AgJYDyxmUL0D1pGuUCRqcE\nl5MTHJjrXeNnH1w2g8aly8YlO/Cr0L51rFg/lBF23vni7ZLv8HbmWh6YpaAf1R8h\nE45zKR7OHqymdjzrg1ITBwovefpwMkVgnJ+Wdr4HPnFlBSkXPoZeM11+Z8L0anzA\nXwIDAQAB\n-----END PUBLIC KEY-----\n"
+  }
 }
index fba112f977162d0b38599c644cd3d6ae7af4e716..baf28ea06bef973b055a898d559a998562794fb4 100644 (file)
     },
     "https://w3id.org/security/v1"
   ],
-  "attributedTo": "https://lemmy.ml/u/nutomic",
-  "commentsEnabled": true,
-  "content": "<p>Recently there have been some discussions about the political stances of the Lemmy developers and site admins. To clear up some misconceptions: Lemmy is run by a team of people with different ideologies, including anti-capitalist, communist, anarchist, and others. While @dessalines and I are communists, we take decisions collectively, and don't demand that anyone adopt our views or convert to our ideologies. We wouldn't devote so much time to building a federated site otherwise.</p>\n<p>What's important to us is that you follow the site rules and <a href=\"https://join.lemmy.ml/docs/en/code_of_conduct.html\">Code of Conduct</a>. Meaning primarily, no-bigotry, and being respectful towards others. As long as that is the case, we can get along perfectly fine.</p>\n<p>In general we are open for constructive feedback, so please contact any member of the admin team if you have an idea how to improve Lemmy.</p>\n<h2>Slur Filter</h2>\n<p>We also noticed a consistent criticism of the built-in slur filter in Lemmy. Not so much on lemmy.ml itself, but whenever Lemmy is recommended elsewhere, a few usual suspects keep bringing it up. To these people we say the following: we are using the slur filter as a tool to keep a friendly atmosphere, and prevent racists, sexists and other bigots from using Lemmy. Its existence alone has lead many of them to not make an account, or run an instance: a clear net positive.</p>\n<p>You can see for yourself the words which are blocked (content warning, <a href=\"https://github.com/LemmyNet/lemmy/blob/main/crates/utils/src/utils.rs#L10\">link here</a>). Note that it doesn't include any simple swear words, but only slurs which are used to insult and attack other people. If you want to use any of these words, then please stay on one of the many platforms that permit them. Lemmy is not for you, and we don't want you here.</p>\n<p>We are fully aware that the slur filter is not perfect. It is made for American English, and can give false positives in other languages or dialects. We are totally willing to fix such problems on a case by case basis, simply open an issue in our <a href=\"https://github.com/LemmyNet/lemmy/issues\">repo </a>with a description of the problem.</p>\n",
-  "id": "https://lemmy.ml/post/55143",
+  "id": "https://enterprise.lemmy.ml/post/55143",
+  "type": "Page",
+  "attributedTo": "https://enterprise.lemmy.ml/u/picard",
+  "to": [
+    "https://enterprise.lemmy.ml/c/tenforward",
+    "https://www.w3.org/ns/activitystreams#Public"
+  ],
+  "name": "Post title",
+  "content": "<p>This is a post in the /c/tenforward community</p>\n",
   "mediaType": "text/html",
-  "name": "Statement on Politics of Lemmy.ml",
-  "published": "2021-02-26T12:35:34.292626+00:00",
-  "sensitive": false,
   "source": {
-    "content": "Recently there have been some discussions about the political stances of the Lemmy developers and site admins. To clear up some misconceptions: Lemmy is run by a team of people with different ideologies, including anti-capitalist, communist, anarchist, and others. While @dessalines and I are communists, we take decisions collectively, and don't demand that anyone adopt our views or convert to our ideologies. We wouldn't devote so much time to building a federated site otherwise.\n\nWhat's important to us is that you follow the site rules and [Code of Conduct](https://join.lemmy.ml/docs/en/code_of_conduct.html). Meaning primarily, no-bigotry, and being respectful towards others. As long as that is the case, we can get along perfectly fine.\n\nIn general we are open for constructive feedback, so please contact any member of the admin team if you have an idea how to improve Lemmy. \n\n## Slur Filter\n\nWe also noticed a consistent criticism of the built-in slur filter in Lemmy. Not so much on lemmy.ml itself, but whenever Lemmy is recommended elsewhere, a few usual suspects keep bringing it up. To these people we say the following: we are using the slur filter as a tool to keep a friendly atmosphere, and prevent racists, sexists and other bigots from using Lemmy. Its existence alone has lead many of them to not make an account, or run an instance: a clear net positive.\n\nYou can see for yourself the words which are blocked (content warning, [link here](https://github.com/LemmyNet/lemmy/blob/main/crates/utils/src/utils.rs#L10)). Note that it doesn't include any simple swear words, but only slurs which are used to insult and attack other people. If you want to use any of these words, then please stay on one of the many platforms that permit them. Lemmy is not for you, and we don't want you here.\n\nWe are fully aware that the slur filter is not perfect. It is made for American English, and can give false positives in other languages or dialects. We are totally willing to fix such problems on a case by case basis, simply open an issue in our [repo ](https://github.com/LemmyNet/lemmy/issues)with a description of the problem.",
+    "content": "This is a post in the /c/tenforward community",
     "mediaType": "text/markdown"
   },
+  "sensitive": false,
+  "commentsEnabled": true,
   "stickied": true,
-  "to": [
-    "https://lemmy.ml/c/announcements",
-    "https://www.w3.org/ns/activitystreams#Public"
-  ],
-  "type": "Page"
+  "published": "2021-02-26T12:35:34.292626+00:00"
 }
index 981cf25d1b2f991377199b7a0ebea5a355f799e2..374754215890f215d566c13b076044ab425ea9a0 100644 (file)
     },
     "https://w3id.org/security/v1"
   ],
-  "attributedTo": "https://lemmy.ml/u/nutomic",
-  "content": "test",
-  "id": "https://lemmy.ml/private_message/1621",
+  "id": "https://enterprise.lemmy.ml/private_message/1621",
+  "type": "ChatMessage",
+  "attributedTo": "https://enterprise.lemmy.ml/u/picard",
+  "to": [
+    "https://queer.hacktivis.me/users/lanodan"
+  ],
+  "content": "Hello hello, testing",
   "mediaType": "text/html",
-  "published": "2021-10-21T10:13:14.597721+00:00",
   "source": {
-    "content": "test",
+    "content": "Hello hello, testing",
     "mediaType": "text/markdown"
   },
-  "to": "https://queer.hacktivis.me/users/lanodan",
-  "type": "Note"
-}
\ No newline at end of file
+  "published": "2021-10-21T10:13:14.597721+00:00"
+}
index af5db78444e33e399735dd26270800975f67d11a..61b636309e34d6ba879c539013664af1dfa2ecb8 100644 (file)
@@ -16,7 +16,7 @@
   "context": "https://queer.hacktivis.me/contexts/34cba3d2-2f35-4169-aeff-56af9bfeb753",
   "conversation": "https://queer.hacktivis.me/contexts/34cba3d2-2f35-4169-aeff-56af9bfeb753",
   "id": "https://queer.hacktivis.me/objects/8d4973f4-53de-49cd-8c27-df160e16a9c2",
-  "inReplyTo": "https://lemmy.ml/post/55143",
+  "inReplyTo": "https://enterprise.lemmy.ml/post/55143",
   "published": "2021-10-07T18:06:52.555500Z",
   "sensitive": null,
   "source": "@popolon@pleroma.popolon.org Have what?",
diff --git a/crates/apub/assets/pleroma-private-message.json b/crates/apub/assets/pleroma-private-message.json
new file mode 100644 (file)
index 0000000..e4b987d
--- /dev/null
@@ -0,0 +1,17 @@
+{
+  "@context": [
+    "https://www.w3.org/ns/activitystreams",
+    "https://queer.hacktivis.me/schemas/litepub-0.1.jsonld",
+    {
+      "@language": "und"
+    }
+  ],
+  "attributedTo": "https://queer.hacktivis.me/users/lanodan",
+  "content": "Hi!",
+  "id": "https://queer.hacktivis.me/objects/2",
+  "published": "2020-02-12T14:08:20Z",
+  "to": [
+    "https://enterprise.lemmy.ml/u/picard"
+  ],
+  "type": "ChatMessage"
+}
index 43bde246597cc40c6b02a4c1d15bf083b7c6bb8c..c4591c7c84b3b5e8818817a426e1ef64ad8c87fb 100644 (file)
@@ -11,7 +11,6 @@ use crate::{
   },
   context::lemmy_context,
   fetcher::object_id::ObjectId,
-  migrations::PublicUrlMigration,
   objects::{
     comment::{ApubComment, Note},
     community::ApubCommunity,
@@ -23,6 +22,7 @@ use lemmy_api_common::{blocking, check_post_deleted_or_removed};
 use lemmy_apub_lib::{
   data::Data,
   traits::{ActivityFields, ActivityHandler, ActorType, FromApub, ToApub},
+  values::PublicUrl,
   verify::verify_domains_match,
 };
 use lemmy_db_schema::{
@@ -38,7 +38,7 @@ use url::Url;
 #[serde(rename_all = "camelCase")]
 pub struct CreateOrUpdateComment {
   actor: ObjectId<ApubPerson>,
-  to: PublicUrlMigration,
+  to: [PublicUrl; 1],
   object: Note,
   cc: Vec<Url>,
   tag: Vec<Mention>,
@@ -76,7 +76,7 @@ impl CreateOrUpdateComment {
 
     let create_or_update = CreateOrUpdateComment {
       actor: ObjectId::new(actor.actor_id()),
-      to: PublicUrlMigration::create(),
+      to: [PublicUrl::Public],
       object: comment.to_apub(context.pool()).await?,
       cc: maa.ccs,
       tag: maa.tags,
index a5b597f52bdd6629e5966a486be119380f6ddea3..e1cf03e0d0238be91c6fdc0c1d5f9bf1594db9da 100644 (file)
@@ -10,7 +10,6 @@ use crate::{
   context::lemmy_context,
   fetcher::object_id::ObjectId,
   generate_moderators_url,
-  migrations::PublicUrlMigration,
   objects::{community::ApubCommunity, person::ApubPerson},
 };
 use activitystreams::{
@@ -23,6 +22,7 @@ use lemmy_api_common::blocking;
 use lemmy_apub_lib::{
   data::Data,
   traits::{ActivityFields, ActivityHandler, ActorType},
+  values::PublicUrl,
 };
 use lemmy_db_schema::{
   source::community::{CommunityModerator, CommunityModeratorForm},
@@ -37,7 +37,7 @@ use url::Url;
 #[serde(rename_all = "camelCase")]
 pub struct AddMod {
   actor: ObjectId<ApubPerson>,
-  to: PublicUrlMigration,
+  to: [PublicUrl; 1],
   object: ObjectId<ApubPerson>,
   target: Url,
   cc: [ObjectId<ApubCommunity>; 1],
@@ -63,7 +63,7 @@ impl AddMod {
     )?;
     let add = AddMod {
       actor: ObjectId::new(actor.actor_id()),
-      to: PublicUrlMigration::create(),
+      to: [PublicUrl::Public],
       object: ObjectId::new(added_mod.actor_id()),
       target: generate_moderators_url(&community.actor_id)?.into(),
       cc: [ObjectId::new(community.actor_id())],
index 3fefac15f5364ee58b3812e40a1ed04f5697eadf..f3dc72c561d6ccd96d22ede6338182cef330baf6 100644 (file)
@@ -12,7 +12,6 @@ use crate::{
     deletion::{delete::Delete, undo_delete::UndoDelete},
     generate_activity_id,
     post::create_or_update::CreateOrUpdatePost,
-    undo_remove::UndoRemovePostCommentOrCommunity,
     verify_activity,
     verify_community,
     voting::{undo_vote::UndoVote, vote::Vote},
@@ -21,7 +20,6 @@ use crate::{
   fetcher::object_id::ObjectId,
   http::is_activity_already_known,
   insert_activity,
-  migrations::PublicUrlMigration,
   objects::community::ApubCommunity,
   send_lemmy_activity,
   CommunityType,
@@ -35,6 +33,7 @@ use activitystreams::{
 use lemmy_apub_lib::{
   data::Data,
   traits::{ActivityFields, ActivityHandler, ActorType},
+  values::PublicUrl,
 };
 use lemmy_utils::LemmyError;
 use lemmy_websocket::LemmyContext;
@@ -51,7 +50,6 @@ pub enum AnnouncableActivities {
   UndoVote(UndoVote),
   Delete(Delete),
   UndoDelete(UndoDelete),
-  UndoRemovePostCommentOrCommunity(UndoRemovePostCommentOrCommunity),
   UpdateCommunity(Box<UpdateCommunity>),
   BlockUserFromCommunity(BlockUserFromCommunity),
   UndoBlockUserFromCommunity(UndoBlockUserFromCommunity),
@@ -63,7 +61,7 @@ pub enum AnnouncableActivities {
 #[serde(rename_all = "camelCase")]
 pub struct AnnounceActivity {
   actor: ObjectId<ApubCommunity>,
-  to: PublicUrlMigration,
+  to: [PublicUrl; 1],
   object: AnnouncableActivities,
   cc: Vec<Url>,
   #[serde(rename = "type")]
@@ -84,7 +82,7 @@ impl AnnounceActivity {
   ) -> Result<(), LemmyError> {
     let announce = AnnounceActivity {
       actor: ObjectId::new(community.actor_id()),
-      to: PublicUrlMigration::create(),
+      to: [PublicUrl::Public],
       object,
       cc: vec![community.followers_url()],
       kind: AnnounceType::Announce,
index d8e131fc3fe562d836f6037d55be74bb1e432825..a1c76c23b88d47d4c21116dd8b8868447ce3a60f 100644 (file)
@@ -8,7 +8,6 @@ use crate::{
   },
   context::lemmy_context,
   fetcher::object_id::ObjectId,
-  migrations::PublicUrlMigration,
   objects::{community::ApubCommunity, person::ApubPerson},
 };
 use activitystreams::{
@@ -21,6 +20,7 @@ use lemmy_api_common::blocking;
 use lemmy_apub_lib::{
   data::Data,
   traits::{ActivityFields, ActivityHandler, ActorType},
+  values::PublicUrl,
 };
 use lemmy_db_schema::{
   source::community::{
@@ -40,7 +40,7 @@ use url::Url;
 #[serde(rename_all = "camelCase")]
 pub struct BlockUserFromCommunity {
   actor: ObjectId<ApubPerson>,
-  to: PublicUrlMigration,
+  to: [PublicUrl; 1],
   pub(in crate::activities::community) object: ObjectId<ApubPerson>,
   cc: [ObjectId<ApubCommunity>; 1],
   #[serde(rename = "type")]
@@ -61,7 +61,7 @@ impl BlockUserFromCommunity {
   ) -> Result<BlockUserFromCommunity, LemmyError> {
     Ok(BlockUserFromCommunity {
       actor: ObjectId::new(actor.actor_id()),
-      to: PublicUrlMigration::create(),
+      to: [PublicUrl::Public],
       object: ObjectId::new(target.actor_id()),
       cc: [ObjectId::new(community.actor_id())],
       kind: BlockType::Block,
index d7186114ddaf6a735d9356cf979724f08decdef5..9f4c9ae627c2638a0cbc89bfcfa4f1e13a757f40 100644 (file)
@@ -1,7 +1,6 @@
 use crate::{
   activities::{
     community::{announce::AnnouncableActivities, send_to_community},
-    deletion::{delete::receive_remove_action, verify_delete_activity},
     generate_activity_id,
     verify_activity,
     verify_add_remove_moderator_target,
@@ -11,7 +10,6 @@ use crate::{
   context::lemmy_context,
   fetcher::object_id::ObjectId,
   generate_moderators_url,
-  migrations::PublicUrlMigration,
   objects::{community::ApubCommunity, person::ApubPerson},
 };
 use activitystreams::{
@@ -24,6 +22,7 @@ use lemmy_api_common::blocking;
 use lemmy_apub_lib::{
   data::Data,
   traits::{ActivityFields, ActivityHandler, ActorType},
+  values::PublicUrl,
 };
 use lemmy_db_schema::{
   source::community::{CommunityModerator, CommunityModeratorForm},
@@ -38,13 +37,13 @@ use url::Url;
 #[serde(rename_all = "camelCase")]
 pub struct RemoveMod {
   actor: ObjectId<ApubPerson>,
-  to: PublicUrlMigration,
+  to: [PublicUrl; 1],
   pub(in crate::activities) object: ObjectId<ApubPerson>,
   cc: [ObjectId<ApubCommunity>; 1],
   #[serde(rename = "type")]
   kind: RemoveType,
   // if target is set, this is means remove mod from community
-  pub(in crate::activities) target: Option<Url>,
+  pub(in crate::activities) target: Url,
   id: Url,
   #[serde(rename = "@context")]
   context: OneOrMany<AnyBase>,
@@ -65,9 +64,9 @@ impl RemoveMod {
     )?;
     let remove = RemoveMod {
       actor: ObjectId::new(actor.actor_id()),
-      to: PublicUrlMigration::create(),
+      to: [PublicUrl::Public],
       object: ObjectId::new(removed_mod.actor_id()),
-      target: Some(generate_moderators_url(&community.actor_id)?.into()),
+      target: generate_moderators_url(&community.actor_id)?.into(),
       id: id.clone(),
       context: lemmy_context(),
       cc: [ObjectId::new(community.actor_id())],
@@ -90,21 +89,9 @@ impl ActivityHandler for RemoveMod {
     request_counter: &mut i32,
   ) -> Result<(), LemmyError> {
     verify_activity(self, &context.settings())?;
-    if let Some(target) = &self.target {
-      verify_person_in_community(&self.actor, &self.cc[0], context, request_counter).await?;
-      verify_mod_action(&self.actor, &self.cc[0], context, request_counter).await?;
-      verify_add_remove_moderator_target(target, &self.cc[0])?;
-    } else {
-      verify_delete_activity(
-        self.object.inner(),
-        self,
-        &self.cc[0],
-        true,
-        context,
-        request_counter,
-      )
-      .await?;
-    }
+    verify_person_in_community(&self.actor, &self.cc[0], context, request_counter).await?;
+    verify_mod_action(&self.actor, &self.cc[0], context, request_counter).await?;
+    verify_add_remove_moderator_target(&self.target, &self.cc[0])?;
     Ok(())
   }
 
@@ -113,29 +100,18 @@ impl ActivityHandler for RemoveMod {
     context: &Data<LemmyContext>,
     request_counter: &mut i32,
   ) -> Result<(), LemmyError> {
-    if self.target.is_some() {
-      let community = self.cc[0].dereference(context, request_counter).await?;
-      let remove_mod = self.object.dereference(context, request_counter).await?;
+    let community = self.cc[0].dereference(context, request_counter).await?;
+    let remove_mod = self.object.dereference(context, request_counter).await?;
 
-      let form = CommunityModeratorForm {
-        community_id: community.id,
-        person_id: remove_mod.id,
-      };
-      blocking(context.pool(), move |conn| {
-        CommunityModerator::leave(conn, &form)
-      })
-      .await??;
-      // TODO: send websocket notification about removed mod
-      Ok(())
-    } else {
-      receive_remove_action(
-        &self.actor,
-        self.object.inner(),
-        None,
-        context,
-        request_counter,
-      )
-      .await
-    }
+    let form = CommunityModeratorForm {
+      community_id: community.id,
+      person_id: remove_mod.id,
+    };
+    blocking(context.pool(), move |conn| {
+      CommunityModerator::leave(conn, &form)
+    })
+    .await??;
+    // TODO: send websocket notification about removed mod
+    Ok(())
   }
 }
index 6b405cf48d9964ea9028b5eddcfa8a132e8de6c4..1614de672d9b131439ddbf425326fca5950c50f0 100644 (file)
@@ -12,7 +12,6 @@ use crate::{
   },
   context::lemmy_context,
   fetcher::object_id::ObjectId,
-  migrations::PublicUrlMigration,
   objects::{community::ApubCommunity, person::ApubPerson},
 };
 use activitystreams::{
@@ -25,6 +24,7 @@ use lemmy_api_common::blocking;
 use lemmy_apub_lib::{
   data::Data,
   traits::{ActivityFields, ActivityHandler, ActorType},
+  values::PublicUrl,
 };
 use lemmy_db_schema::{
   source::community::{CommunityPersonBan, CommunityPersonBanForm},
@@ -39,7 +39,7 @@ use url::Url;
 #[serde(rename_all = "camelCase")]
 pub struct UndoBlockUserFromCommunity {
   actor: ObjectId<ApubPerson>,
-  to: PublicUrlMigration,
+  to: [PublicUrl; 1],
   object: BlockUserFromCommunity,
   cc: [ObjectId<ApubCommunity>; 1],
   #[serde(rename = "type")]
@@ -66,7 +66,7 @@ impl UndoBlockUserFromCommunity {
     )?;
     let undo = UndoBlockUserFromCommunity {
       actor: ObjectId::new(actor.actor_id()),
-      to: PublicUrlMigration::create(),
+      to: [PublicUrl::Public],
       object: block,
       cc: [ObjectId::new(community.actor_id())],
       kind: UndoType::Undo,
index 3a7b44fee31cf9c45d110a0ad904cd0c7bba9669..1120bd8bb70d136a2f23f24133b940c6782740b3 100644 (file)
@@ -8,7 +8,6 @@ use crate::{
   },
   context::lemmy_context,
   fetcher::object_id::ObjectId,
-  migrations::PublicUrlMigration,
   objects::{
     community::{ApubCommunity, Group},
     person::ApubPerson,
@@ -24,6 +23,7 @@ use lemmy_api_common::blocking;
 use lemmy_apub_lib::{
   data::Data,
   traits::{ActivityFields, ActivityHandler, ActorType, ToApub},
+  values::PublicUrl,
 };
 use lemmy_db_schema::{
   source::community::{Community, CommunityForm},
@@ -40,7 +40,7 @@ use url::Url;
 #[serde(rename_all = "camelCase")]
 pub struct UpdateCommunity {
   actor: ObjectId<ApubPerson>,
-  to: PublicUrlMigration,
+  to: [PublicUrl; 1],
   // TODO: would be nice to use a separate struct here, which only contains the fields updated here
   object: Group,
   cc: [ObjectId<ApubCommunity>; 1],
@@ -65,7 +65,7 @@ impl UpdateCommunity {
     )?;
     let update = UpdateCommunity {
       actor: ObjectId::new(actor.actor_id()),
-      to: PublicUrlMigration::create(),
+      to: [PublicUrl::Public],
       object: community.to_apub(context.pool()).await?,
       cc: [ObjectId::new(community.actor_id())],
       kind: UpdateType::Update,
index acfc1ba7ef3ad84264eeb37406f4f29a00c6321f..02df7dc38a2d87de5f133179fa09689e55060e3a 100644 (file)
@@ -12,7 +12,6 @@ use crate::{
   },
   context::lemmy_context,
   fetcher::object_id::ObjectId,
-  migrations::PublicUrlMigration,
   objects::{community::ApubCommunity, person::ApubPerson},
 };
 use activitystreams::{
@@ -26,6 +25,7 @@ use lemmy_api_common::blocking;
 use lemmy_apub_lib::{
   data::Data,
   traits::{ActivityFields, ActivityHandler, ActorType},
+  values::PublicUrl,
 };
 use lemmy_db_schema::{
   source::{
@@ -66,7 +66,7 @@ use url::Url;
 #[serde(rename_all = "camelCase")]
 pub struct Delete {
   actor: ObjectId<ApubPerson>,
-  to: PublicUrlMigration,
+  to: [PublicUrl; 1],
   pub(in crate::activities::deletion) object: Url,
   pub(in crate::activities::deletion) cc: [ObjectId<ApubCommunity>; 1],
   #[serde(rename = "type")]
@@ -144,7 +144,7 @@ impl Delete {
   ) -> Result<Delete, LemmyError> {
     Ok(Delete {
       actor: ObjectId::new(actor.actor_id()),
-      to: PublicUrlMigration::create(),
+      to: [PublicUrl::Public],
       object: object_id,
       cc: [ObjectId::new(community.actor_id())],
       kind: DeleteType::Delete,
index 2527a97172da5274fe83eb111a817dfd774532d4..327bf86c03a6ac28888d733b62f149f36c4fc6da 100644 (file)
@@ -13,7 +13,6 @@ use crate::{
   },
   context::lemmy_context,
   fetcher::object_id::ObjectId,
-  migrations::PublicUrlMigration,
   objects::{community::ApubCommunity, person::ApubPerson},
 };
 use activitystreams::{
@@ -27,6 +26,7 @@ use lemmy_api_common::blocking;
 use lemmy_apub_lib::{
   data::Data,
   traits::{ActivityFields, ActivityHandler, ActorType},
+  values::PublicUrl,
 };
 use lemmy_db_schema::source::{comment::Comment, community::Community, post::Post};
 use lemmy_utils::LemmyError;
@@ -42,7 +42,7 @@ use url::Url;
 #[serde(rename_all = "camelCase")]
 pub struct UndoDelete {
   actor: ObjectId<ApubPerson>,
-  to: PublicUrlMigration,
+  to: [PublicUrl; 1],
   object: Delete,
   cc: [ObjectId<ApubCommunity>; 1],
   #[serde(rename = "type")]
@@ -117,7 +117,7 @@ impl UndoDelete {
     )?;
     let undo = UndoDelete {
       actor: ObjectId::new(actor.actor_id()),
-      to: PublicUrlMigration::create(),
+      to: [PublicUrl::Public],
       object,
       cc: [ObjectId::new(community.actor_id())],
       kind: UndoType::Undo,
index f59a93850468c375042bfba25f84ffebe1508670..14a67394e8c09e3b277942404dd55fcc5353ae60 100644 (file)
@@ -26,7 +26,6 @@ pub mod following;
 pub mod post;
 pub mod private_message;
 pub mod report;
-pub mod undo_remove;
 pub mod voting;
 
 #[derive(Clone, Debug, ToString, Deserialize, Serialize)]
index cda78ce1edbe07a6b285732625e548d6170e6f05..cc7ef5c97c015110616957304f74af2b44a06c32 100644 (file)
@@ -10,7 +10,6 @@ use crate::{
   },
   context::lemmy_context,
   fetcher::object_id::ObjectId,
-  migrations::PublicUrlMigration,
   objects::{
     community::ApubCommunity,
     person::ApubPerson,
@@ -23,6 +22,7 @@ use lemmy_api_common::blocking;
 use lemmy_apub_lib::{
   data::Data,
   traits::{ActivityFields, ActivityHandler, ActorType, FromApub, ToApub},
+  values::PublicUrl,
   verify::{verify_domains_match, verify_urls_match},
 };
 use lemmy_db_schema::{source::community::Community, traits::Crud};
@@ -35,7 +35,7 @@ use url::Url;
 #[serde(rename_all = "camelCase")]
 pub struct CreateOrUpdatePost {
   actor: ObjectId<ApubPerson>,
-  to: PublicUrlMigration,
+  to: [PublicUrl; 1],
   object: Page,
   cc: [ObjectId<ApubCommunity>; 1],
   #[serde(rename = "type")]
@@ -67,7 +67,7 @@ impl CreateOrUpdatePost {
     )?;
     let create_or_update = CreateOrUpdatePost {
       actor: ObjectId::new(actor.actor_id()),
-      to: PublicUrlMigration::create(),
+      to: [PublicUrl::Public],
       object: post.to_apub(context.pool()).await?,
       cc: [ObjectId::new(community.actor_id())],
       kind,
diff --git a/crates/apub/src/activities/undo_remove.rs b/crates/apub/src/activities/undo_remove.rs
deleted file mode 100644 (file)
index 5734649..0000000
+++ /dev/null
@@ -1,73 +0,0 @@
-use crate::{
-  activities::{
-    community::remove_mod::RemoveMod,
-    deletion::{undo_delete::UndoDelete, verify_delete_activity},
-    verify_activity,
-  },
-  fetcher::object_id::ObjectId,
-  migrations::PublicUrlMigration,
-  objects::{community::ApubCommunity, person::ApubPerson},
-};
-use activitystreams::{
-  activity::kind::UndoType,
-  base::AnyBase,
-  primitives::OneOrMany,
-  unparsed::Unparsed,
-};
-use lemmy_apub_lib::{
-  data::Data,
-  traits::{ActivityFields, ActivityHandler},
-};
-use lemmy_utils::LemmyError;
-use lemmy_websocket::LemmyContext;
-use serde::{Deserialize, Serialize};
-use url::Url;
-
-#[derive(Clone, Debug, Deserialize, Serialize, ActivityFields)]
-#[serde(rename_all = "camelCase")]
-pub struct UndoRemovePostCommentOrCommunity {
-  actor: ObjectId<ApubPerson>,
-  to: PublicUrlMigration,
-  // Note, there is no such thing as Undo/Remove/Mod, so we ignore that
-  object: RemoveMod,
-  cc: [ObjectId<ApubCommunity>; 1],
-  #[serde(rename = "type")]
-  kind: UndoType,
-  id: Url,
-  #[serde(rename = "@context")]
-  context: OneOrMany<AnyBase>,
-  #[serde(flatten)]
-  unparsed: Unparsed,
-}
-
-#[async_trait::async_trait(?Send)]
-impl ActivityHandler for UndoRemovePostCommentOrCommunity {
-  type DataType = LemmyContext;
-  async fn verify(
-    &self,
-    context: &Data<LemmyContext>,
-    request_counter: &mut i32,
-  ) -> Result<(), LemmyError> {
-    verify_activity(self, &context.settings())?;
-    self.object.verify(context, request_counter).await?;
-
-    verify_delete_activity(
-      self.object.object.inner(),
-      self,
-      &self.cc[0],
-      true,
-      context,
-      request_counter,
-    )
-    .await?;
-    Ok(())
-  }
-
-  async fn receive(
-    self,
-    context: &Data<LemmyContext>,
-    _request_counter: &mut i32,
-  ) -> Result<(), LemmyError> {
-    UndoDelete::receive_undo_remove_action(self.object.object.inner(), context).await
-  }
-}
index fa7a1119556becab41ee3eac7ec76d747b2c39b4..d72b5245dce641f5bae0a0e472b108c371d4efe6 100644 (file)
@@ -12,7 +12,6 @@ use crate::{
   },
   context::lemmy_context,
   fetcher::object_id::ObjectId,
-  migrations::PublicUrlMigration,
   objects::{community::ApubCommunity, person::ApubPerson},
   PostOrComment,
 };
@@ -26,6 +25,7 @@ use lemmy_api_common::blocking;
 use lemmy_apub_lib::{
   data::Data,
   traits::{ActivityFields, ActivityHandler, ActorType},
+  values::PublicUrl,
   verify::verify_urls_match,
 };
 use lemmy_db_schema::{newtypes::CommunityId, source::community::Community, traits::Crud};
@@ -39,7 +39,7 @@ use url::Url;
 #[serde(rename_all = "camelCase")]
 pub struct UndoVote {
   actor: ObjectId<ApubPerson>,
-  to: PublicUrlMigration,
+  to: [PublicUrl; 1],
   object: Vote,
   cc: [ObjectId<ApubCommunity>; 1],
   #[serde(rename = "type")]
@@ -72,7 +72,7 @@ impl UndoVote {
     )?;
     let undo_vote = UndoVote {
       actor: ObjectId::new(actor.actor_id()),
-      to: PublicUrlMigration::create(),
+      to: [PublicUrl::Public],
       object,
       cc: [ObjectId::new(community.actor_id())],
       kind: UndoType::Undo,
index 847ffbd4c23a0524b491c09bf7764c8266c41f37..5d4c9066e51f63bee436928f9964b8399e458b1d 100644 (file)
@@ -8,7 +8,6 @@ use crate::{
   },
   context::lemmy_context,
   fetcher::object_id::ObjectId,
-  migrations::PublicUrlMigration,
   objects::{community::ApubCommunity, person::ApubPerson},
   PostOrComment,
 };
@@ -18,6 +17,7 @@ use lemmy_api_common::blocking;
 use lemmy_apub_lib::{
   data::Data,
   traits::{ActivityFields, ActivityHandler, ActorType},
+  values::PublicUrl,
 };
 use lemmy_db_schema::{newtypes::CommunityId, source::community::Community, traits::Crud};
 use lemmy_utils::LemmyError;
@@ -58,7 +58,7 @@ impl From<&VoteType> for i16 {
 #[serde(rename_all = "camelCase")]
 pub struct Vote {
   actor: ObjectId<ApubPerson>,
-  to: PublicUrlMigration,
+  to: [PublicUrl; 1],
   pub(in crate::activities::voting) object: ObjectId<PostOrComment>,
   cc: [ObjectId<ApubCommunity>; 1],
   #[serde(rename = "type")]
@@ -80,7 +80,7 @@ impl Vote {
   ) -> Result<Vote, LemmyError> {
     Ok(Vote {
       actor: ObjectId::new(actor.actor_id()),
-      to: PublicUrlMigration::create(),
+      to: [PublicUrl::Public],
       object: ObjectId::new(object.ap_id()),
       cc: [ObjectId::new(community.actor_id())],
       kind: kind.clone(),
index e8b075c45353d1e4a1a8aae91f0013c367e5a2cb..8b137891791fe96927ad78e64b0aad7bded08bdc 100644 (file)
@@ -1,49 +1 @@
-use crate::fetcher::{object_id::ObjectId, post_or_comment::PostOrComment};
-use lemmy_apub_lib::values::PublicUrl;
-use serde::{Deserialize, Serialize};
-use url::Url;
 
-/// Migrate comment.in_reply_to field from containing post and parent comment ID, to only containing
-/// the direct parent (whether its a post or comment). This is for compatibility with Pleroma and
-/// Smithereen.
-/// [https://github.com/LemmyNet/lemmy/issues/1454]
-///
-/// v0.12: receive both, send old (compatible with v0.11)
-/// v0.13 receive both, send new (compatible with v0.12+, incompatible with v0.11)
-/// v0.14: only send and receive new, remove migration (compatible with v0.13+)
-#[derive(Serialize, Deserialize, Debug, Clone)]
-#[serde(untagged)]
-pub enum CommentInReplyToMigration {
-  Old(Vec<Url>),
-  New(ObjectId<PostOrComment>),
-}
-
-// Another migration we are doing is to handle all deletions and removals using Delete activity.
-// This is because Remove is for removing an object from a collection, so using it that way doesn't
-// really make sense. It is also a problem because we have a RemoveMod activity, which was awkward
-// to handle together with removing posts etc.
-//
-// v0.11: send and receive mod removals as Remove
-// v0.12: receive removals as Remove, send as Delete (compatible with v0.11)
-// v0.13: send and receive mod removals as Delete (compatible with v0.12)
-//
-// For v0.13, delete [`UndoRemovePostCommentOrCommunity`], and don't handle object deletion in
-// [`RemoveMod`] handler.
-
-/// Migrate value of field `to` from single value to vec.
-///
-/// v0.14: send as single value, accept both
-/// v0.15: send as vec, accept both
-/// v0.16: send and accept only vec
-#[derive(Serialize, Deserialize, Debug, Clone)]
-#[serde(untagged)]
-pub enum PublicUrlMigration {
-  Old(PublicUrl),
-  New([PublicUrl; 1]),
-}
-
-impl PublicUrlMigration {
-  pub(crate) fn create() -> PublicUrlMigration {
-    PublicUrlMigration::Old(PublicUrl::Public)
-  }
-}
index fc02b8f3731874ff3048d827d6c6acdda083dee6..5fe4fa690d78d1e66a845a3db68193d680723620 100644 (file)
@@ -2,7 +2,6 @@ use crate::{
   activities::{verify_is_public, verify_person_in_community},
   context::lemmy_context,
   fetcher::object_id::ObjectId,
-  migrations::CommentInReplyToMigration,
   objects::{create_tombstone, person::ApubPerson, post::ApubPost, Source},
   PostOrComment,
 };
@@ -14,7 +13,7 @@ use activitystreams::{
   public,
   unparsed::Unparsed,
 };
-use anyhow::{anyhow, Context};
+use anyhow::anyhow;
 use chrono::{DateTime, FixedOffset};
 use html2md::parse_html;
 use lemmy_api_common::blocking;
@@ -35,7 +34,6 @@ use lemmy_db_schema::{
   DbPool,
 };
 use lemmy_utils::{
-  location_info,
   utils::{convert_datetime, remove_slurs},
   LemmyError,
 };
@@ -61,7 +59,7 @@ pub struct Note {
   content: String,
   media_type: Option<MediaTypeHtml>,
   source: SourceCompat,
-  in_reply_to: CommentInReplyToMigration,
+  in_reply_to: ObjectId<PostOrComment>,
   published: Option<DateTime<FixedOffset>>,
   updated: Option<DateTime<FixedOffset>>,
   #[serde(flatten)]
@@ -91,43 +89,25 @@ impl Note {
     context: &LemmyContext,
     request_counter: &mut i32,
   ) -> Result<(ApubPost, Option<CommentId>), LemmyError> {
-    match &self.in_reply_to {
-      CommentInReplyToMigration::Old(in_reply_to) => {
-        // This post, or the parent comment might not yet exist on this server yet, fetch them.
-        let post_id = in_reply_to.get(0).context(location_info!())?;
-        let post_id = ObjectId::new(post_id.clone());
-        let post = Box::pin(post_id.dereference(context, request_counter)).await?;
-
-        // The 2nd item, if it exists, is the parent comment apub_id
-        // Nested comments will automatically get fetched recursively
-        let parent_id: Option<CommentId> = match in_reply_to.get(1) {
-          Some(comment_id) => {
-            let comment_id = ObjectId::<ApubComment>::new(comment_id.clone());
-            let parent_comment = Box::pin(comment_id.dereference(context, request_counter)).await?;
-
-            Some(parent_comment.id)
-          }
-          None => None,
-        };
-
-        Ok((post, parent_id))
+    // Fetch parent comment chain in a box, otherwise it can cause a stack overflow.
+    let parent = Box::pin(
+      self
+        .in_reply_to
+        .dereference(context, request_counter)
+        .await?,
+    );
+    match parent.deref() {
+      PostOrComment::Post(p) => {
+        // Workaround because I cant figure out how to get the post out of the box (and we dont
+        // want to stackoverflow in a deep comment hierarchy).
+        let post_id = p.id;
+        let post = blocking(context.pool(), move |conn| Post::read(conn, post_id)).await??;
+        Ok((post.into(), None))
       }
-      CommentInReplyToMigration::New(in_reply_to) => {
-        let parent = Box::pin(in_reply_to.dereference(context, request_counter).await?);
-        match parent.deref() {
-          PostOrComment::Post(p) => {
-            // Workaround because I cant figure out how to get the post out of the box (and we dont
-            // want to stackoverflow in a deep comment hierarchy).
-            let post_id = p.id;
-            let post = blocking(context.pool(), move |conn| Post::read(conn, post_id)).await??;
-            Ok((post.into(), None))
-          }
-          PostOrComment::Comment(c) => {
-            let post_id = c.post_id;
-            let post = blocking(context.pool(), move |conn| Post::read(conn, post_id)).await??;
-            Ok((post.into(), Some(c.id)))
-          }
-        }
+      PostOrComment::Comment(c) => {
+        let post_id = c.post_id;
+        let post = blocking(context.pool(), move |conn| Post::read(conn, post_id)).await??;
+        Ok((post.into(), Some(c.id)))
       }
     }
   }
@@ -219,15 +199,12 @@ impl ToApub for ApubComment {
     let post_id = self.post_id;
     let post = blocking(pool, move |conn| Post::read(conn, post_id)).await??;
 
-    // Add a vector containing some important info to the "in_reply_to" field
-    // [post_ap_id, Option(parent_comment_ap_id)]
-    let mut in_reply_to_vec = vec![post.ap_id.into_inner()];
-
-    if let Some(parent_id) = self.parent_id {
-      let parent_comment = blocking(pool, move |conn| Comment::read(conn, parent_id)).await??;
-
-      in_reply_to_vec.push(parent_comment.ap_id.into_inner());
-    }
+    let in_reply_to = if let Some(comment_id) = self.parent_id {
+      let parent_comment = blocking(pool, move |conn| Comment::read(conn, comment_id)).await??;
+      ObjectId::<PostOrComment>::new(parent_comment.ap_id.into_inner())
+    } else {
+      ObjectId::<PostOrComment>::new(post.ap_id.into_inner())
+    };
 
     let note = Note {
       context: lemmy_context(),
@@ -241,7 +218,7 @@ impl ToApub for ApubComment {
         content: self.content.clone(),
         media_type: MediaTypeMarkdown::Markdown,
       }),
-      in_reply_to: CommentInReplyToMigration::Old(in_reply_to_vec),
+      in_reply_to,
       published: Some(convert_datetime(self.published)),
       updated: self.updated.map(convert_datetime),
       unparsed: Default::default(),
@@ -346,9 +323,9 @@ mod tests {
 
   #[actix_rt::test]
   #[serial]
-  async fn test_fetch_lemmy_comment() {
+  async fn test_parse_lemmy_comment() {
     let context = init_context();
-    let url = Url::parse("https://lemmy.ml/comment/38741").unwrap();
+    let url = Url::parse("https://enterprise.lemmy.ml/comment/38741").unwrap();
     let data = prepare_comment_test(&url, &context).await;
 
     let json = file_to_json_object("assets/lemmy-comment.json");
@@ -358,7 +335,7 @@ mod tests {
       .unwrap();
 
     assert_eq!(comment.ap_id.clone().into_inner(), url);
-    assert_eq!(comment.content.len(), 1063);
+    assert_eq!(comment.content.len(), 14);
     assert!(!comment.local);
     assert_eq!(request_counter, 0);
 
@@ -371,9 +348,9 @@ mod tests {
 
   #[actix_rt::test]
   #[serial]
-  async fn test_fetch_pleroma_comment() {
+  async fn test_parse_pleroma_comment() {
     let context = init_context();
-    let url = Url::parse("https://lemmy.ml/comment/38741").unwrap();
+    let url = Url::parse("https://enterprise.lemmy.ml/comment/38741").unwrap();
     let data = prepare_comment_test(&url, &context).await;
 
     let pleroma_url =
index 525ae854d5e3b874146a73765a81501c4276e21a..74d417c3920d404aa4e0a78c8fef04f8d65b29c4 100644 (file)
@@ -4,7 +4,7 @@ use crate::{
   fetcher::community::{fetch_community_outbox, update_community_mods},
   generate_moderators_url,
   generate_outbox_url,
-  objects::{create_tombstone, ImageObject, Source},
+  objects::{create_tombstone, get_summary_from_string_or_source, ImageObject, Source},
   CommunityType,
 };
 use activitystreams::{
@@ -21,7 +21,7 @@ use lemmy_api_common::blocking;
 use lemmy_apub_lib::{
   signatures::PublicKey,
   traits::{ActorType, ApubObject, FromApub, ToApub},
-  values::{MediaTypeHtml, MediaTypeMarkdown},
+  values::MediaTypeMarkdown,
   verify::verify_domains_match,
 };
 use lemmy_db_schema::{
@@ -55,8 +55,7 @@ pub struct Group {
   preferred_username: String,
   /// title (can be changed at any time)
   name: String,
-  content: Option<String>,
-  media_type: Option<MediaTypeHtml>,
+  summary: Option<String>,
   source: Option<Source>,
   icon: Option<ImageObject>,
   /// banner
@@ -89,7 +88,7 @@ impl Group {
     let actor_id = Some(group.id(expected_domain)?.clone().into());
     let name = group.preferred_username.clone();
     let title = group.name.clone();
-    let description = group.source.clone().map(|s| s.content);
+    let description = get_summary_from_string_or_source(&group.summary, &group.source);
     let shared_inbox = group.endpoints.shared_inbox.clone().map(|s| s.into());
 
     let slur_regex = &settings.slur_regex();
@@ -218,8 +217,7 @@ impl ToApub for ApubCommunity {
       id: self.actor_id(),
       preferred_username: self.name.clone(),
       name: self.title.clone(),
-      content: self.description.as_ref().map(|b| markdown_to_html(b)),
-      media_type: self.description.as_ref().map(|_| MediaTypeHtml::Html),
+      summary: self.description.as_ref().map(|b| markdown_to_html(b)),
       source,
       icon,
       image,
@@ -324,25 +322,26 @@ mod tests {
 
   #[actix_rt::test]
   #[serial]
-  async fn test_fetch_lemmy_community() {
+  async fn test_parse_lemmy_community() {
     let context = init_context();
     let mut json: Group = file_to_json_object("assets/lemmy-community.json");
     let json_orig = json.clone();
     // change these links so they dont fetch over the network
-    json.moderators = Some(Url::parse("https://lemmy.ml/c/announcements/not_moderators").unwrap());
-    json.outbox = Url::parse("https://lemmy.ml/c/announcements/not_outbox").unwrap();
+    json.moderators =
+      Some(Url::parse("https://enterprise.lemmy.ml/c/tenforward/not_moderators").unwrap());
+    json.outbox = Url::parse("https://enterprise.lemmy.ml/c/tenforward/not_outbox").unwrap();
 
-    let url = Url::parse("https://lemmy.ml/c/announcements").unwrap();
+    let url = Url::parse("https://enterprise.lemmy.ml/c/tenforward").unwrap();
     let mut request_counter = 0;
     let community = ApubCommunity::from_apub(&json, &context, &url, &mut request_counter)
       .await
       .unwrap();
 
     assert_eq!(community.actor_id.clone().into_inner(), url);
-    assert_eq!(community.title, "Announcements");
+    assert_eq!(community.title, "Ten Forward");
     assert!(community.public_key.is_some());
     assert!(!community.local);
-    assert_eq!(community.description.as_ref().unwrap().len(), 126);
+    assert_eq!(community.description.as_ref().unwrap().len(), 132);
     // this makes two requests to the (intentionally) broken outbox/moderators collections
     assert_eq!(request_counter, 2);
 
index 61f0f2808debd8900dd9177cff00c571ae12102c..76c258ce27ab444f3416fe874b263fdb650682be 100644 (file)
@@ -4,8 +4,10 @@ use activitystreams::{
 };
 use anyhow::anyhow;
 use chrono::NaiveDateTime;
+use html2md::parse_html;
 use lemmy_apub_lib::values::MediaTypeMarkdown;
 use lemmy_utils::{utils::convert_datetime, LemmyError};
+use serde::{Deserialize, Serialize};
 use url::Url;
 
 pub mod comment;
@@ -14,14 +16,14 @@ pub mod person;
 pub mod post;
 pub mod private_message;
 
-#[derive(Clone, Debug, serde::Deserialize, serde::Serialize)]
+#[derive(Clone, Debug, Deserialize, Serialize)]
 #[serde(rename_all = "camelCase")]
 pub struct Source {
   content: String,
   media_type: MediaTypeMarkdown,
 }
 
-#[derive(Clone, Debug, serde::Deserialize, serde::Serialize)]
+#[derive(Clone, Debug, Deserialize, Serialize)]
 #[serde(rename_all = "camelCase")]
 pub struct ImageObject {
   #[serde(rename = "type")]
@@ -54,6 +56,17 @@ where
   }
 }
 
+fn get_summary_from_string_or_source(
+  raw: &Option<String>,
+  source: &Option<Source>,
+) -> Option<String> {
+  if let Some(source) = &source {
+    Some(source.content.clone())
+  } else {
+    raw.as_ref().map(|s| parse_html(s))
+  }
+}
+
 #[cfg(test)]
 mod tests {
   use super::*;
index 7d5b99234a758664034e4bda71c4d4a06c3d8ce6..99847562f87dd300e58af96e5600094554a433d5 100644 (file)
@@ -2,7 +2,7 @@ use crate::{
   check_is_apub_id_valid,
   context::lemmy_context,
   generate_outbox_url,
-  objects::{ImageObject, Source},
+  objects::{get_summary_from_string_or_source, ImageObject, Source},
 };
 use activitystreams::{
   actor::Endpoints,
@@ -17,7 +17,7 @@ use lemmy_api_common::blocking;
 use lemmy_apub_lib::{
   signatures::PublicKey,
   traits::{ActorType, ApubObject, FromApub, ToApub},
-  values::{MediaTypeHtml, MediaTypeMarkdown},
+  values::MediaTypeMarkdown,
   verify::verify_domains_match,
 };
 use lemmy_db_schema::{
@@ -54,8 +54,7 @@ pub struct Person {
   preferred_username: String,
   /// displayname (can be changed at any time)
   name: Option<String>,
-  content: Option<String>,
-  media_type: Option<MediaTypeHtml>,
+  summary: Option<String>,
   source: Option<Source>,
   /// user avatar
   icon: Option<ImageObject>,
@@ -186,8 +185,7 @@ impl ToApub for ApubPerson {
       id: self.actor_id.to_owned().into_inner(),
       preferred_username: self.name.clone(),
       name: self.display_name.clone(),
-      content: self.bio.as_ref().map(|b| markdown_to_html(b)),
-      media_type: self.bio.as_ref().map(|_| MediaTypeHtml::Html),
+      summary: self.bio.as_ref().map(|b| markdown_to_html(b)),
       source,
       icon,
       image,
@@ -224,7 +222,7 @@ impl FromApub for ApubPerson {
     let actor_id = Some(person.id(expected_domain)?.clone().into());
     let name = person.preferred_username.clone();
     let display_name: Option<String> = person.name.clone();
-    let bio = person.source.clone().map(|s| s.content);
+    let bio = get_summary_from_string_or_source(&person.summary, &person.source);
     let shared_inbox = person.endpoints.shared_inbox.clone().map(|s| s.into());
     let bot_account = match person.kind {
       UserTypes::Person => false,
@@ -277,20 +275,20 @@ mod tests {
 
   #[actix_rt::test]
   #[serial]
-  async fn test_fetch_lemmy_person() {
+  async fn test_parse_lemmy_person() {
     let context = init_context();
     let json = file_to_json_object("assets/lemmy-person.json");
-    let url = Url::parse("https://lemmy.ml/u/nutomic").unwrap();
+    let url = Url::parse("https://enterprise.lemmy.ml/u/picard").unwrap();
     let mut request_counter = 0;
     let person = ApubPerson::from_apub(&json, &context, &url, &mut request_counter)
       .await
       .unwrap();
 
     assert_eq!(person.actor_id.clone().into_inner(), url);
-    assert_eq!(person.name, "nutomic");
+    assert_eq!(person.display_name, Some("Jean-Luc Picard".to_string()));
     assert!(person.public_key.is_some());
     assert!(!person.local);
-    assert!(person.bio.is_some());
+    assert_eq!(person.bio.as_ref().unwrap().len(), 39);
     assert_eq!(request_counter, 0);
 
     let to_apub = person.to_apub(context.pool()).await.unwrap();
@@ -301,7 +299,7 @@ mod tests {
 
   #[actix_rt::test]
   #[serial]
-  async fn test_fetch_pleroma_person() {
+  async fn test_parse_pleroma_person() {
     let context = init_context();
     let json = file_to_json_object("assets/pleroma-person.json");
     let url = Url::parse("https://queer.hacktivis.me/users/lanodan").unwrap();
@@ -315,8 +313,7 @@ mod tests {
     assert!(person.public_key.is_some());
     assert!(!person.local);
     assert_eq!(request_counter, 0);
-    // TODO: pleroma uses summary for user profile, while we use content
-    //assert!(person.bio.is_some());
+    assert_eq!(person.bio.as_ref().unwrap().len(), 873);
 
     DbPerson::delete(&*context.pool().get().unwrap(), person.id).unwrap();
   }
index 47b4b99a930e574667ee2cf509a3f00271822c62..a56bbd59029237ff0307efc5dd1b9a7542ca7050 100644 (file)
@@ -290,9 +290,9 @@ mod tests {
 
   #[actix_rt::test]
   #[serial]
-  async fn test_fetch_lemmy_post() {
+  async fn test_parse_lemmy_post() {
     let context = init_context();
-    let url = Url::parse("https://lemmy.ml/post/55143").unwrap();
+    let url = Url::parse("https://enterprise.lemmy.ml/post/55143").unwrap();
     let community_json = file_to_json_object("assets/lemmy-community.json");
     let community = ApubCommunity::from_apub(&community_json, &context, &url, &mut 0)
       .await
@@ -308,9 +308,9 @@ mod tests {
       .unwrap();
 
     assert_eq!(post.ap_id.clone().into_inner(), url);
-    assert_eq!(post.name, "Statement on Politics of Lemmy.ml");
+    assert_eq!(post.name, "Post title");
     assert!(post.body.is_some());
-    assert_eq!(post.body.as_ref().unwrap().len(), 2144);
+    assert_eq!(post.body.as_ref().unwrap().len(), 45);
     assert!(!post.locked);
     assert!(post.stickied);
     assert_eq!(request_counter, 0);
index cf622eccbdaf7a3bb4c7ee44cbb1034503e6b378..bd9cc1da479ae16a2aca4cb39be5eef009790c58 100644 (file)
@@ -12,6 +12,7 @@ use activitystreams::{
 };
 use anyhow::anyhow;
 use chrono::{DateTime, FixedOffset};
+use html2md::parse_html;
 use lemmy_api_common::blocking;
 use lemmy_apub_lib::{
   traits::{ApubObject, FromApub, ToApub},
@@ -39,19 +40,25 @@ use url::Url;
 pub struct Note {
   #[serde(rename = "@context")]
   context: OneOrMany<AnyBase>,
-  r#type: NoteType,
+  r#type: ChatMessageType,
   id: Url,
   pub(crate) attributed_to: ObjectId<ApubPerson>,
-  to: ObjectId<ApubPerson>,
+  to: [ObjectId<ApubPerson>; 1],
   content: String,
-  media_type: MediaTypeHtml,
-  source: Source,
+  media_type: Option<MediaTypeHtml>,
+  source: Option<Source>,
   published: Option<DateTime<FixedOffset>>,
   updated: Option<DateTime<FixedOffset>>,
   #[serde(flatten)]
   unparsed: Unparsed,
 }
 
+/// https://docs.pleroma.social/backend/development/ap_extensions/#chatmessages
+#[derive(Clone, Debug, Deserialize, Serialize)]
+pub enum ChatMessageType {
+  ChatMessage,
+}
+
 impl Note {
   pub(crate) fn id_unchecked(&self) -> &Url {
     &self.id
@@ -136,16 +143,16 @@ impl ToApub for ApubPrivateMessage {
 
     let note = Note {
       context: lemmy_context(),
-      r#type: NoteType::Note,
+      r#type: ChatMessageType::ChatMessage,
       id: self.ap_id.clone().into(),
       attributed_to: ObjectId::new(creator.actor_id),
-      to: ObjectId::new(recipient.actor_id),
+      to: [ObjectId::new(recipient.actor_id)],
       content: self.content.clone(),
-      media_type: MediaTypeHtml::Html,
-      source: Source {
+      media_type: Some(MediaTypeHtml::Html),
+      source: Some(Source {
         content: self.content.clone(),
         media_type: MediaTypeMarkdown::Markdown,
-      },
+      }),
       published: Some(convert_datetime(self.published)),
       updated: self.updated.map(convert_datetime),
       unparsed: Default::default(),
@@ -179,12 +186,17 @@ impl FromApub for ApubPrivateMessage {
       .attributed_to
       .dereference(context, request_counter)
       .await?;
-    let recipient = note.to.dereference(context, request_counter).await?;
+    let recipient = note.to[0].dereference(context, request_counter).await?;
+    let content = if let Some(source) = &note.source {
+      source.content.clone()
+    } else {
+      parse_html(&note.content)
+    };
 
     let form = PrivateMessageForm {
       creator_id: creator.id,
       recipient_id: recipient.id,
-      content: note.source.content.clone(),
+      content,
       published: note.published.map(|u| u.to_owned().naive_local()),
       updated: note.updated.map(|u| u.to_owned().naive_local()),
       deleted: None,
@@ -207,20 +219,30 @@ mod tests {
   use assert_json_diff::assert_json_include;
   use serial_test::serial;
 
-  #[actix_rt::test]
-  #[serial]
-  async fn test_fetch_lemmy_pm() {
-    let context = init_context();
-    let url = Url::parse("https://lemmy.ml/private_message/1621").unwrap();
+  async fn prepare_comment_test(url: &Url, context: &LemmyContext) -> (ApubPerson, ApubPerson) {
     let lemmy_person = file_to_json_object("assets/lemmy-person.json");
-    let person1 = ApubPerson::from_apub(&lemmy_person, &context, &url, &mut 0)
+    let person1 = ApubPerson::from_apub(&lemmy_person, context, url, &mut 0)
       .await
       .unwrap();
     let pleroma_person = file_to_json_object("assets/pleroma-person.json");
     let pleroma_url = Url::parse("https://queer.hacktivis.me/users/lanodan").unwrap();
-    let person2 = ApubPerson::from_apub(&pleroma_person, &context, &pleroma_url, &mut 0)
+    let person2 = ApubPerson::from_apub(&pleroma_person, context, &pleroma_url, &mut 0)
       .await
       .unwrap();
+    (person1, person2)
+  }
+
+  fn cleanup(data: (ApubPerson, ApubPerson), context: &LemmyContext) {
+    Person::delete(&*context.pool().get().unwrap(), data.0.id).unwrap();
+    Person::delete(&*context.pool().get().unwrap(), data.1.id).unwrap();
+  }
+
+  #[actix_rt::test]
+  #[serial]
+  async fn test_parse_lemmy_pm() {
+    let context = init_context();
+    let url = Url::parse("https://enterprise.lemmy.ml/private_message/1621").unwrap();
+    let data = prepare_comment_test(&url, &context).await;
     let json = file_to_json_object("assets/lemmy-private-message.json");
     let mut request_counter = 0;
     let pm = ApubPrivateMessage::from_apub(&json, &context, &url, &mut request_counter)
@@ -228,14 +250,34 @@ mod tests {
       .unwrap();
 
     assert_eq!(pm.ap_id.clone().into_inner(), url);
-    assert_eq!(pm.content.len(), 4);
+    assert_eq!(pm.content.len(), 20);
     assert_eq!(request_counter, 0);
 
     let to_apub = pm.to_apub(context.pool()).await.unwrap();
     assert_json_include!(actual: json, expected: to_apub);
 
     PrivateMessage::delete(&*context.pool().get().unwrap(), pm.id).unwrap();
-    Person::delete(&*context.pool().get().unwrap(), person1.id).unwrap();
-    Person::delete(&*context.pool().get().unwrap(), person2.id).unwrap();
+    cleanup(data, &context);
+  }
+
+  #[actix_rt::test]
+  #[serial]
+  async fn test_parse_pleroma_pm() {
+    let context = init_context();
+    let url = Url::parse("https://enterprise.lemmy.ml/private_message/1621").unwrap();
+    let data = prepare_comment_test(&url, &context).await;
+    let pleroma_url = Url::parse("https://queer.hacktivis.me/objects/2").unwrap();
+    let json = file_to_json_object("assets/pleroma-private-message.json");
+    let mut request_counter = 0;
+    let pm = ApubPrivateMessage::from_apub(&json, &context, &pleroma_url, &mut request_counter)
+      .await
+      .unwrap();
+
+    assert_eq!(pm.ap_id.clone().into_inner(), pleroma_url);
+    assert_eq!(pm.content.len(), 3);
+    assert_eq!(request_counter, 0);
+
+    PrivateMessage::delete(&*context.pool().get().unwrap(), pm.id).unwrap();
+    cleanup(data, &context);
   }
 }