From 0bb2e6293a93885d8b53d45e308a7f24476723df Mon Sep 17 00:00:00 2001 From: Trinity Pointard Date: Sun, 28 Oct 2018 11:42:01 +0100 Subject: [PATCH] Send Create activity when undrafting post Send a Create activity when a post get undrafted, instead of sending an Update activity for a non federated post Fix #221 --- src/routes/posts.rs | 19 ++++++++++++++----- 1 file changed, 14 insertions(+), 5 deletions(-) diff --git a/src/routes/posts.rs b/src/routes/posts.rs index b7692f5e..d544e4ae 100644 --- a/src/routes/posts.rs +++ b/src/routes/posts.rs @@ -192,10 +192,13 @@ fn update(blog: String, slug: String, user: User, conn: DbConn, data: LenientFor }; // update publication date if when this article is no longer a draft - if !post.published && !form.draft { + let newly_published = if !post.published && !form.draft { post.published = true; post.creation_date = Utc::now().naive_utc(); - } + true + } else { + false + }; post.slug = new_slug.clone(); post.title = form.title.clone(); @@ -246,9 +249,15 @@ fn update(blog: String, slug: String, user: User, conn: DbConn, data: LenientFor } if post.published { - let act = post.update_activity(&*conn); - let dest = User::one_by_instance(&*conn); - worker.execute(Thunk::of(move || broadcast(&user, act, dest))); + if newly_published { + let act = post.create_activity(&conn); + let dest = User::one_by_instance(&*conn); + worker.execute(Thunk::of(move || broadcast(&user, act, dest))); + } else { + let act = post.update_activity(&*conn); + let dest = User::one_by_instance(&*conn); + worker.execute(Thunk::of(move || broadcast(&user, act, dest))); + } } Ok(Redirect::to(uri!(details: blog = blog, slug = new_slug)))