Private message query debugging.

This commit is contained in:
Dessalines 2021-01-06 16:02:08 -05:00
parent 1c113f915e
commit ceae7eb47a
2 changed files with 37 additions and 16 deletions

View File

@ -53,6 +53,17 @@ impl Perform for CreateComment {
let content_slurs_removed = remove_slurs(&data.content.to_owned());
// Check for a community ban
let post_id = data.post_id;
let post = get_post(post_id, context.pool()).await?;
check_community_ban(user.id, post.community_id, context.pool()).await?;
// Check if post is locked, no new comments
if post.locked {
return Err(APIError::err("locked").into());
}
let comment_form = CommentForm {
content: content_slurs_removed,
parent_id: data.parent_id.to_owned(),
@ -67,17 +78,6 @@ impl Perform for CreateComment {
local: true,
};
// Check for a community ban
let post_id = data.post_id;
let post = get_post(post_id, context.pool()).await?;
check_community_ban(user.id, post.community_id, context.pool()).await?;
// Check if post is locked, no new comments
if post.locked {
return Err(APIError::err("locked").into());
}
// Create the comment
let comment_form2 = comment_form.clone();
let inserted_comment = match blocking(context.pool(), move |conn| {
@ -133,11 +133,25 @@ impl Perform for CreateComment {
updated_comment.send_like(&user, context).await?;
let user_id = user.id;
let comment_view = blocking(context.pool(), move |conn| {
let mut comment_view = blocking(context.pool(), move |conn| {
CommentView::read(&conn, inserted_comment.id, Some(user_id))
})
.await??;
// If its a comment to yourself, mark it as read
let comment_id = comment_view.comment.id;
if user.id == comment_view.get_recipient_id() {
match blocking(context.pool(), move |conn| {
Comment::update_read(conn, comment_id, true)
})
.await?
{
Ok(comment) => comment,
Err(_e) => return Err(APIError::err("couldnt_update_comment").into()),
};
comment_view.comment.read = true;
}
let mut res = CommentResponse {
comment_view,
recipient_ids,

View File

@ -1,4 +1,4 @@
use diesel::{result::Error, *};
use diesel::{pg::Pg, result::Error, *};
use lemmy_db_queries::{limit_and_offset, MaybeOptional, ToSafe, ViewToVec};
use lemmy_db_schema::{
schema::{private_message, user_, user_alias_1},
@ -7,6 +7,7 @@ use lemmy_db_schema::{
user::{UserAlias1, UserSafe, UserSafeAlias1, User_},
},
};
use log::debug;
use serde::Serialize;
#[derive(Debug, PartialEq, Serialize, Clone)]
@ -102,12 +103,18 @@ impl<'a> PrivateMessageQueryBuilder<'a> {
let (limit, offset) = limit_and_offset(self.page, self.limit);
let res = query
query = query
.filter(private_message::deleted.eq(false))
.limit(limit)
.offset(offset)
.order_by(private_message::published.desc())
.load::<PrivateMessageViewTuple>(self.conn)?;
.order_by(private_message::published.desc());
debug!(
"Private Message View Query: {:?}",
debug_query::<Pg, _>(&query)
);
let res = query.load::<PrivateMessageViewTuple>(self.conn)?;
Ok(PrivateMessageView::from_tuple_to_vec(res))
}