Allow likes to be deleted with AP

This commit is contained in:
Bat
2018-05-13 11:44:05 +01:00
parent bae49bcb47
commit 601fe7cf4f
7 changed files with 81 additions and 10 deletions
+38 -2
View File
@@ -210,12 +210,48 @@ impl Activity for Like {
}
fn get_type(&self) -> String {
"Follow".to_string()
"Like".to_string()
}
fn serialize(&self) -> serde_json::Value {
json!({
"type": "Follow",
"type": "Like",
"id": self.id,
"actor": self.actor,
"object": self.object
})
}
}
#[derive(Clone)]
pub struct Undo {
id: String,
actor: serde_json::Value,
object: serde_json::Value
}
impl Undo {
pub fn new<A: Actor, B: Object>(actor: &A, obj: &B, conn: &PgConnection) -> Undo {
Undo {
id: format!("{}/undo", obj.compute_id(conn)),
actor: serde_json::Value::String(actor.compute_id(conn)),
object: obj.serialize(conn)
}
}
}
impl Activity for Undo {
fn get_id(&self) -> String {
self.id.clone()
}
fn get_type(&self) -> String {
"Undo".to_string()
}
fn serialize(&self) -> serde_json::Value {
json!({
"type": "Undo",
"id": self.id,
"actor": self.actor,
"object": self.object
+11 -1
View File
@@ -64,9 +64,19 @@ pub trait Inbox: Actor + Sized {
let post = Post::get_by_ap_url(conn, act["object"].as_str().unwrap().to_string());
Like::insert(conn, NewLike {
post_id: post.unwrap().id,
user_id: liker.unwrap().id
user_id: liker.unwrap().id,
ap_url: act["id"].as_str().unwrap().to_string()
});
},
"Undo" => {
match act["object"]["type"].as_str().unwrap() {
"Like" => {
let like = Like::find_by_ap_url(conn, act["object"]["id"].as_str().unwrap().to_string()).unwrap();
like.delete(conn);
}
x => println!("Wanted to Undo a {}, but it is not supported yet", x)
}
},
x => println!("Received unknow activity type: {}", x)
}
}