Skip to content

Commit

Permalink
Breaking apub changes (#1859)
Browse files Browse the repository at this point in the history
* 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
  • Loading branch information
Nutomic authored Oct 22, 2021
1 parent 23731cd commit 149a4e0
Show file tree
Hide file tree
Showing 30 changed files with 285 additions and 383 deletions.
1 change: 0 additions & 1 deletion api_tests/src/comment.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
1 change: 0 additions & 1 deletion api_tests/src/post.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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();

Expand Down
18 changes: 8 additions & 10 deletions crates/apub/assets/lemmy-comment.json
Original file line number Diff line number Diff line change
Expand Up @@ -18,19 +18,17 @@
},
"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"
}
43 changes: 23 additions & 20 deletions crates/apub/assets/lemmy-community.json
Original file line number Diff line number Diff line change
Expand Up @@ -18,33 +18,36 @@
},
"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"
}
42 changes: 23 additions & 19 deletions crates/apub/assets/lemmy-person.json
Original file line number Diff line number Diff line change
Expand Up @@ -18,29 +18,33 @@
},
"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"
}
}
26 changes: 13 additions & 13 deletions crates/apub/assets/lemmy-post.json
Original file line number Diff line number Diff line change
Expand Up @@ -18,22 +18,22 @@
},
"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"
}
18 changes: 10 additions & 8 deletions crates/apub/assets/lemmy-private-message.json
Original file line number Diff line number Diff line change
Expand Up @@ -18,15 +18,17 @@
},
"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"
}
"published": "2021-10-21T10:13:14.597721+00:00"
}
2 changes: 1 addition & 1 deletion crates/apub/assets/pleroma-comment.json
Original file line number Diff line number Diff line change
Expand Up @@ -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": "@[email protected] Have what?",
Expand Down
17 changes: 17 additions & 0 deletions crates/apub/assets/pleroma-private-message.json
Original file line number Diff line number Diff line change
@@ -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"
}
6 changes: 3 additions & 3 deletions crates/apub/src/activities/comment/create_or_update.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@ use crate::{
},
context::lemmy_context,
fetcher::object_id::ObjectId,
migrations::PublicUrlMigration,
objects::{
comment::{ApubComment, Note},
community::ApubCommunity,
Expand All @@ -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::{
Expand All @@ -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>,
Expand Down Expand Up @@ -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,
Expand Down
6 changes: 3 additions & 3 deletions crates/apub/src/activities/community/add_mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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::{
Expand All @@ -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},
Expand All @@ -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],
Expand All @@ -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())],
Expand Down
Loading

0 comments on commit 149a4e0

Please sign in to comment.