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
This commit is contained in:
Trinity Pointard 2018-10-28 11:42:01 +01:00
parent cbbd0ca920
commit 0bb2e6293a

View File

@ -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 // 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.published = true;
post.creation_date = Utc::now().naive_utc(); post.creation_date = Utc::now().naive_utc();
} true
} else {
false
};
post.slug = new_slug.clone(); post.slug = new_slug.clone();
post.title = form.title.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 { if post.published {
let act = post.update_activity(&*conn); if newly_published {
let dest = User::one_by_instance(&*conn); let act = post.create_activity(&conn);
worker.execute(Thunk::of(move || broadcast(&user, act, dest))); 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))) Ok(Redirect::to(uri!(details: blog = blog, slug = new_slug)))