summaryrefslogtreecommitdiffstats
path: root/server/src/apub/community.rs
diff options
context:
space:
mode:
authorFelix <me@nutomic.com>2020-04-28 19:46:25 +0200
committerFelix <me@nutomic.com>2020-04-28 19:46:25 +0200
commit0c0c68398609d549a757a9c3a26ce2311075fa38 (patch)
treefe2f07a1ad195bc042217538fc2b3e54e7a44124 /server/src/apub/community.rs
parent36d0e34668b94a955306a4b83947deb1f10689f2 (diff)
Implement deleting communities
Diffstat (limited to 'server/src/apub/community.rs')
-rw-r--r--server/src/apub/community.rs46
1 files changed, 42 insertions, 4 deletions
diff --git a/server/src/apub/community.rs b/server/src/apub/community.rs
index 46bd9024..ee319995 100644
--- a/server/src/apub/community.rs
+++ b/server/src/apub/community.rs
@@ -9,7 +9,17 @@ impl ToApub for Community {
type Response = GroupExt;
// Turn a Lemmy Community into an ActivityPub group that can be sent out over the network.
- fn to_apub(&self, conn: &PgConnection) -> Result<GroupExt, Error> {
+ fn to_apub(&self, conn: &PgConnection) -> Result<ResponseOrTombstone<GroupExt>, Error> {
+ if self.deleted || self.removed {
+ let mut tombstone = Tombstone::default();
+ // TODO: might want to include updated/deleted times as well
+ tombstone
+ .object_props
+ .set_id(self.actor_id.to_owned())?
+ .set_published(convert_datetime(self.published))?;
+ return Ok(ResponseOrTombstone::Tombstone(Box::new(tombstone)));
+ }
+
let mut group = Group::default();
let oprops: &mut ObjectProperties = group.as_mut();
@@ -43,7 +53,9 @@ impl ToApub for Community {
.set_endpoints(endpoint_props)?
.set_followers(self.get_followers_url())?;
- Ok(group.extend(actor_props).extend(self.get_public_key_ext()))
+ Ok(ResponseOrTombstone::Response(
+ group.extend(actor_props).extend(self.get_public_key_ext()),
+ ))
}
}
@@ -94,10 +106,36 @@ impl ActorType for Community {
Ok(())
}
+ fn send_delete(&self, conn: &PgConnection) -> Result<(), Error> {
+ let community = self.to_apub(conn)?;
+ let mut delete = Delete::default();
+ delete
+ .delete_props
+ .set_actor_xsd_any_uri(self.actor_id.to_owned())?
+ .set_object_base_box(BaseBox::from_concrete(
+ community.as_tombstone()?.to_owned(),
+ )?)?;
+
+ // 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)?;
+
+ send_activity(
+ &delete,
+ &self.private_key.to_owned().unwrap(),
+ &self.actor_id,
+ self.get_follower_inboxes(&conn)?,
+ )?;
+ Ok(())
+ }
+
/// For a given community, returns the inboxes of all followers.
fn get_follower_inboxes(&self, conn: &PgConnection) -> Result<Vec<String>, Error> {
- debug!("got here.");
-
Ok(
CommunityFollowerView::for_community(conn, self.id)?
.into_iter()