From 08873990486b890f7636c12d7d331399d979ef1f Mon Sep 17 00:00:00 2001 From: Kitaiti Makoto Date: Sun, 24 Apr 2022 06:42:48 +0900 Subject: [PATCH] Implement AsObject07 for Reshare --- plume-models/src/reshares.rs | 22 +++++++++++++++++++++- 1 file changed, 21 insertions(+), 1 deletion(-) diff --git a/plume-models/src/reshares.rs b/plume-models/src/reshares.rs index e22fb7e8..8198edae 100644 --- a/plume-models/src/reshares.rs +++ b/plume-models/src/reshares.rs @@ -4,7 +4,7 @@ use crate::{ }; use activitypub::activity::{Announce, Undo}; use activitystreams::{ - activity::{ActorAndObjectRef, Announce as Announce07}, + activity::{ActorAndObjectRef, Announce as Announce07, Undo as Undo07}, iri_string::types::IriString, prelude::*, }; @@ -279,6 +279,26 @@ impl AsObject for Reshare { } } +impl AsObject07 for Reshare { + 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::RESHARE, self.id) { + diesel::delete(¬if).execute(&**conn)?; + } + + Ok(()) + } else { + Err(Error::Unauthorized) + } + } +} + impl NewReshare { pub fn new(p: &Post, u: &User) -> Self { let ap_url = format!("{}reshare/{}", u.ap_url, p.ap_url);