From e14e0c3cae300cfb69abf41d01cca5ab87c49d88 Mon Sep 17 00:00:00 2001 From: Felix Ableitner Date: Fri, 22 Oct 2021 13:11:58 +0200 Subject: [PATCH] Also change group.content to summary --- crates/apub/assets/lemmy-comment.json | 2 +- crates/apub/assets/lemmy-community.json | 3 +-- crates/apub/assets/lemmy-person.json | 3 +-- crates/apub/src/objects/community.rs | 12 +++++------- crates/apub/src/objects/mod.rs | 12 ++++++++++++ crates/apub/src/objects/person.rs | 11 +++-------- scripts/test.sh | 2 +- 7 files changed, 24 insertions(+), 21 deletions(-) diff --git a/crates/apub/assets/lemmy-comment.json b/crates/apub/assets/lemmy-comment.json index 1d0740ebb..663067ea8 100644 --- a/crates/apub/assets/lemmy-comment.json +++ b/crates/apub/assets/lemmy-comment.json @@ -19,7 +19,7 @@ "https://w3id.org/security/v1" ], "attributedTo": "https://lemmy.ml/u/nutomic", - "summary": "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", "inReplyTo": "https://lemmy.ml/post/55143", "mediaType": "text/html", diff --git a/crates/apub/assets/lemmy-community.json b/crates/apub/assets/lemmy-community.json index e0f3c6809..b9488ab70 100644 --- a/crates/apub/assets/lemmy-community.json +++ b/crates/apub/assets/lemmy-community.json @@ -18,7 +18,7 @@ }, "https://w3id.org/security/v1" ], - "content": "

Lemmy Announcements

\n
\n

Feel free to announce new communities here.

\n

Other than that, this is reserved for admin use only.

\n", + "summary": "

Lemmy Announcements

\n
\n

Feel free to announce new communities here.

\n

Other than that, this is reserved for admin use only.

\n", "endpoints": { "sharedInbox": "https://lemmy.ml/inbox" }, @@ -29,7 +29,6 @@ }, "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", diff --git a/crates/apub/assets/lemmy-person.json b/crates/apub/assets/lemmy-person.json index 6514b6e91..6cd976584 100644 --- a/crates/apub/assets/lemmy-person.json +++ b/crates/apub/assets/lemmy-person.json @@ -18,7 +18,7 @@ }, "https://w3id.org/security/v1" ], - "content": "

Lemmy maintainer. Interested in politics, video games, and many other things.

\n", + "summary": "

Lemmy maintainer. Interested in politics, video games, and many other things.

\n", "endpoints": { "sharedInbox": "https://lemmy.ml/inbox" }, @@ -28,7 +28,6 @@ }, "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": { diff --git a/crates/apub/src/objects/community.rs b/crates/apub/src/objects/community.rs index 525ae854d..9f9a91aca 100644 --- a/crates/apub/src/objects/community.rs +++ b/crates/apub/src/objects/community.rs @@ -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, - media_type: Option, + summary: Option, source: Option, icon: Option, /// 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, diff --git a/crates/apub/src/objects/mod.rs b/crates/apub/src/objects/mod.rs index a2e3aac74..76c258ce2 100644 --- a/crates/apub/src/objects/mod.rs +++ b/crates/apub/src/objects/mod.rs @@ -4,6 +4,7 @@ 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}; @@ -55,6 +56,17 @@ where } } +fn get_summary_from_string_or_source( + raw: &Option, + source: &Option, +) -> Option { + if let Some(source) = &source { + Some(source.content.clone()) + } else { + raw.as_ref().map(|s| parse_html(s)) + } +} + #[cfg(test)] mod tests { use super::*; diff --git a/crates/apub/src/objects/person.rs b/crates/apub/src/objects/person.rs index 9cb56ca44..c6ecc543f 100644 --- a/crates/apub/src/objects/person.rs +++ b/crates/apub/src/objects/person.rs @@ -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, @@ -13,7 +13,6 @@ use activitystreams::{ unparsed::Unparsed, }; use chrono::{DateTime, FixedOffset}; -use html2md::parse_html; use lemmy_api_common::blocking; use lemmy_apub_lib::{ signatures::PublicKey, @@ -223,11 +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 = person.name.clone(); - let bio = if let Some(source) = &person.source { - Some(source.content.clone()) - } else { - person.summary.as_ref().map(|s| parse_html(s)) - }; + 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, @@ -293,7 +288,7 @@ mod tests { assert_eq!(person.name, "nutomic"); assert!(person.public_key.is_some()); assert!(!person.local); - assert!(person.bio.is_some()); + assert_eq!(person.bio.as_ref().unwrap().len(), 77); assert_eq!(request_counter, 0); let to_apub = person.to_apub(context.pool()).await.unwrap(); diff --git a/scripts/test.sh b/scripts/test.sh index 9e4582497..0a3fa90fc 100755 --- a/scripts/test.sh +++ b/scripts/test.sh @@ -9,4 +9,4 @@ export LEMMY_DATABASE_URL=postgres://lemmy:password@localhost:5432/lemmy # so to load the config we need to traverse to the repo root export LEMMY_CONFIG_LOCATION=../../config/config.hjson RUST_BACKTRACE=1 \ - cargo test --workspace --no-fail-fast test_fetch_pleroma_person + cargo test --workspace --no-fail-fast