]> Untitled Git - lemmy.git/commitdiff
Remove code for apub compatibility with Lemmy v0.8.9 and older
authorFelix Ableitner <me@nutomic.com>
Fri, 26 Feb 2021 13:03:49 +0000 (14:03 +0100)
committerFelix Ableitner <me@nutomic.com>
Fri, 26 Feb 2021 13:03:49 +0000 (14:03 +0100)
crates/apub/src/inbox/receive_for_community.rs
crates/apub/src/routes.rs

index e3704d97a6db167d1ba07abdff1bcbd28b25a2e8..6c087fc80b3e90f737cf676139b3618d045d93e1 100644 (file)
@@ -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<Activity>(like_or_dislike: &Activity) -> Result<Url, LemmyError>
-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(),
-    )
-  }
-}
index 3717a894f09e336e7d26bd904678ac38b2964657..6fa82ea84ce526d2e656e500cf2bb72ca9a1f212 100644 (file)
@@ -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(