From 0ecf256ce32392b53b96a24ddd8f2e4e513281da Mon Sep 17 00:00:00 2001 From: Nutomic Date: Fri, 9 Dec 2022 16:21:17 +0000 Subject: [PATCH] Remove federation backwards compatibility with 0.16.x (#2183) * Breaking: remove compatiblity with page.url field (ref #2182) * Breaking: change type of Instance to `Application` (ref #2200) Co-authored-by: Dessalines --- .../lemmy/activities/create_or_update/create_page.json | 1 - .../lemmy/activities/create_or_update/update_page.json | 1 - crates/apub/assets/lemmy/objects/instance.json | 2 +- crates/apub/assets/lemmy/objects/page.json | 1 - crates/apub/src/fetcher/post_or_comment.rs | 4 ++-- crates/apub/src/objects/instance.rs | 8 +++----- crates/apub/src/objects/post.rs | 5 +---- crates/apub/src/protocol/objects/instance.rs | 9 ++------- crates/apub/src/protocol/objects/page.rs | 3 --- 9 files changed, 9 insertions(+), 25 deletions(-) diff --git a/crates/apub/assets/lemmy/activities/create_or_update/create_page.json b/crates/apub/assets/lemmy/activities/create_or_update/create_page.json index 907faa5c..e9dd8014 100644 --- a/crates/apub/assets/lemmy/activities/create_or_update/create_page.json +++ b/crates/apub/assets/lemmy/activities/create_or_update/create_page.json @@ -19,7 +19,6 @@ "content": "test body", "mediaType": "text/markdown" }, - "url": "https://lemmy.ml/pictrs/image/xl8W7FZfk9.jpg", "attachment": [ { "type": "Link", diff --git a/crates/apub/assets/lemmy/activities/create_or_update/update_page.json b/crates/apub/assets/lemmy/activities/create_or_update/update_page.json index 46cb0e2a..daaf76bf 100644 --- a/crates/apub/assets/lemmy/activities/create_or_update/update_page.json +++ b/crates/apub/assets/lemmy/activities/create_or_update/update_page.json @@ -19,7 +19,6 @@ "content": "test body", "mediaType": "text/markdown" }, - "url": "https://lemmy.ml/pictrs/image/xl8W7FZfk9.jpg", "attachment": [ { "type": "Link", diff --git a/crates/apub/assets/lemmy/objects/instance.json b/crates/apub/assets/lemmy/objects/instance.json index 03c4e375..1ac6939c 100644 --- a/crates/apub/assets/lemmy/objects/instance.json +++ b/crates/apub/assets/lemmy/objects/instance.json @@ -1,5 +1,5 @@ { - "type": "Service", + "type": "Application", "id": "https://enterprise.lemmy.ml/", "name": "Enterprise", "summary": "A test instance", diff --git a/crates/apub/assets/lemmy/objects/page.json b/crates/apub/assets/lemmy/objects/page.json index 0f514bc0..bbe7e6d2 100644 --- a/crates/apub/assets/lemmy/objects/page.json +++ b/crates/apub/assets/lemmy/objects/page.json @@ -14,7 +14,6 @@ "content": "This is a post in the /c/tenforward community", "mediaType": "text/markdown" }, - "url": "https://enterprise.lemmy.ml/pictrs/image/eOtYb9iEiB.png", "attachment": [ { "type": "Link", diff --git a/crates/apub/src/fetcher/post_or_comment.rs b/crates/apub/src/fetcher/post_or_comment.rs index 68e176b0..f8a260b9 100644 --- a/crates/apub/src/fetcher/post_or_comment.rs +++ b/crates/apub/src/fetcher/post_or_comment.rs @@ -26,7 +26,7 @@ pub enum PostOrComment { #[serde(untagged)] pub enum PageOrNote { Page(Box), - Note(Box), + Note(Note), } #[async_trait::async_trait(?Send)] @@ -91,7 +91,7 @@ impl ApubObject for PostOrComment { ApubPost::from_apub(*p, context, request_counter).await?, )), PageOrNote::Note(n) => PostOrComment::Comment(Box::new( - ApubComment::from_apub(*n, context, request_counter).await?, + ApubComment::from_apub(n, context, request_counter).await?, )), }) } diff --git a/crates/apub/src/objects/instance.rs b/crates/apub/src/objects/instance.rs index 5ec4fe90..e3cb8b46 100644 --- a/crates/apub/src/objects/instance.rs +++ b/crates/apub/src/objects/instance.rs @@ -4,10 +4,7 @@ use crate::{ local_instance, objects::read_from_string_or_source_opt, protocol::{ - objects::{ - instance::{Instance, InstanceType}, - LanguageTag, - }, + objects::{instance::Instance, LanguageTag}, ImageObject, Source, }, @@ -19,6 +16,7 @@ use activitypub_federation::{ traits::{Actor, ApubObject}, utils::verify_domains_match, }; +use activitystreams_kinds::actor::ApplicationType; use chrono::NaiveDateTime; use lemmy_api_common::{context::LemmyContext, utils::local_site_opt_to_slur_regex}; use lemmy_db_schema::{ @@ -88,7 +86,7 @@ impl ApubObject for ApubSite { let language = LanguageTag::new_multiple(langs, data.pool()).await?; let instance = Instance { - kind: InstanceType::Service, + kind: ApplicationType::Application, id: ObjectId::new(self.actor_id()), name: self.name.clone(), content: self.sidebar.as_ref().map(|d| markdown_to_html(d)), diff --git a/crates/apub/src/objects/post.rs b/crates/apub/src/objects/post.rs index afe025ce..ecad2e46 100644 --- a/crates/apub/src/objects/post.rs +++ b/crates/apub/src/objects/post.rs @@ -112,7 +112,6 @@ impl ApubObject for ApubPost { content: self.body.as_ref().map(|b| markdown_to_html(b)), media_type: Some(MediaTypeMarkdownOrHtml::Html), source: self.body.clone().map(Source::new), - url: self.url.clone().map(Into::into), attachment: self.url.clone().map(Attachment::new).into_iter().collect(), image: self.thumbnail_url.clone().map(ImageObject::new), comments_enabled: Some(!self.locked), @@ -179,8 +178,7 @@ impl ApubObject for ApubPost { // we cant display videos directly, so insert a link to external video page Some(page.id.inner().clone()) } else { - // url sent by lemmy (old) - page.url + None }; let (metadata_res, thumbnail_url) = if let Some(url) = &url { fetch_site_data(context.client(), context.settings(), Some(url)).await @@ -231,7 +229,6 @@ impl ApubObject for ApubPost { .updated(page.updated.map(|u| u.naive_local())) .build() }; - // read existing, local post if any (for generating mod log) let old_post = ObjectId::::new(page.id.clone()) .dereference_local(context) diff --git a/crates/apub/src/protocol/objects/instance.rs b/crates/apub/src/protocol/objects/instance.rs index 2df9dcc9..00c9c8be 100644 --- a/crates/apub/src/protocol/objects/instance.rs +++ b/crates/apub/src/protocol/objects/instance.rs @@ -6,23 +6,18 @@ use activitypub_federation::{ core::{object_id::ObjectId, signatures::PublicKey}, deser::{helpers::deserialize_skip_error, values::MediaTypeHtml}, }; +use activitystreams_kinds::actor::ApplicationType; use chrono::{DateTime, FixedOffset}; use serde::{Deserialize, Serialize}; use serde_with::skip_serializing_none; use url::Url; -#[derive(Clone, Copy, Debug, Deserialize, Serialize, PartialEq, Eq)] -pub enum InstanceType { - Application, - Service, -} - #[skip_serializing_none] #[derive(Clone, Debug, Deserialize, Serialize)] #[serde(rename_all = "camelCase")] pub struct Instance { #[serde(rename = "type")] - pub(crate) kind: InstanceType, + pub(crate) kind: ApplicationType, pub(crate) id: ObjectId, // site name pub(crate) name: String, diff --git a/crates/apub/src/protocol/objects/page.rs b/crates/apub/src/protocol/objects/page.rs index a62fb8e5..65df30e4 100644 --- a/crates/apub/src/protocol/objects/page.rs +++ b/crates/apub/src/protocol/objects/page.rs @@ -54,9 +54,6 @@ pub struct Page { pub(crate) media_type: Option, #[serde(deserialize_with = "deserialize_skip_error", default)] pub(crate) source: Option, - /// deprecated, use attachment field - #[serde(deserialize_with = "deserialize_skip_error", default)] - pub(crate) url: Option, /// most software uses array type for attachment field, so we do the same. nevertheless, we only /// use the first item #[serde(default)] -- 2.44.1