mirror of
https://git.joinplu.me/Plume/Plume.git
synced 2024-11-26 05:21:00 +00:00
Use User::delete_activity07() instead of delete_activity()
This commit is contained in:
parent
fd341bdb22
commit
effdc44943
3 changed files with 13 additions and 67 deletions
|
@ -4,21 +4,16 @@ use crate::{
|
|||
safe_string::SafeString, schema::users, timeline::Timeline, Connection, Error, Result,
|
||||
UserEvent::*, CONFIG, ITEMS_PER_PAGE, USER_CHAN,
|
||||
};
|
||||
use activitypub::{
|
||||
activity::Delete,
|
||||
actor::Person,
|
||||
object::{Image, Tombstone},
|
||||
Activity, CustomObject, Endpoint,
|
||||
};
|
||||
use activitypub::{actor::Person, object::Image, Activity, CustomObject, Endpoint};
|
||||
use activitystreams::{
|
||||
activity::Delete as Delete07,
|
||||
activity::Delete,
|
||||
actor::{ApActor, AsApActor},
|
||||
actor::{ApActor as ApActor07, Endpoints as Endpoints07, Person as Person07},
|
||||
base::{AnyBase, Base},
|
||||
collection::{OrderedCollection as OrderedCollection07, OrderedCollectionPage},
|
||||
iri_string::types::IriString,
|
||||
markers::Activity as Activity07,
|
||||
object::{kind::ImageType, AsObject as _, Image as Image07, Tombstone as Tombstone07},
|
||||
object::{kind::ImageType, AsObject as _, Image as Image07, Tombstone},
|
||||
prelude::*,
|
||||
};
|
||||
use chrono::{NaiveDateTime, Utc};
|
||||
|
@ -917,34 +912,11 @@ impl User {
|
|||
Ok(CustomPerson07::new(actor, ap_signature))
|
||||
}
|
||||
|
||||
pub fn delete_activity(&self, conn: &Connection) -> Result<Delete> {
|
||||
let mut del = Delete::default();
|
||||
|
||||
let mut tombstone = Tombstone::default();
|
||||
tombstone.object_props.set_id_string(self.ap_url.clone())?;
|
||||
|
||||
del.delete_props
|
||||
.set_actor_link(Id::new(self.ap_url.clone()))?;
|
||||
del.delete_props.set_object_object(tombstone)?;
|
||||
del.object_props
|
||||
.set_id_string(format!("{}#delete", self.ap_url))?;
|
||||
del.object_props
|
||||
.set_to_link_vec(vec![Id::new(PUBLIC_VISIBILITY)])?;
|
||||
del.object_props.set_cc_link_vec(
|
||||
self.get_followers(conn)?
|
||||
.into_iter()
|
||||
.map(|f| Id::new(f.ap_url))
|
||||
.collect(),
|
||||
)?;
|
||||
|
||||
Ok(del)
|
||||
}
|
||||
|
||||
pub fn delete_activity07(&self, conn: &Connection) -> Result<Delete07> {
|
||||
let mut tombstone = Tombstone07::new();
|
||||
pub fn delete_activity07(&self, conn: &Connection) -> Result<Delete> {
|
||||
let mut tombstone = Tombstone::new();
|
||||
tombstone.set_id(self.ap_url.parse()?);
|
||||
|
||||
let mut del = Delete07::new(
|
||||
let mut del = Delete::new(
|
||||
self.ap_url.parse::<IriString>()?,
|
||||
Base::retract(tombstone)?.into_generic()?,
|
||||
);
|
||||
|
@ -1192,7 +1164,7 @@ impl AsActor<&DbConn> for User {
|
|||
}
|
||||
}
|
||||
|
||||
impl AsObject<User, Delete07, &DbConn> for User {
|
||||
impl AsObject<User, Delete, &DbConn> for User {
|
||||
type Error = Error;
|
||||
type Output = ();
|
||||
|
||||
|
@ -1700,32 +1672,6 @@ pub(crate) mod tests {
|
|||
});
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn delete_activity() {
|
||||
let conn = db();
|
||||
conn.test_transaction::<_, Error, _>(|| {
|
||||
let users = fill_database(&conn);
|
||||
let user = &users[1];
|
||||
let act = user.delete_activity(&conn)?;
|
||||
|
||||
let expected = json!({
|
||||
"actor": "https://plu.me/@/user/",
|
||||
"cc": [],
|
||||
"id": "https://plu.me/@/user/#delete",
|
||||
"object": {
|
||||
"id": "https://plu.me/@/user/",
|
||||
"type": "Tombstone",
|
||||
},
|
||||
"to": ["https://www.w3.org/ns/activitystreams#Public"],
|
||||
"type": "Delete",
|
||||
});
|
||||
|
||||
assert_json_eq!(to_value(act)?, expected);
|
||||
|
||||
Ok(())
|
||||
});
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn delete_activity07() {
|
||||
let conn = db();
|
||||
|
|
|
@ -11,7 +11,7 @@ use validator::{Validate, ValidationErrors};
|
|||
use crate::inbox;
|
||||
use crate::routes::{errors::ErrorPage, rocket_uri_macro_static_files, Page, RespondOrRedirect};
|
||||
use crate::template_utils::{IntoContext, Ructe};
|
||||
use plume_common::activity_pub::{broadcast, inbox::FromId};
|
||||
use plume_common::activity_pub::{broadcast07, inbox::FromId};
|
||||
use plume_models::{
|
||||
admin::*,
|
||||
blocklisted_emails::*,
|
||||
|
@ -382,8 +382,8 @@ fn ban(id: i32, conn: &Connection, worker: &ScheduledThreadPool) -> Result<(), E
|
|||
)
|
||||
.unwrap();
|
||||
let target = User::one_by_instance(&*conn)?;
|
||||
let delete_act = u.delete_activity(&*conn)?;
|
||||
worker.execute(move || broadcast(&u, delete_act, target, CONFIG.proxy().cloned()));
|
||||
let delete_act = u.delete_activity07(&*conn)?;
|
||||
worker.execute(move || broadcast07(&u, delete_act, target, CONFIG.proxy().cloned()));
|
||||
}
|
||||
|
||||
Ok(())
|
||||
|
|
|
@ -18,7 +18,7 @@ use crate::routes::{
|
|||
};
|
||||
use crate::template_utils::{IntoContext, Ructe};
|
||||
use crate::utils::requires_login;
|
||||
use plume_common::activity_pub::{broadcast, ActivityStream, ApRequest, Id};
|
||||
use plume_common::activity_pub::{broadcast, broadcast07, ActivityStream, ApRequest, Id};
|
||||
use plume_common::utils::md_to_html;
|
||||
use plume_models::{
|
||||
blogs::Blog,
|
||||
|
@ -386,10 +386,10 @@ pub fn delete(
|
|||
account.delete(&conn)?;
|
||||
|
||||
let target = User::one_by_instance(&conn)?;
|
||||
let delete_act = account.delete_activity(&conn)?;
|
||||
let delete_act = account.delete_activity07(&conn)?;
|
||||
rockets
|
||||
.worker
|
||||
.execute(move || broadcast(&account, delete_act, target, CONFIG.proxy().cloned()));
|
||||
.execute(move || broadcast07(&account, delete_act, target, CONFIG.proxy().cloned()));
|
||||
|
||||
if let Some(cookie) = cookies.get_private(AUTH_COOKIE) {
|
||||
cookies.remove_private(cookie);
|
||||
|
|
Loading…
Reference in a new issue