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 <dessalines@users.noreply.github.com>
This commit is contained in:
Nutomic 2022-12-09 16:21:17 +00:00 committed by GitHub
parent 2732a5bf07
commit 0ecf256ce3
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
9 changed files with 9 additions and 25 deletions

View file

@ -19,7 +19,6 @@
"content": "test body", "content": "test body",
"mediaType": "text/markdown" "mediaType": "text/markdown"
}, },
"url": "https://lemmy.ml/pictrs/image/xl8W7FZfk9.jpg",
"attachment": [ "attachment": [
{ {
"type": "Link", "type": "Link",

View file

@ -19,7 +19,6 @@
"content": "test body", "content": "test body",
"mediaType": "text/markdown" "mediaType": "text/markdown"
}, },
"url": "https://lemmy.ml/pictrs/image/xl8W7FZfk9.jpg",
"attachment": [ "attachment": [
{ {
"type": "Link", "type": "Link",

View file

@ -1,5 +1,5 @@
{ {
"type": "Service", "type": "Application",
"id": "https://enterprise.lemmy.ml/", "id": "https://enterprise.lemmy.ml/",
"name": "Enterprise", "name": "Enterprise",
"summary": "A test instance", "summary": "A test instance",

View file

@ -14,7 +14,6 @@
"content": "This is a post in the /c/tenforward community", "content": "This is a post in the /c/tenforward community",
"mediaType": "text/markdown" "mediaType": "text/markdown"
}, },
"url": "https://enterprise.lemmy.ml/pictrs/image/eOtYb9iEiB.png",
"attachment": [ "attachment": [
{ {
"type": "Link", "type": "Link",

View file

@ -26,7 +26,7 @@ pub enum PostOrComment {
#[serde(untagged)] #[serde(untagged)]
pub enum PageOrNote { pub enum PageOrNote {
Page(Box<Page>), Page(Box<Page>),
Note(Box<Note>), Note(Note),
} }
#[async_trait::async_trait(?Send)] #[async_trait::async_trait(?Send)]
@ -91,7 +91,7 @@ impl ApubObject for PostOrComment {
ApubPost::from_apub(*p, context, request_counter).await?, ApubPost::from_apub(*p, context, request_counter).await?,
)), )),
PageOrNote::Note(n) => PostOrComment::Comment(Box::new( PageOrNote::Note(n) => PostOrComment::Comment(Box::new(
ApubComment::from_apub(*n, context, request_counter).await?, ApubComment::from_apub(n, context, request_counter).await?,
)), )),
}) })
} }

View file

@ -4,10 +4,7 @@ use crate::{
local_instance, local_instance,
objects::read_from_string_or_source_opt, objects::read_from_string_or_source_opt,
protocol::{ protocol::{
objects::{ objects::{instance::Instance, LanguageTag},
instance::{Instance, InstanceType},
LanguageTag,
},
ImageObject, ImageObject,
Source, Source,
}, },
@ -19,6 +16,7 @@ use activitypub_federation::{
traits::{Actor, ApubObject}, traits::{Actor, ApubObject},
utils::verify_domains_match, utils::verify_domains_match,
}; };
use activitystreams_kinds::actor::ApplicationType;
use chrono::NaiveDateTime; use chrono::NaiveDateTime;
use lemmy_api_common::{context::LemmyContext, utils::local_site_opt_to_slur_regex}; use lemmy_api_common::{context::LemmyContext, utils::local_site_opt_to_slur_regex};
use lemmy_db_schema::{ use lemmy_db_schema::{
@ -88,7 +86,7 @@ impl ApubObject for ApubSite {
let language = LanguageTag::new_multiple(langs, data.pool()).await?; let language = LanguageTag::new_multiple(langs, data.pool()).await?;
let instance = Instance { let instance = Instance {
kind: InstanceType::Service, kind: ApplicationType::Application,
id: ObjectId::new(self.actor_id()), id: ObjectId::new(self.actor_id()),
name: self.name.clone(), name: self.name.clone(),
content: self.sidebar.as_ref().map(|d| markdown_to_html(d)), content: self.sidebar.as_ref().map(|d| markdown_to_html(d)),

View file

@ -112,7 +112,6 @@ impl ApubObject for ApubPost {
content: self.body.as_ref().map(|b| markdown_to_html(b)), content: self.body.as_ref().map(|b| markdown_to_html(b)),
media_type: Some(MediaTypeMarkdownOrHtml::Html), media_type: Some(MediaTypeMarkdownOrHtml::Html),
source: self.body.clone().map(Source::new), source: self.body.clone().map(Source::new),
url: self.url.clone().map(Into::into),
attachment: self.url.clone().map(Attachment::new).into_iter().collect(), attachment: self.url.clone().map(Attachment::new).into_iter().collect(),
image: self.thumbnail_url.clone().map(ImageObject::new), image: self.thumbnail_url.clone().map(ImageObject::new),
comments_enabled: Some(!self.locked), 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 // we cant display videos directly, so insert a link to external video page
Some(page.id.inner().clone()) Some(page.id.inner().clone())
} else { } else {
// url sent by lemmy (old) None
page.url
}; };
let (metadata_res, thumbnail_url) = if let Some(url) = &url { let (metadata_res, thumbnail_url) = if let Some(url) = &url {
fetch_site_data(context.client(), context.settings(), Some(url)).await 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())) .updated(page.updated.map(|u| u.naive_local()))
.build() .build()
}; };
// read existing, local post if any (for generating mod log) // read existing, local post if any (for generating mod log)
let old_post = ObjectId::<ApubPost>::new(page.id.clone()) let old_post = ObjectId::<ApubPost>::new(page.id.clone())
.dereference_local(context) .dereference_local(context)

View file

@ -6,23 +6,18 @@ use activitypub_federation::{
core::{object_id::ObjectId, signatures::PublicKey}, core::{object_id::ObjectId, signatures::PublicKey},
deser::{helpers::deserialize_skip_error, values::MediaTypeHtml}, deser::{helpers::deserialize_skip_error, values::MediaTypeHtml},
}; };
use activitystreams_kinds::actor::ApplicationType;
use chrono::{DateTime, FixedOffset}; use chrono::{DateTime, FixedOffset};
use serde::{Deserialize, Serialize}; use serde::{Deserialize, Serialize};
use serde_with::skip_serializing_none; use serde_with::skip_serializing_none;
use url::Url; use url::Url;
#[derive(Clone, Copy, Debug, Deserialize, Serialize, PartialEq, Eq)]
pub enum InstanceType {
Application,
Service,
}
#[skip_serializing_none] #[skip_serializing_none]
#[derive(Clone, Debug, Deserialize, Serialize)] #[derive(Clone, Debug, Deserialize, Serialize)]
#[serde(rename_all = "camelCase")] #[serde(rename_all = "camelCase")]
pub struct Instance { pub struct Instance {
#[serde(rename = "type")] #[serde(rename = "type")]
pub(crate) kind: InstanceType, pub(crate) kind: ApplicationType,
pub(crate) id: ObjectId<ApubSite>, pub(crate) id: ObjectId<ApubSite>,
// site name // site name
pub(crate) name: String, pub(crate) name: String,

View file

@ -54,9 +54,6 @@ pub struct Page {
pub(crate) media_type: Option<MediaTypeMarkdownOrHtml>, pub(crate) media_type: Option<MediaTypeMarkdownOrHtml>,
#[serde(deserialize_with = "deserialize_skip_error", default)] #[serde(deserialize_with = "deserialize_skip_error", default)]
pub(crate) source: Option<Source>, pub(crate) source: Option<Source>,
/// deprecated, use attachment field
#[serde(deserialize_with = "deserialize_skip_error", default)]
pub(crate) url: Option<Url>,
/// most software uses array type for attachment field, so we do the same. nevertheless, we only /// most software uses array type for attachment field, so we do the same. nevertheless, we only
/// use the first item /// use the first item
#[serde(default)] #[serde(default)]