From: Felix Date: Wed, 29 Apr 2020 19:10:50 +0000 (+0200) Subject: wip: add former_type to tombstone X-Git-Url: http://these/git/readmes/%7B%60%24%7BarchiveTodayUrl%7D/static/%7BpictrsAvatarThumbnail%28user.avatar%29%7D?a=commitdiff_plain;h=770dcbdc49c9bf01f781e5259dc8e6d816143344;p=lemmy.git wip: add former_type to tombstone --- diff --git a/server/src/apub/comment.rs b/server/src/apub/comment.rs index 4a5f18b7..14a09956 100644 --- a/server/src/apub/comment.rs +++ b/server/src/apub/comment.rs @@ -39,7 +39,7 @@ impl ToApub for Comment { impl ToTombstone for Comment { fn to_tombstone(&self) -> Result { - 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()) } } diff --git a/server/src/apub/community.rs b/server/src/apub/community.rs index 36e33c89..0bfb95d2 100644 --- a/server/src/apub/community.rs +++ b/server/src/apub/community.rs @@ -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 { - 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()) } } diff --git a/server/src/apub/mod.rs b/server/src/apub/mod.rs index 9d312cc3..f72eb17e 100644 --- a/server/src/apub/mod.rs +++ b/server/src/apub/mod.rs @@ -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, PublicKeyExtension>; type PersonExt = Ext, PublicKeyExtension>; @@ -87,6 +91,7 @@ where .content_type(APUB_JSON_CONTENT_TYPE) .json(data) } + fn create_apub_tombstone_response(data: &T) -> HttpResponse where T: Serialize, @@ -158,6 +163,7 @@ fn create_tombstone( object_id: &str, published: NaiveDateTime, updated: Option, + former_type: String, ) -> Result { 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!( diff --git a/server/src/apub/post.rs b/server/src/apub/post.rs index 77f8d984..35614181 100644 --- a/server/src/apub/post.rs +++ b/server/src/apub/post.rs @@ -61,7 +61,7 @@ impl ToApub for Post { impl ToTombstone for Post { fn to_tombstone(&self) -> Result { - 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()) } } diff --git a/server/src/apub/shared_inbox.rs b/server/src/apub/shared_inbox.rs index 28cb71e2..692e6f2b 100644 --- a/server/src/apub/shared_inbox.rs +++ b/server/src/apub/shared_inbox.rs @@ -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::()?; + // 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::(); + 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)?;