Broadcast delete to AP
This commit is contained in:
parent
b8aade1e12
commit
bae49bcb47
@ -95,6 +95,50 @@ impl Activity for Create {
|
||||
}
|
||||
}
|
||||
|
||||
#[derive(Clone)]
|
||||
pub struct Delete {
|
||||
id: String,
|
||||
actor: serde_json::Value,
|
||||
object: serde_json::Value,
|
||||
date: chrono::DateTime<chrono::Utc>
|
||||
}
|
||||
|
||||
impl Delete {
|
||||
pub fn new<A: Actor, B: Object>(actor: &A, obj: &B, conn: &PgConnection) -> Delete {
|
||||
Delete {
|
||||
id: format!("{}#delete", obj.compute_id(conn)),
|
||||
actor: serde_json::Value::String(actor.compute_id(conn)),
|
||||
object: serde_json::Value::String(obj.compute_id(conn)),
|
||||
date: chrono::Utc::now()
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
impl Activity for Delete {
|
||||
fn get_id(&self) -> String {
|
||||
self.id.clone()
|
||||
}
|
||||
|
||||
fn get_type(&self) -> String {
|
||||
"Delete".to_string()
|
||||
}
|
||||
|
||||
fn serialize(&self) -> serde_json::Value {
|
||||
json!({
|
||||
"type": "Delete",
|
||||
"id": self.id,
|
||||
"actor": self.actor,
|
||||
"object": {
|
||||
"type": "Tombstone",
|
||||
"id": self.object
|
||||
},
|
||||
"published": self.date.to_rfc3339(),
|
||||
"to": self.object["to"],
|
||||
"cc": self.object["cc"]
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
#[derive(Clone)]
|
||||
pub struct Follow {
|
||||
id: String,
|
||||
|
@ -1,6 +1,9 @@
|
||||
use chrono;
|
||||
use diesel::{self, PgConnection, QueryDsl, RunQueryDsl, ExpressionMethods};
|
||||
use serde_json;
|
||||
|
||||
use activity_pub::actor::Actor;
|
||||
use activity_pub::object::Object;
|
||||
use models::posts::Post;
|
||||
use models::users::User;
|
||||
use schema::likes;
|
||||
@ -49,3 +52,19 @@ impl Like {
|
||||
diesel::delete(self).execute(conn).unwrap();
|
||||
}
|
||||
}
|
||||
|
||||
impl Object for Like {
|
||||
fn serialize(&self, conn: &PgConnection) -> serde_json::Value {
|
||||
json!({
|
||||
"id": self.compute_id(conn)
|
||||
})
|
||||
}
|
||||
|
||||
fn compute_id(&self, conn: &PgConnection) -> String {
|
||||
format!(
|
||||
"{}/like/{}",
|
||||
User::get(conn, self.user_id).unwrap().compute_id(conn),
|
||||
Post::get(conn, self.post_id).unwrap().compute_id(conn)
|
||||
)
|
||||
}
|
||||
}
|
||||
|
@ -1,6 +1,6 @@
|
||||
use rocket::response::Redirect;
|
||||
|
||||
use activity_pub::activity::Like;
|
||||
use activity_pub::activity::{Like, Delete};
|
||||
use activity_pub::outbox::broadcast;
|
||||
use db_conn::DbConn;
|
||||
use models::likes;
|
||||
@ -21,7 +21,7 @@ fn create(blog: String, slug: String, user: User, conn: DbConn) -> Redirect {
|
||||
} else {
|
||||
let like = likes::Like::for_user_on_post(&*conn, &user, &post).unwrap();
|
||||
like.delete(&*conn);
|
||||
// TODO: send Delete to AP
|
||||
broadcast(&*conn, &user, Delete::new(&user, &like, &*conn), user.get_followers(&*conn));
|
||||
}
|
||||
|
||||
Redirect::to(format!("/~/{}/{}/", blog, slug).as_ref())
|
||||
|
Loading…
Reference in New Issue
Block a user