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);