diff options
Diffstat (limited to 'server/src/apub/comment.rs')
-rw-r--r-- | server/src/apub/comment.rs | 47 |
1 files changed, 47 insertions, 0 deletions
diff --git a/server/src/apub/comment.rs b/server/src/apub/comment.rs index 55dec23b..17da45a6 100644 --- a/server/src/apub/comment.rs +++ b/server/src/apub/comment.rs @@ -413,4 +413,51 @@ impl ApubLikeableType for Comment { )?; Ok(()) } + + fn send_undo_like(&self, creator: &User_, conn: &PgConnection) -> Result<(), Error> { + let note = self.to_apub(&conn)?; + let post = Post::read(&conn, self.post_id)?; + let community = Community::read(&conn, post.community_id)?; + let id = format!("{}/dislike/{}", self.ap_id, uuid::Uuid::new_v4()); + + let mut like = Like::new(); + populate_object_props(&mut like.object_props, &community.get_followers_url(), &id)?; + like + .like_props + .set_actor_xsd_any_uri(creator.actor_id.to_owned())? + .set_object_base_box(note)?; + + // TODO + // Undo that fake activity + let undo_id = format!("{}/undo/like/{}", self.ap_id, uuid::Uuid::new_v4()); + let mut undo = Undo::default(); + + populate_object_props( + &mut undo.object_props, + &community.get_followers_url(), + &undo_id, + )?; + + undo + .undo_props + .set_actor_xsd_any_uri(creator.actor_id.to_owned())? + .set_object_base_box(like)?; + + // Insert the sent activity into the activity table + let activity_form = activity::ActivityForm { + user_id: creator.id, + data: serde_json::to_value(&undo)?, + local: true, + updated: None, + }; + activity::Activity::create(&conn, &activity_form)?; + + send_activity( + &undo, + &creator.private_key.as_ref().unwrap(), + &creator.actor_id, + community.get_follower_inboxes(&conn)?, + )?; + Ok(()) + } } |