diff options
author | Dessalines <tyhou13@gmx.com> | 2020-05-01 15:01:29 -0400 |
---|---|---|
committer | Dessalines <tyhou13@gmx.com> | 2020-05-01 15:01:29 -0400 |
commit | 5366797a4b14634f1cfee183b8b8309efd457f46 (patch) | |
tree | cb212dcba31f1f299d1f68792356d45681a03350 /server/src/apub/community.rs | |
parent | 2f1cd9976dbdc034836a01748086056999aff52a (diff) |
Add undos for delete community, post, and comment.
Diffstat (limited to 'server/src/apub/community.rs')
-rw-r--r-- | server/src/apub/community.rs | 44 |
1 files changed, 44 insertions, 0 deletions
diff --git a/server/src/apub/community.rs b/server/src/apub/community.rs index 336aa24f..c4d9bf83 100644 --- a/server/src/apub/community.rs +++ b/server/src/apub/community.rs @@ -137,6 +137,50 @@ impl ActorType for Community { Ok(()) } + fn send_undo_delete(&self, creator: &User_, conn: &PgConnection) -> Result<(), Error> { + let group = self.to_apub(conn)?; + let id = format!("{}/delete/{}", self.actor_id, uuid::Uuid::new_v4()); + + let mut delete = Delete::default(); + populate_object_props(&mut delete.object_props, &self.get_followers_url(), &id)?; + + delete + .delete_props + .set_actor_xsd_any_uri(creator.actor_id.to_owned())? + .set_object_base_box(group)?; + + // Undo that fake activity + let undo_id = format!("{}/undo/delete/{}", self.actor_id, uuid::Uuid::new_v4()); + let mut undo = Undo::default(); + + populate_object_props(&mut undo.object_props, &self.get_followers_url(), &undo_id)?; + + undo + .undo_props + .set_actor_xsd_any_uri(creator.actor_id.to_owned())? + .set_object_base_box(delete)?; + + // Insert the sent activity into the activity table + let activity_form = activity::ActivityForm { + user_id: self.creator_id, + data: serde_json::to_value(&undo)?, + local: true, + updated: None, + }; + activity::Activity::create(&conn, &activity_form)?; + + // Note: For an accept, since it was automatic, no one pushed a button, + // the community was the actor. + // But for delete, the creator is the actor, and does the signing + send_activity( + &undo, + &creator.private_key.as_ref().unwrap(), + &creator.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> { Ok( |