mirror of
https://github.com/LemmyNet/lemmy.git
synced 2024-11-26 03:11:08 +00:00
Fixing issue with comment replies wrongly marked as read. (#4567)
* Fixing issue with comment replies wrongly marked as read. - Fixes #4566 * Elaborating on a comment.
This commit is contained in:
parent
95069d7648
commit
7929e77602
3 changed files with 41 additions and 24 deletions
|
@ -164,10 +164,15 @@ pub async fn create_comment(
|
|||
)
|
||||
.await?;
|
||||
|
||||
// If its a reply, mark the parent as read
|
||||
// If we're responding to a comment where we're the recipient,
|
||||
// (ie we're the grandparent, or the recipient of the parent comment_reply),
|
||||
// then mark the parent as read.
|
||||
// Then we don't have to do it manually after we respond to a comment.
|
||||
if let Some(parent) = parent_opt {
|
||||
let person_id = local_user_view.person.id;
|
||||
let parent_id = parent.id;
|
||||
let comment_reply = CommentReply::read_by_comment(&mut context.pool(), parent_id).await;
|
||||
let comment_reply =
|
||||
CommentReply::read_by_comment_and_person(&mut context.pool(), parent_id, person_id).await;
|
||||
if let Ok(reply) = comment_reply {
|
||||
CommentReply::update(
|
||||
&mut context.pool(),
|
||||
|
@ -179,7 +184,6 @@ pub async fn create_comment(
|
|||
}
|
||||
|
||||
// If the parent has PersonMentions mark them as read too
|
||||
let person_id = local_user_view.person.id;
|
||||
let person_mention =
|
||||
PersonMention::read_by_comment_and_person(&mut context.pool(), parent_id, person_id).await;
|
||||
if let Ok(mention) = person_mention {
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
use crate::{
|
||||
newtypes::{CommentId, CommentReplyId, PersonId},
|
||||
schema::comment_reply::dsl::{comment_id, comment_reply, read, recipient_id},
|
||||
schema::comment_reply,
|
||||
source::comment_reply::{CommentReply, CommentReplyInsertForm, CommentReplyUpdateForm},
|
||||
traits::Crud,
|
||||
utils::{get_conn, DbPool},
|
||||
|
@ -22,9 +22,9 @@ impl Crud for CommentReply {
|
|||
|
||||
// since the return here isnt utilized, we dont need to do an update
|
||||
// but get_result doesnt return the existing row here
|
||||
insert_into(comment_reply)
|
||||
insert_into(comment_reply::table)
|
||||
.values(comment_reply_form)
|
||||
.on_conflict((recipient_id, comment_id))
|
||||
.on_conflict((comment_reply::recipient_id, comment_reply::comment_id))
|
||||
.do_update()
|
||||
.set(comment_reply_form)
|
||||
.get_result::<Self>(conn)
|
||||
|
@ -37,7 +37,7 @@ impl Crud for CommentReply {
|
|||
comment_reply_form: &Self::UpdateForm,
|
||||
) -> Result<Self, Error> {
|
||||
let conn = &mut get_conn(pool).await?;
|
||||
diesel::update(comment_reply.find(comment_reply_id))
|
||||
diesel::update(comment_reply::table.find(comment_reply_id))
|
||||
.set(comment_reply_form)
|
||||
.get_result::<Self>(conn)
|
||||
.await
|
||||
|
@ -51,11 +51,11 @@ impl CommentReply {
|
|||
) -> Result<Vec<CommentReply>, Error> {
|
||||
let conn = &mut get_conn(pool).await?;
|
||||
diesel::update(
|
||||
comment_reply
|
||||
.filter(recipient_id.eq(for_recipient_id))
|
||||
.filter(read.eq(false)),
|
||||
comment_reply::table
|
||||
.filter(comment_reply::recipient_id.eq(for_recipient_id))
|
||||
.filter(comment_reply::read.eq(false)),
|
||||
)
|
||||
.set(read.eq(true))
|
||||
.set(comment_reply::read.eq(true))
|
||||
.get_results::<Self>(conn)
|
||||
.await
|
||||
}
|
||||
|
@ -65,8 +65,21 @@ impl CommentReply {
|
|||
for_comment_id: CommentId,
|
||||
) -> Result<Self, Error> {
|
||||
let conn = &mut get_conn(pool).await?;
|
||||
comment_reply
|
||||
.filter(comment_id.eq(for_comment_id))
|
||||
comment_reply::table
|
||||
.filter(comment_reply::comment_id.eq(for_comment_id))
|
||||
.first::<Self>(conn)
|
||||
.await
|
||||
}
|
||||
|
||||
pub async fn read_by_comment_and_person(
|
||||
pool: &mut DbPool<'_>,
|
||||
for_comment_id: CommentId,
|
||||
for_recipient_id: PersonId,
|
||||
) -> Result<Self, Error> {
|
||||
let conn = &mut get_conn(pool).await?;
|
||||
comment_reply::table
|
||||
.filter(comment_reply::comment_id.eq(for_comment_id))
|
||||
.filter(comment_reply::recipient_id.eq(for_recipient_id))
|
||||
.first::<Self>(conn)
|
||||
.await
|
||||
}
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
use crate::{
|
||||
newtypes::{CommentId, PersonId, PersonMentionId},
|
||||
schema::person_mention::dsl::{comment_id, person_mention, read, recipient_id},
|
||||
schema::person_mention,
|
||||
source::person_mention::{PersonMention, PersonMentionInsertForm, PersonMentionUpdateForm},
|
||||
traits::Crud,
|
||||
utils::{get_conn, DbPool},
|
||||
|
@ -21,9 +21,9 @@ impl Crud for PersonMention {
|
|||
let conn = &mut get_conn(pool).await?;
|
||||
// since the return here isnt utilized, we dont need to do an update
|
||||
// but get_result doesnt return the existing row here
|
||||
insert_into(person_mention)
|
||||
insert_into(person_mention::table)
|
||||
.values(person_mention_form)
|
||||
.on_conflict((recipient_id, comment_id))
|
||||
.on_conflict((person_mention::recipient_id, person_mention::comment_id))
|
||||
.do_update()
|
||||
.set(person_mention_form)
|
||||
.get_result::<Self>(conn)
|
||||
|
@ -36,7 +36,7 @@ impl Crud for PersonMention {
|
|||
person_mention_form: &Self::UpdateForm,
|
||||
) -> Result<Self, Error> {
|
||||
let conn = &mut get_conn(pool).await?;
|
||||
diesel::update(person_mention.find(person_mention_id))
|
||||
diesel::update(person_mention::table.find(person_mention_id))
|
||||
.set(person_mention_form)
|
||||
.get_result::<Self>(conn)
|
||||
.await
|
||||
|
@ -50,11 +50,11 @@ impl PersonMention {
|
|||
) -> Result<Vec<PersonMention>, Error> {
|
||||
let conn = &mut get_conn(pool).await?;
|
||||
diesel::update(
|
||||
person_mention
|
||||
.filter(recipient_id.eq(for_recipient_id))
|
||||
.filter(read.eq(false)),
|
||||
person_mention::table
|
||||
.filter(person_mention::recipient_id.eq(for_recipient_id))
|
||||
.filter(person_mention::read.eq(false)),
|
||||
)
|
||||
.set(read.eq(true))
|
||||
.set(person_mention::read.eq(true))
|
||||
.get_results::<Self>(conn)
|
||||
.await
|
||||
}
|
||||
|
@ -65,9 +65,9 @@ impl PersonMention {
|
|||
for_recipient_id: PersonId,
|
||||
) -> Result<Self, Error> {
|
||||
let conn = &mut get_conn(pool).await?;
|
||||
person_mention
|
||||
.filter(comment_id.eq(for_comment_id))
|
||||
.filter(recipient_id.eq(for_recipient_id))
|
||||
person_mention::table
|
||||
.filter(person_mention::comment_id.eq(for_comment_id))
|
||||
.filter(person_mention::recipient_id.eq(for_recipient_id))
|
||||
.first::<Self>(conn)
|
||||
.await
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue