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(),
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| {
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,
-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},
user::{UserAlias1, UserSafe, UserSafeAlias1, User_},
},
};
+use log::debug;
use serde::Serialize;
#[derive(Debug, PartialEq, Serialize, Clone)]
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))
}