Replace PlumeRocket.conn with DbConn
This commit is contained in:
+30
-31
@@ -15,8 +15,9 @@ use plume_common::{
|
||||
utils,
|
||||
};
|
||||
use plume_models::{
|
||||
blogs::Blog, comments::*, inbox::inbox, instance::Instance, medias::Media, mentions::Mention,
|
||||
posts::Post, safe_string::SafeString, tags::Tag, users::User, Error, PlumeRocket, CONFIG,
|
||||
blogs::Blog, comments::*, db_conn::DbConn, inbox::inbox, instance::Instance, medias::Media,
|
||||
mentions::Mention, posts::Post, safe_string::SafeString, tags::Tag, users::User, Error,
|
||||
PlumeRocket, CONFIG,
|
||||
};
|
||||
|
||||
#[derive(Default, FromForm, Debug, Validate)]
|
||||
@@ -33,11 +34,11 @@ pub fn create(
|
||||
slug: String,
|
||||
form: LenientForm<NewCommentForm>,
|
||||
user: User,
|
||||
conn: DbConn,
|
||||
rockets: PlumeRocket,
|
||||
) -> Result<Flash<Redirect>, Ructe> {
|
||||
let conn = &*rockets.conn;
|
||||
let blog = Blog::find_by_fqn(&rockets, &blog_name).expect("comments::create: blog error");
|
||||
let post = Post::find_by_slug(&*conn, &slug, blog.id).expect("comments::create: post error");
|
||||
let blog = Blog::find_by_fqn(&conn, &blog_name).expect("comments::create: blog error");
|
||||
let post = Post::find_by_slug(&conn, &slug, blog.id).expect("comments::create: post error");
|
||||
form.validate()
|
||||
.map(|_| {
|
||||
let (html, mentions, _hashtags) = utils::md_to_html(
|
||||
@@ -51,7 +52,7 @@ pub fn create(
|
||||
Some(Media::get_media_processor(&conn, vec![&user])),
|
||||
);
|
||||
let comm = Comment::insert(
|
||||
&*conn,
|
||||
&conn,
|
||||
NewComment {
|
||||
content: SafeString::new(html.as_ref()),
|
||||
in_response_to_id: form.responding_to,
|
||||
@@ -65,14 +66,14 @@ pub fn create(
|
||||
)
|
||||
.expect("comments::create: insert error");
|
||||
let new_comment = comm
|
||||
.create_activity(&rockets)
|
||||
.create_activity(&conn)
|
||||
.expect("comments::create: activity error");
|
||||
|
||||
// save mentions
|
||||
for ment in mentions {
|
||||
Mention::from_activity(
|
||||
&*conn,
|
||||
&Mention::build_activity(&rockets, &ment)
|
||||
&conn,
|
||||
&Mention::build_activity(&conn, &ment)
|
||||
.expect("comments::create: build mention error"),
|
||||
comm.id,
|
||||
false,
|
||||
@@ -81,10 +82,10 @@ pub fn create(
|
||||
.expect("comments::create: mention save error");
|
||||
}
|
||||
|
||||
comm.notify(&*conn).expect("comments::create: notify error");
|
||||
comm.notify(&conn).expect("comments::create: notify error");
|
||||
|
||||
// federate
|
||||
let dest = User::one_by_instance(&*conn).expect("comments::create: dest error");
|
||||
let dest = User::one_by_instance(&conn).expect("comments::create: dest error");
|
||||
let user_clone = user.clone();
|
||||
rockets.worker.execute(move || {
|
||||
broadcast(&user_clone, new_comment, dest, CONFIG.proxy().cloned())
|
||||
@@ -101,38 +102,36 @@ pub fn create(
|
||||
})
|
||||
.map_err(|errors| {
|
||||
// TODO: de-duplicate this code
|
||||
let comments = CommentTree::from_post(&*conn, &post, Some(&user))
|
||||
let comments = CommentTree::from_post(&conn, &post, Some(&user))
|
||||
.expect("comments::create: comments error");
|
||||
|
||||
let previous = form
|
||||
.responding_to
|
||||
.and_then(|r| Comment::get(&*conn, r).ok());
|
||||
let previous = form.responding_to.and_then(|r| Comment::get(&conn, r).ok());
|
||||
|
||||
render!(posts::details(
|
||||
&rockets.to_context(),
|
||||
&(&conn, &rockets).to_context(),
|
||||
post.clone(),
|
||||
blog,
|
||||
&*form,
|
||||
errors,
|
||||
Tag::for_post(&*conn, post.id).expect("comments::create: tags error"),
|
||||
Tag::for_post(&conn, post.id).expect("comments::create: tags error"),
|
||||
comments,
|
||||
previous,
|
||||
post.count_likes(&*conn)
|
||||
post.count_likes(&conn)
|
||||
.expect("comments::create: count likes error"),
|
||||
post.count_reshares(&*conn)
|
||||
post.count_reshares(&conn)
|
||||
.expect("comments::create: count reshares error"),
|
||||
user.has_liked(&*conn, &post)
|
||||
user.has_liked(&conn, &post)
|
||||
.expect("comments::create: liked error"),
|
||||
user.has_reshared(&*conn, &post)
|
||||
user.has_reshared(&conn, &post)
|
||||
.expect("comments::create: reshared error"),
|
||||
user.is_following(
|
||||
&*conn,
|
||||
post.get_authors(&*conn)
|
||||
post.get_authors(&conn)
|
||||
.expect("comments::create: authors error")[0]
|
||||
.id
|
||||
)
|
||||
.expect("comments::create: following error"),
|
||||
post.get_authors(&*conn)
|
||||
post.get_authors(&conn)
|
||||
.expect("comments::create: authors error")[0]
|
||||
.clone()
|
||||
))
|
||||
@@ -145,14 +144,15 @@ pub fn delete(
|
||||
slug: String,
|
||||
id: i32,
|
||||
user: User,
|
||||
conn: DbConn,
|
||||
rockets: PlumeRocket,
|
||||
) -> Result<Flash<Redirect>, ErrorPage> {
|
||||
if let Ok(comment) = Comment::get(&*rockets.conn, id) {
|
||||
if let Ok(comment) = Comment::get(&conn, id) {
|
||||
if comment.author_id == user.id {
|
||||
let dest = User::one_by_instance(&*rockets.conn)?;
|
||||
let delete_activity = comment.build_delete(&*rockets.conn)?;
|
||||
let dest = User::one_by_instance(&conn)?;
|
||||
let delete_activity = comment.build_delete(&conn)?;
|
||||
inbox(
|
||||
&rockets,
|
||||
&conn,
|
||||
serde_json::to_value(&delete_activity).map_err(Error::from)?,
|
||||
)?;
|
||||
|
||||
@@ -160,7 +160,6 @@ pub fn delete(
|
||||
rockets.worker.execute(move || {
|
||||
broadcast(&user_c, delete_activity, dest, CONFIG.proxy().cloned())
|
||||
});
|
||||
let conn = rockets.conn;
|
||||
rockets
|
||||
.worker
|
||||
.execute_after(Duration::from_secs(10 * 60), move || {
|
||||
@@ -185,10 +184,10 @@ pub fn activity_pub(
|
||||
_slug: String,
|
||||
id: i32,
|
||||
_ap: ApRequest,
|
||||
rockets: PlumeRocket,
|
||||
conn: DbConn,
|
||||
) -> Option<ActivityStream<Note>> {
|
||||
Comment::get(&*rockets.conn, id)
|
||||
.and_then(|c| c.to_activity(&rockets))
|
||||
Comment::get(&conn, id)
|
||||
.and_then(|c| c.to_activity(&conn))
|
||||
.ok()
|
||||
.map(ActivityStream::new)
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user