Allow for comment deletion (#363)

* Allow for comment deletion

Receive and emit deletion activity
Add button to delete comment

* Remove debug print and fix copy-past typo

* Improve style of comment deletion button
This commit is contained in:
fdb-hiroshima
2018-12-23 11:13:36 +01:00
committed by GitHub
parent 0df9c4d400
commit 5c5cf36b0d
8 changed files with 86 additions and 12 deletions
+8
View File
@@ -65,6 +65,14 @@ pub trait Inbox {
actor_id.as_ref(),
&(conn, searcher),
);
Comment::delete_id(
&act.delete_props
.object_object::<Tombstone>()?
.object_props
.id_string()?,
actor_id.as_ref(),
conn,
);
Ok(())
}
"Follow" => {
+1
View File
@@ -91,6 +91,7 @@ fn main() {
routes::blogs::atom_feed,
routes::comments::create,
routes::comments::delete,
routes::comments::activity_pub,
routes::instance::index,
+14 -1
View File
@@ -7,7 +7,8 @@ use rocket_i18n::I18n;
use validator::Validate;
use template_utils::Ructe;
use plume_common::{utils, activity_pub::{broadcast, ApRequest, ActivityStream}};
use plume_common::{utils, activity_pub::{broadcast, ApRequest,
ActivityStream, inbox::Deletable}};
use plume_models::{
blogs::Blog,
comments::*,
@@ -86,6 +87,18 @@ pub fn create(blog_name: String, slug: String, form: LenientForm<NewCommentForm>
})
}
#[post("/~/<blog>/<slug>/comment/<id>/delete")]
pub fn delete(blog: String, slug: String, id: i32, user: User, conn: DbConn, worker: Worker) -> Redirect {
if let Some(comment) = Comment::get(&*conn, id) {
if comment.author_id == user.id {
let dest = User::one_by_instance(&*conn);
let delete_activity = comment.delete(&*conn);
worker.execute(move || broadcast(&user, delete_activity, dest));
}
}
Redirect::to(uri!(super::posts::details: blog = blog, slug = slug, responding_to = _))
}
#[get("/~/<_blog>/<_slug>/comment/<id>")]
pub fn activity_pub(_blog: String, _slug: String, id: i32, _ap: ApRequest, conn: DbConn) -> Option<ActivityStream<Note>> {
Comment::get(&*conn, id).map(|c| ActivityStream::new(c.to_activity(&*conn)))