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 () => {
let betaCommunity = (await resolveBetaCommunity(beta)).community;
console.log(betaCommunity);
let postRes = await createPost(beta, betaCommunity.community.id);
expect(postRes.post_view.post).toBeDefined();

View File

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

View File

@ -1,22 +1,5 @@
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

View 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(),