Use Comment::build_delete07() instead of build_delete()

This commit is contained in:
Kitaiti Makoto 2022-05-02 23:26:25 +09:00
parent 6cc43c2420
commit b5e1076b0e
2 changed files with 10 additions and 57 deletions

View File

@ -11,17 +11,13 @@ use crate::{
users::User,
Connection, Error, Result, CONFIG,
};
use activitypub::{
activity::Delete,
link,
object::{Note, Tombstone},
};
use activitypub::{link, object::Note};
use activitystreams::{
activity::{Create as Create07, Delete as Delete07},
activity::{Create as Create07, Delete},
base::{AnyBase, Base},
iri_string::types::IriString,
link::{self as link07, kind::MentionType},
object::{Note as Note07, Tombstone as Tombstone07},
object::{Note as Note07, Tombstone},
prelude::*,
primitives::OneOrMany,
time::OffsetDateTime,
@ -236,27 +232,8 @@ impl Comment {
Ok(())
}
pub fn build_delete(&self, conn: &Connection) -> Result<Delete> {
let mut act = Delete::default();
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();
pub fn build_delete07(&self, conn: &Connection) -> Result<Delete> {
let mut tombstone = Tombstone::new();
tombstone.set_id(
self.ap_url
.as_ref()
@ -264,7 +241,7 @@ impl Comment {
.parse::<IriString>()?,
);
let mut act = Delete07::new(
let mut act = Delete::new(
self.get_author(conn)?.into_id().parse::<IriString>()?,
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 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]
fn build_delete07() {
let conn = db();

View File

@ -11,7 +11,7 @@ use std::time::Duration;
use crate::routes::errors::ErrorPage;
use crate::template_utils::IntoContext;
use plume_common::{
activity_pub::{broadcast, broadcast07, ActivityStream, ApRequest},
activity_pub::{broadcast07, ActivityStream, ApRequest},
utils,
};
use plume_models::{
@ -150,7 +150,7 @@ pub fn delete(
if let Ok(comment) = Comment::get(&conn, id) {
if comment.author_id == user.id {
let dest = User::one_by_instance(&conn)?;
let delete_activity = comment.build_delete(&conn)?;
let delete_activity = comment.build_delete07(&conn)?;
inbox(
&conn,
serde_json::to_value(&delete_activity).map_err(Error::from)?,
@ -158,7 +158,7 @@ pub fn delete(
let user_c = user.clone();
rockets.worker.execute(move || {
broadcast(&user_c, delete_activity, dest, CONFIG.proxy().cloned())
broadcast07(&user_c, delete_activity, dest, CONFIG.proxy().cloned())
});
rockets
.worker