diff options
author | Felix <me@nutomic.com> | 2020-04-29 16:51:25 +0200 |
---|---|---|
committer | Felix <me@nutomic.com> | 2020-04-29 16:51:25 +0200 |
commit | c43f06124a00f3af8559d849541c2b84d3383f13 (patch) | |
tree | 0f850596a52cdfa77bff0eb620056432558af8b0 /server/src/apub/post.rs | |
parent | 0c0c68398609d549a757a9c3a26ce2311075fa38 (diff) |
Address comments, implement delete for posts and comments
Diffstat (limited to 'server/src/apub/post.rs')
-rw-r--r-- | server/src/apub/post.rs | 50 |
1 files changed, 43 insertions, 7 deletions
diff --git a/server/src/apub/post.rs b/server/src/apub/post.rs index 381ba3c6..77f8d984 100644 --- a/server/src/apub/post.rs +++ b/server/src/apub/post.rs @@ -12,14 +12,18 @@ pub async fn get_apub_post( ) -> Result<HttpResponse<Body>, Error> { let id = info.post_id.parse::<i32>()?; let post = Post::read(&&db.get()?, id)?; - Ok(create_apub_response(&post.to_apub(&db.get().unwrap())?)) + if !post.deleted { + Ok(create_apub_response(&post.to_apub(&db.get().unwrap())?)) + } else { + Ok(create_apub_tombstone_response(&post.to_tombstone()?)) + } } impl ToApub for Post { type Response = Page; // Turn a Lemmy post into an ActivityPub page that can be sent out over the network. - fn to_apub(&self, conn: &PgConnection) -> Result<ResponseOrTombstone<Page>, Error> { + fn to_apub(&self, conn: &PgConnection) -> Result<Page, Error> { let mut page = Page::default(); let oprops: &mut ObjectProperties = page.as_mut(); let creator = User_::read(conn, self.creator_id)?; @@ -51,7 +55,13 @@ impl ToApub for Post { oprops.set_updated(convert_datetime(u))?; } - Ok(ResponseOrTombstone::Response(page)) + Ok(page) + } +} + +impl ToTombstone for Post { + fn to_tombstone(&self) -> Result<Tombstone, Error> { + create_tombstone(self.deleted, &self.ap_id, self.published, self.updated) } } @@ -109,7 +119,7 @@ impl ApubObjectType for Post { create .create_props .set_actor_xsd_any_uri(creator.actor_id.to_owned())? - .set_object_base_box(page.as_response()?.to_owned())?; + .set_object_base_box(page)?; // Insert the sent activity into the activity table let activity_form = activity::ActivityForm { @@ -144,7 +154,7 @@ impl ApubObjectType for Post { update .update_props .set_actor_xsd_any_uri(creator.actor_id.to_owned())? - .set_object_base_box(page.as_response()?.to_owned())?; + .set_object_base_box(page)?; // Insert the sent activity into the activity table let activity_form = activity::ActivityForm { @@ -163,6 +173,32 @@ impl ApubObjectType for Post { )?; Ok(()) } + + fn send_delete(&self, actor: &User_, conn: &PgConnection) -> Result<(), Error> { + let mut delete = Delete::default(); + delete + .delete_props + .set_actor_xsd_any_uri(actor.actor_id.to_owned())? + .set_object_base_box(BaseBox::from_concrete(self.to_tombstone()?)?)?; + + // Insert the sent activity into the activity table + let activity_form = activity::ActivityForm { + user_id: self.creator_id, + data: serde_json::to_value(&delete)?, + local: true, + updated: None, + }; + activity::Activity::create(&conn, &activity_form)?; + + let community = Community::read(conn, self.community_id)?; + send_activity( + &delete, + &actor.private_key.to_owned().unwrap(), + &actor.actor_id, + community.get_follower_inboxes(&conn)?, + )?; + Ok(()) + } } impl ApubLikeableType for Post { @@ -176,7 +212,7 @@ impl ApubLikeableType for Post { like .like_props .set_actor_xsd_any_uri(creator.actor_id.to_owned())? - .set_object_base_box(page.as_response()?.to_owned())?; + .set_object_base_box(page)?; // Insert the sent activity into the activity table let activity_form = activity::ActivityForm { @@ -210,7 +246,7 @@ impl ApubLikeableType for Post { dislike .dislike_props .set_actor_xsd_any_uri(creator.actor_id.to_owned())? - .set_object_base_box(page.as_response()?.to_owned())?; + .set_object_base_box(page)?; // Insert the sent activity into the activity table let activity_form = activity::ActivityForm { |