]> Untitled Git - lemmy.git/commitdiff
wip: add former_type to tombstone
authorFelix <me@nutomic.com>
Wed, 29 Apr 2020 19:10:50 +0000 (21:10 +0200)
committerFelix <me@nutomic.com>
Wed, 29 Apr 2020 19:10:50 +0000 (21:10 +0200)
server/src/apub/comment.rs
server/src/apub/community.rs
server/src/apub/mod.rs
server/src/apub/post.rs
server/src/apub/shared_inbox.rs

index 4a5f18b7c4a6ef7a9f080defb7780f6a3296b9a4..14a0995652b2cf985b01576736c50c1ae4acea32 100644 (file)
@@ -39,7 +39,7 @@ impl ToApub for Comment {
 
 impl ToTombstone for Comment {
   fn to_tombstone(&self) -> Result<Tombstone, Error> {
-    create_tombstone(self.deleted, &self.ap_id, self.published, self.updated)
+    create_tombstone(self.deleted, &self.ap_id, self.published, self.updated, NoteType.to_string())
   }
 }
 
index 36e33c8951aefdb7012cf129bc1b0c8babdf056d..0bfb95d2b2c2ecc63359a5f3ead7d7795969e270 100644 (file)
@@ -1,4 +1,5 @@
 use super::*;
+use activitystreams::actor::kind::GroupType;
 
 #[derive(Deserialize)]
 pub struct CommunityQuery {
@@ -49,7 +50,7 @@ impl ToApub for Community {
 
 impl ToTombstone for Community {
   fn to_tombstone(&self) -> Result<Tombstone, Error> {
-    create_tombstone(self.deleted, &self.actor_id, self.published, self.updated)
+    create_tombstone(self.deleted, &self.actor_id, self.published, self.updated, GroupType.to_string())
   }
 }
 
index 9d312cc3d2e8d9a6d231e7ecda0140790b75b000..f72eb17e3bf981b7e128cf0193b2e434e45eb4ac 100644 (file)
@@ -19,6 +19,9 @@ use activitystreams::{
   object::{properties::ObjectProperties, Note, Page, Tombstone},
   public, BaseBox,
 };
+use activitystreams::object::kind::{NoteType, PageType};
+use crate::api::community::CommunityResponse;
+use crate::websocket::server::SendCommunityRoomMessage;
 use actix_web::body::Body;
 use actix_web::web::Path;
 use actix_web::{web, HttpRequest, HttpResponse, Result};
@@ -64,6 +67,7 @@ use chrono::NaiveDateTime;
 use fetcher::{get_or_fetch_and_upsert_remote_community, get_or_fetch_and_upsert_remote_user};
 use signatures::verify;
 use signatures::{sign, PublicKey, PublicKeyExtension};
+use activitystreams::primitives::XsdString;
 
 type GroupExt = Ext<Ext<Group, ApActorProperties>, PublicKeyExtension>;
 type PersonExt = Ext<Ext<Person, ApActorProperties>, PublicKeyExtension>;
@@ -87,6 +91,7 @@ where
     .content_type(APUB_JSON_CONTENT_TYPE)
     .json(data)
 }
+
 fn create_apub_tombstone_response<T>(data: &T) -> HttpResponse<Body>
 where
   T: Serialize,
@@ -158,6 +163,7 @@ fn create_tombstone(
   object_id: &str,
   published: NaiveDateTime,
   updated: Option<NaiveDateTime>,
+  former_type: String,
 ) -> Result<Tombstone, Error> {
   if deleted {
     let mut tombstone = Tombstone::default();
@@ -165,12 +171,13 @@ fn create_tombstone(
     tombstone
       .object_props
       .set_id(object_id)?
-      .set_published(convert_datetime(published))?;
+      .set_published(convert_datetime(published));
     if let Some(updated) = updated {
       tombstone
         .object_props
         .set_updated(convert_datetime(updated))?;
     }
+    tombstone.tombstone_props.set_former_type_object_box(XsdString::from_string(former_type))?;
     Ok(tombstone)
   } else {
     Err(format_err!(
index 77f8d9842815b57a78068baf6e2917cc7c38cca3..356141819d347f7b4c2fcc5c03df13d0671d5d28 100644 (file)
@@ -61,7 +61,7 @@ impl ToApub for Post {
 
 impl ToTombstone for Post {
   fn to_tombstone(&self) -> Result<Tombstone, Error> {
-    create_tombstone(self.deleted, &self.ap_id, self.published, self.updated)
+    create_tombstone(self.deleted, &self.ap_id, self.published, self.updated, PageType.to_string())
   }
 }
 
index 28cb71e2a6c2b1567eb84c6115209b1ab7f9aefc..692e6f2b1929a65bd0afc9a5493a731698f1e844 100644 (file)
@@ -1,6 +1,4 @@
 use super::*;
-use crate::api::community::CommunityResponse;
-use crate::websocket::server::SendCommunityRoomMessage;
 
 #[serde(untagged)]
 #[derive(Serialize, Deserialize, Debug)]
@@ -66,8 +64,7 @@ pub async fn shared_inbox(
       receive_dislike_comment(&d, &request, &conn, chat_server)
     }
     (SharedAcceptedObjects::Delete(d), Some("Tombstone")) => {
-      // TODO: is this deleting a community, post, comment or what?
-      receive_delete_community(&d, &request, &conn, chat_server)
+      receive_delete(&d, &request, &conn, chat_server)
     }
     _ => Err(format_err!("Unknown incoming activity type.")),
   }
@@ -511,7 +508,7 @@ fn receive_dislike_comment(
   Ok(HttpResponse::Ok().finish())
 }
 
-fn receive_delete_community(
+fn receive_delete(
   delete: &Delete,
   request: &HttpRequest,
   conn: &PgConnection,
@@ -524,6 +521,13 @@ fn receive_delete_community(
     .unwrap()
     .to_owned()
     .to_concrete::<Tombstone>()?;
+  // TODO: not sure how to handle formerType (should be a string)
+  // https://www.w3.org/TR/activitystreams-vocabulary/#dfn-formertype
+  let former_type: &str = tombstone.tombstone_props.get_former_type_object_box().unwrap().to_concrete::<String>();
+  match former_type {
+    "Group" => {},
+    d => return Err(format_err!("Delete type {} not supported", d)),
+  }
   let community_apub_id = tombstone.object_props.get_id().unwrap().to_string();
 
   let community = Community::read_from_actor_id(conn, &community_apub_id)?;