From: Felix Ableitner Date: Fri, 26 Feb 2021 13:03:49 +0000 (+0100) Subject: Remove code for apub compatibility with Lemmy v0.8.9 and older X-Git-Url: http://these/git/%7B%60%24%7BwebArchiveUrl%7D/%22%7B%7D/%22https:/nerdica.net/%7BtotpUrl%7D?a=commitdiff_plain;h=4cc341e4aa996cb7c3e5296168442a162b82ed6d;p=lemmy.git Remove code for apub compatibility with Lemmy v0.8.9 and older --- diff --git a/crates/apub/src/inbox/receive_for_community.rs b/crates/apub/src/inbox/receive_for_community.rs index e3704d97..6c087fc8 100644 --- a/crates/apub/src/inbox/receive_for_community.rs +++ b/crates/apub/src/inbox/receive_for_community.rs @@ -115,7 +115,10 @@ pub(in crate::inbox) async fn receive_like_for_community( verify_activity_domains_valid(&like, &expected_domain, false)?; is_addressed_to_public(&like)?; - let object_id = get_like_object_id(&like)?; + let object_id = like + .object() + .as_single_xsd_any_uri() + .context(location_info!())?; match fetch_post_or_comment_by_id(&object_id, context, request_counter).await? { PostOrComment::Post(post) => receive_like_post(like, post, context, request_counter).await, PostOrComment::Comment(comment) => { @@ -143,7 +146,10 @@ pub(in crate::inbox) async fn receive_dislike_for_community( verify_activity_domains_valid(&dislike, &expected_domain, false)?; is_addressed_to_public(&dislike)?; - let object_id = get_like_object_id(&dislike)?; + let object_id = dislike + .object() + .as_single_xsd_any_uri() + .context(location_info!())?; match fetch_post_or_comment_by_id(&object_id, context, request_counter).await? { PostOrComment::Post(post) => { receive_dislike_post(dislike, post, context, request_counter).await @@ -313,7 +319,10 @@ pub(in crate::inbox) async fn receive_undo_like_for_community( verify_activity_domains_valid(&like, &expected_domain, false)?; is_addressed_to_public(&like)?; - let object_id = get_like_object_id(&like)?; + let object_id = like + .object() + .as_single_xsd_any_uri() + .context(location_info!())?; match fetch_post_or_comment_by_id(&object_id, context, request_counter).await? { PostOrComment::Post(post) => { receive_undo_like_post(&like, post, context, request_counter).await @@ -336,7 +345,10 @@ pub(in crate::inbox) async fn receive_undo_dislike_for_community( verify_activity_domains_valid(&dislike, &expected_domain, false)?; is_addressed_to_public(&dislike)?; - let object_id = get_like_object_id(&dislike)?; + let object_id = dislike + .object() + .as_single_xsd_any_uri() + .context(location_info!())?; match fetch_post_or_comment_by_id(&object_id, context, request_counter).await? { PostOrComment::Post(post) => { receive_undo_dislike_post(&dislike, post, context, request_counter).await @@ -362,26 +374,3 @@ async fn fetch_post_or_comment_by_id( Err(NotFound.into()) } - -fn get_like_object_id(like_or_dislike: &Activity) -> Result -where - Activity: ActorAndObjectRefExt, -{ - // TODO: For backwards compatibility with older Lemmy versions where like.object contains a full - // post/comment. This can be removed after some time, using - // `activity.oject().as_single_xsd_any_uri()` instead. - let object = like_or_dislike.object(); - if let Some(xsd_uri) = object.as_single_xsd_any_uri() { - Ok(xsd_uri.to_owned()) - } else { - Ok( - object - .to_owned() - .one() - .context(location_info!())? - .id() - .context(location_info!())? - .to_owned(), - ) - } -} diff --git a/crates/apub/src/routes.rs b/crates/apub/src/routes.rs index 3717a894..6fa82ea8 100644 --- a/crates/apub/src/routes.rs +++ b/crates/apub/src/routes.rs @@ -31,9 +31,7 @@ pub fn config(cfg: &mut web::ServiceConfig) { .or(guard::Header("Accept", APUB_JSON_CONTENT_TYPE_LONG)); let header_guard_content_type = guard::Any(guard::Header("Content-Type", APUB_JSON_CONTENT_TYPE)) - .or(guard::Header("Content-Type", APUB_JSON_CONTENT_TYPE_LONG)) - // TODO: compatibility with previous lemmy versions, remove this later - .or(guard::Header("Content-Type", "application/json")); + .or(guard::Header("Content-Type", APUB_JSON_CONTENT_TYPE_LONG)); cfg .service(