Use Comment::build_delete07() instead of build_delete()
This commit is contained in:
parent
6cc43c2420
commit
b5e1076b0e
@ -11,17 +11,13 @@ use crate::{
|
|||||||
users::User,
|
users::User,
|
||||||
Connection, Error, Result, CONFIG,
|
Connection, Error, Result, CONFIG,
|
||||||
};
|
};
|
||||||
use activitypub::{
|
use activitypub::{link, object::Note};
|
||||||
activity::Delete,
|
|
||||||
link,
|
|
||||||
object::{Note, Tombstone},
|
|
||||||
};
|
|
||||||
use activitystreams::{
|
use activitystreams::{
|
||||||
activity::{Create as Create07, Delete as Delete07},
|
activity::{Create as Create07, Delete},
|
||||||
base::{AnyBase, Base},
|
base::{AnyBase, Base},
|
||||||
iri_string::types::IriString,
|
iri_string::types::IriString,
|
||||||
link::{self as link07, kind::MentionType},
|
link::{self as link07, kind::MentionType},
|
||||||
object::{Note as Note07, Tombstone as Tombstone07},
|
object::{Note as Note07, Tombstone},
|
||||||
prelude::*,
|
prelude::*,
|
||||||
primitives::OneOrMany,
|
primitives::OneOrMany,
|
||||||
time::OffsetDateTime,
|
time::OffsetDateTime,
|
||||||
@ -236,27 +232,8 @@ impl Comment {
|
|||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn build_delete(&self, conn: &Connection) -> Result<Delete> {
|
pub fn build_delete07(&self, conn: &Connection) -> Result<Delete> {
|
||||||
let mut act = Delete::default();
|
let mut tombstone = Tombstone::new();
|
||||||
act.delete_props
|
|
||||||
.set_actor_link(self.get_author(conn)?.into_id())?;
|
|
||||||
|
|
||||||
let mut tombstone = Tombstone::default();
|
|
||||||
tombstone
|
|
||||||
.object_props
|
|
||||||
.set_id_string(self.ap_url.clone().ok_or(Error::MissingApProperty)?)?;
|
|
||||||
act.delete_props.set_object_object(tombstone)?;
|
|
||||||
|
|
||||||
act.object_props
|
|
||||||
.set_id_string(format!("{}#delete", self.ap_url.clone().unwrap()))?;
|
|
||||||
act.object_props
|
|
||||||
.set_to_link_vec(vec![Id::new(PUBLIC_VISIBILITY)])?;
|
|
||||||
|
|
||||||
Ok(act)
|
|
||||||
}
|
|
||||||
|
|
||||||
pub fn build_delete07(&self, conn: &Connection) -> Result<Delete07> {
|
|
||||||
let mut tombstone = Tombstone07::new();
|
|
||||||
tombstone.set_id(
|
tombstone.set_id(
|
||||||
self.ap_url
|
self.ap_url
|
||||||
.as_ref()
|
.as_ref()
|
||||||
@ -264,7 +241,7 @@ impl Comment {
|
|||||||
.parse::<IriString>()?,
|
.parse::<IriString>()?,
|
||||||
);
|
);
|
||||||
|
|
||||||
let mut act = Delete07::new(
|
let mut act = Delete::new(
|
||||||
self.get_author(conn)?.into_id().parse::<IriString>()?,
|
self.get_author(conn)?.into_id().parse::<IriString>()?,
|
||||||
Base::retract(tombstone)?.into_generic()?,
|
Base::retract(tombstone)?.into_generic()?,
|
||||||
);
|
);
|
||||||
@ -423,7 +400,7 @@ impl AsObject<User, Create07, &DbConn> for Comment {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
impl AsObject<User, Delete07, &DbConn> for Comment {
|
impl AsObject<User, Delete, &DbConn> for Comment {
|
||||||
type Error = Error;
|
type Error = Error;
|
||||||
type Output = ();
|
type Output = ();
|
||||||
|
|
||||||
@ -666,30 +643,6 @@ mod tests {
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
#[test]
|
|
||||||
fn build_delete() {
|
|
||||||
let conn = db();
|
|
||||||
conn.test_transaction::<_, Error, _>(|| {
|
|
||||||
let (comment, _posts, _users, _blogs) = prepare_activity(&conn);
|
|
||||||
let act = comment.build_delete(&conn)?;
|
|
||||||
|
|
||||||
let expected = json!({
|
|
||||||
"actor": "https://plu.me/@/admin/",
|
|
||||||
"id": format!("https://plu.me/~/BlogName/testing/comment/{}#delete", comment.id),
|
|
||||||
"object": {
|
|
||||||
"id": format!("https://plu.me/~/BlogName/testing/comment/{}", comment.id),
|
|
||||||
"type": "Tombstone"
|
|
||||||
},
|
|
||||||
"to": ["https://www.w3.org/ns/activitystreams#Public"],
|
|
||||||
"type": "Delete"
|
|
||||||
});
|
|
||||||
|
|
||||||
assert_json_eq!(to_value(act)?, expected);
|
|
||||||
|
|
||||||
Ok(())
|
|
||||||
});
|
|
||||||
}
|
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn build_delete07() {
|
fn build_delete07() {
|
||||||
let conn = db();
|
let conn = db();
|
||||||
|
@ -11,7 +11,7 @@ use std::time::Duration;
|
|||||||
use crate::routes::errors::ErrorPage;
|
use crate::routes::errors::ErrorPage;
|
||||||
use crate::template_utils::IntoContext;
|
use crate::template_utils::IntoContext;
|
||||||
use plume_common::{
|
use plume_common::{
|
||||||
activity_pub::{broadcast, broadcast07, ActivityStream, ApRequest},
|
activity_pub::{broadcast07, ActivityStream, ApRequest},
|
||||||
utils,
|
utils,
|
||||||
};
|
};
|
||||||
use plume_models::{
|
use plume_models::{
|
||||||
@ -150,7 +150,7 @@ pub fn delete(
|
|||||||
if let Ok(comment) = Comment::get(&conn, id) {
|
if let Ok(comment) = Comment::get(&conn, id) {
|
||||||
if comment.author_id == user.id {
|
if comment.author_id == user.id {
|
||||||
let dest = User::one_by_instance(&conn)?;
|
let dest = User::one_by_instance(&conn)?;
|
||||||
let delete_activity = comment.build_delete(&conn)?;
|
let delete_activity = comment.build_delete07(&conn)?;
|
||||||
inbox(
|
inbox(
|
||||||
&conn,
|
&conn,
|
||||||
serde_json::to_value(&delete_activity).map_err(Error::from)?,
|
serde_json::to_value(&delete_activity).map_err(Error::from)?,
|
||||||
@ -158,7 +158,7 @@ pub fn delete(
|
|||||||
|
|
||||||
let user_c = user.clone();
|
let user_c = user.clone();
|
||||||
rockets.worker.execute(move || {
|
rockets.worker.execute(move || {
|
||||||
broadcast(&user_c, delete_activity, dest, CONFIG.proxy().cloned())
|
broadcast07(&user_c, delete_activity, dest, CONFIG.proxy().cloned())
|
||||||
});
|
});
|
||||||
rockets
|
rockets
|
||||||
.worker
|
.worker
|
||||||
|
Loading…
Reference in New Issue
Block a user