Remove CommentInReplyToMigration

breaking-apub-changes
Felix Ableitner 2021-10-22 12:23:18 +02:00
parent 23731cd49c
commit 32970d735d
4 changed files with 28 additions and 71 deletions

View File

@ -358,7 +358,6 @@ test('Enforce community ban for federated user', async () => {
test('Report a post', async () => { test('Report a post', async () => {
let betaCommunity = (await resolveBetaCommunity(beta)).community; let betaCommunity = (await resolveBetaCommunity(beta)).community;
console.log(betaCommunity);
let postRes = await createPost(beta, betaCommunity.community.id); let postRes = await createPost(beta, betaCommunity.community.id);
expect(postRes.post_view.post).toBeDefined(); expect(postRes.post_view.post).toBeDefined();

View File

@ -21,9 +21,7 @@
"attributedTo": "https://lemmy.ml/u/nutomic", "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.", "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", "id": "https://lemmy.ml/comment/38741",
"inReplyTo": [ "inReplyTo": "https://lemmy.ml/post/55143",
"https://lemmy.ml/post/55143"
],
"mediaType": "text/html", "mediaType": "text/html",
"published": "2021-03-01T13:42:43.966208+00:00", "published": "2021-03-01T13:42:43.966208+00:00",
"source": { "source": {

View File

@ -1,22 +1,5 @@
use crate::fetcher::{object_id::ObjectId, post_or_comment::PostOrComment};
use lemmy_apub_lib::values::PublicUrl; use lemmy_apub_lib::values::PublicUrl;
use serde::{Deserialize, Serialize}; 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. // 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 // This is because Remove is for removing an object from a collection, so using it that way doesn't

View File

@ -2,7 +2,6 @@ use crate::{
activities::{verify_is_public, verify_person_in_community}, activities::{verify_is_public, verify_person_in_community},
context::lemmy_context, context::lemmy_context,
fetcher::object_id::ObjectId, fetcher::object_id::ObjectId,
migrations::CommentInReplyToMigration,
objects::{create_tombstone, person::ApubPerson, post::ApubPost, Source}, objects::{create_tombstone, person::ApubPerson, post::ApubPost, Source},
PostOrComment, PostOrComment,
}; };
@ -14,7 +13,7 @@ use activitystreams::{
public, public,
unparsed::Unparsed, unparsed::Unparsed,
}; };
use anyhow::{anyhow, Context}; use anyhow::anyhow;
use chrono::{DateTime, FixedOffset}; use chrono::{DateTime, FixedOffset};
use html2md::parse_html; use html2md::parse_html;
use lemmy_api_common::blocking; use lemmy_api_common::blocking;
@ -35,7 +34,6 @@ use lemmy_db_schema::{
DbPool, DbPool,
}; };
use lemmy_utils::{ use lemmy_utils::{
location_info,
utils::{convert_datetime, remove_slurs}, utils::{convert_datetime, remove_slurs},
LemmyError, LemmyError,
}; };
@ -61,7 +59,7 @@ pub struct Note {
content: String, content: String,
media_type: Option<MediaTypeHtml>, media_type: Option<MediaTypeHtml>,
source: SourceCompat, source: SourceCompat,
in_reply_to: CommentInReplyToMigration, in_reply_to: ObjectId<PostOrComment>,
published: Option<DateTime<FixedOffset>>, published: Option<DateTime<FixedOffset>>,
updated: Option<DateTime<FixedOffset>>, updated: Option<DateTime<FixedOffset>>,
#[serde(flatten)] #[serde(flatten)]
@ -91,43 +89,25 @@ impl Note {
context: &LemmyContext, context: &LemmyContext,
request_counter: &mut i32, request_counter: &mut i32,
) -> Result<(ApubPost, Option<CommentId>), LemmyError> { ) -> Result<(ApubPost, Option<CommentId>), LemmyError> {
match &self.in_reply_to { // Fetch parent comment chain in a box, otherwise it can cause a stack overflow.
CommentInReplyToMigration::Old(in_reply_to) => { let parent = Box::pin(
// This post, or the parent comment might not yet exist on this server yet, fetch them. self
let post_id = in_reply_to.get(0).context(location_info!())?; .in_reply_to
let post_id = ObjectId::new(post_id.clone()); .dereference(context, request_counter)
let post = Box::pin(post_id.dereference(context, request_counter)).await?; .await?,
);
// The 2nd item, if it exists, is the parent comment apub_id match parent.deref() {
// Nested comments will automatically get fetched recursively PostOrComment::Post(p) => {
let parent_id: Option<CommentId> = match in_reply_to.get(1) { // Workaround because I cant figure out how to get the post out of the box (and we dont
Some(comment_id) => { // want to stackoverflow in a deep comment hierarchy).
let comment_id = ObjectId::<ApubComment>::new(comment_id.clone()); let post_id = p.id;
let parent_comment = Box::pin(comment_id.dereference(context, request_counter)).await?; let post = blocking(context.pool(), move |conn| Post::read(conn, post_id)).await??;
Ok((post.into(), None))
Some(parent_comment.id)
}
None => None,
};
Ok((post, parent_id))
} }
CommentInReplyToMigration::New(in_reply_to) => { PostOrComment::Comment(c) => {
let parent = Box::pin(in_reply_to.dereference(context, request_counter).await?); let post_id = c.post_id;
match parent.deref() { let post = blocking(context.pool(), move |conn| Post::read(conn, post_id)).await??;
PostOrComment::Post(p) => { Ok((post.into(), Some(c.id)))
// 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)))
}
}
} }
} }
} }
@ -219,15 +199,12 @@ impl ToApub for ApubComment {
let post_id = self.post_id; let post_id = self.post_id;
let post = blocking(pool, move |conn| Post::read(conn, post_id)).await??; 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 let in_reply_to = if let Some(comment_id) = self.parent_id {
// [post_ap_id, Option(parent_comment_ap_id)] let parent_comment = blocking(pool, move |conn| Comment::read(conn, comment_id)).await??;
let mut in_reply_to_vec = vec![post.ap_id.into_inner()]; ObjectId::<PostOrComment>::new(parent_comment.ap_id.into_inner())
} else {
if let Some(parent_id) = self.parent_id { ObjectId::<PostOrComment>::new(post.ap_id.into_inner())
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 note = Note { let note = Note {
context: lemmy_context(), context: lemmy_context(),
@ -241,7 +218,7 @@ impl ToApub for ApubComment {
content: self.content.clone(), content: self.content.clone(),
media_type: MediaTypeMarkdown::Markdown, media_type: MediaTypeMarkdown::Markdown,
}), }),
in_reply_to: CommentInReplyToMigration::Old(in_reply_to_vec), in_reply_to,
published: Some(convert_datetime(self.published)), published: Some(convert_datetime(self.published)),
updated: self.updated.map(convert_datetime), updated: self.updated.map(convert_datetime),
unparsed: Default::default(), unparsed: Default::default(),