From 3e54d1098189ebb583f90660a77ff6430179043d Mon Sep 17 00:00:00 2001 From: Kitaiti Makoto Date: Sun, 24 Apr 2022 07:11:46 +0900 Subject: [PATCH] Implement AsObject07 for Like --- plume-models/src/likes.rs | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) diff --git a/plume-models/src/likes.rs b/plume-models/src/likes.rs index 2190fbc7..202354dc 100644 --- a/plume-models/src/likes.rs +++ b/plume-models/src/likes.rs @@ -266,6 +266,25 @@ impl AsObject for Like { } } +impl AsObject07 for Like { + type Error = Error; + type Output = (); + + fn activity07(self, conn: &DbConn, actor: User, _id: &str) -> Result<()> { + if actor.id == self.user_id { + diesel::delete(&self).execute(&**conn)?; + + // delete associated notification if any + if let Ok(notif) = Notification::find(conn, notification_kind::LIKE, self.id) { + diesel::delete(¬if).execute(&**conn)?; + } + Ok(()) + } else { + Err(Error::Unauthorized) + } + } +} + impl NewLike { pub fn new(p: &Post, u: &User) -> Self { let ap_url = format!("{}like/{}", u.ap_url, p.ap_url);