mirror of
https://github.com/LemmyNet/lemmy.git
synced 2024-11-29 21:01:03 +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?;
|
.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 {
|
if let Some(parent) = parent_opt {
|
||||||
|
let person_id = local_user_view.person.id;
|
||||||
let parent_id = parent.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 {
|
if let Ok(reply) = comment_reply {
|
||||||
CommentReply::update(
|
CommentReply::update(
|
||||||
&mut context.pool(),
|
&mut context.pool(),
|
||||||
|
@ -179,7 +184,6 @@ pub async fn create_comment(
|
||||||
}
|
}
|
||||||
|
|
||||||
// If the parent has PersonMentions mark them as read too
|
// If the parent has PersonMentions mark them as read too
|
||||||
let person_id = local_user_view.person.id;
|
|
||||||
let person_mention =
|
let person_mention =
|
||||||
PersonMention::read_by_comment_and_person(&mut context.pool(), parent_id, person_id).await;
|
PersonMention::read_by_comment_and_person(&mut context.pool(), parent_id, person_id).await;
|
||||||
if let Ok(mention) = person_mention {
|
if let Ok(mention) = person_mention {
|
||||||
|
|
|
@ -1,6 +1,6 @@
|
||||||
use crate::{
|
use crate::{
|
||||||
newtypes::{CommentId, CommentReplyId, PersonId},
|
newtypes::{CommentId, CommentReplyId, PersonId},
|
||||||
schema::comment_reply::dsl::{comment_id, comment_reply, read, recipient_id},
|
schema::comment_reply,
|
||||||
source::comment_reply::{CommentReply, CommentReplyInsertForm, CommentReplyUpdateForm},
|
source::comment_reply::{CommentReply, CommentReplyInsertForm, CommentReplyUpdateForm},
|
||||||
traits::Crud,
|
traits::Crud,
|
||||||
utils::{get_conn, DbPool},
|
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
|
// since the return here isnt utilized, we dont need to do an update
|
||||||
// but get_result doesnt return the existing row here
|
// but get_result doesnt return the existing row here
|
||||||
insert_into(comment_reply)
|
insert_into(comment_reply::table)
|
||||||
.values(comment_reply_form)
|
.values(comment_reply_form)
|
||||||
.on_conflict((recipient_id, comment_id))
|
.on_conflict((comment_reply::recipient_id, comment_reply::comment_id))
|
||||||
.do_update()
|
.do_update()
|
||||||
.set(comment_reply_form)
|
.set(comment_reply_form)
|
||||||
.get_result::<Self>(conn)
|
.get_result::<Self>(conn)
|
||||||
|
@ -37,7 +37,7 @@ impl Crud for CommentReply {
|
||||||
comment_reply_form: &Self::UpdateForm,
|
comment_reply_form: &Self::UpdateForm,
|
||||||
) -> Result<Self, Error> {
|
) -> Result<Self, Error> {
|
||||||
let conn = &mut get_conn(pool).await?;
|
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)
|
.set(comment_reply_form)
|
||||||
.get_result::<Self>(conn)
|
.get_result::<Self>(conn)
|
||||||
.await
|
.await
|
||||||
|
@ -51,11 +51,11 @@ impl CommentReply {
|
||||||
) -> Result<Vec<CommentReply>, Error> {
|
) -> Result<Vec<CommentReply>, Error> {
|
||||||
let conn = &mut get_conn(pool).await?;
|
let conn = &mut get_conn(pool).await?;
|
||||||
diesel::update(
|
diesel::update(
|
||||||
comment_reply
|
comment_reply::table
|
||||||
.filter(recipient_id.eq(for_recipient_id))
|
.filter(comment_reply::recipient_id.eq(for_recipient_id))
|
||||||
.filter(read.eq(false)),
|
.filter(comment_reply::read.eq(false)),
|
||||||
)
|
)
|
||||||
.set(read.eq(true))
|
.set(comment_reply::read.eq(true))
|
||||||
.get_results::<Self>(conn)
|
.get_results::<Self>(conn)
|
||||||
.await
|
.await
|
||||||
}
|
}
|
||||||
|
@ -65,8 +65,21 @@ impl CommentReply {
|
||||||
for_comment_id: CommentId,
|
for_comment_id: CommentId,
|
||||||
) -> Result<Self, Error> {
|
) -> Result<Self, Error> {
|
||||||
let conn = &mut get_conn(pool).await?;
|
let conn = &mut get_conn(pool).await?;
|
||||||
comment_reply
|
comment_reply::table
|
||||||
.filter(comment_id.eq(for_comment_id))
|
.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)
|
.first::<Self>(conn)
|
||||||
.await
|
.await
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,6 +1,6 @@
|
||||||
use crate::{
|
use crate::{
|
||||||
newtypes::{CommentId, PersonId, PersonMentionId},
|
newtypes::{CommentId, PersonId, PersonMentionId},
|
||||||
schema::person_mention::dsl::{comment_id, person_mention, read, recipient_id},
|
schema::person_mention,
|
||||||
source::person_mention::{PersonMention, PersonMentionInsertForm, PersonMentionUpdateForm},
|
source::person_mention::{PersonMention, PersonMentionInsertForm, PersonMentionUpdateForm},
|
||||||
traits::Crud,
|
traits::Crud,
|
||||||
utils::{get_conn, DbPool},
|
utils::{get_conn, DbPool},
|
||||||
|
@ -21,9 +21,9 @@ impl Crud for PersonMention {
|
||||||
let conn = &mut get_conn(pool).await?;
|
let conn = &mut get_conn(pool).await?;
|
||||||
// since the return here isnt utilized, we dont need to do an update
|
// since the return here isnt utilized, we dont need to do an update
|
||||||
// but get_result doesnt return the existing row here
|
// but get_result doesnt return the existing row here
|
||||||
insert_into(person_mention)
|
insert_into(person_mention::table)
|
||||||
.values(person_mention_form)
|
.values(person_mention_form)
|
||||||
.on_conflict((recipient_id, comment_id))
|
.on_conflict((person_mention::recipient_id, person_mention::comment_id))
|
||||||
.do_update()
|
.do_update()
|
||||||
.set(person_mention_form)
|
.set(person_mention_form)
|
||||||
.get_result::<Self>(conn)
|
.get_result::<Self>(conn)
|
||||||
|
@ -36,7 +36,7 @@ impl Crud for PersonMention {
|
||||||
person_mention_form: &Self::UpdateForm,
|
person_mention_form: &Self::UpdateForm,
|
||||||
) -> Result<Self, Error> {
|
) -> Result<Self, Error> {
|
||||||
let conn = &mut get_conn(pool).await?;
|
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)
|
.set(person_mention_form)
|
||||||
.get_result::<Self>(conn)
|
.get_result::<Self>(conn)
|
||||||
.await
|
.await
|
||||||
|
@ -50,11 +50,11 @@ impl PersonMention {
|
||||||
) -> Result<Vec<PersonMention>, Error> {
|
) -> Result<Vec<PersonMention>, Error> {
|
||||||
let conn = &mut get_conn(pool).await?;
|
let conn = &mut get_conn(pool).await?;
|
||||||
diesel::update(
|
diesel::update(
|
||||||
person_mention
|
person_mention::table
|
||||||
.filter(recipient_id.eq(for_recipient_id))
|
.filter(person_mention::recipient_id.eq(for_recipient_id))
|
||||||
.filter(read.eq(false)),
|
.filter(person_mention::read.eq(false)),
|
||||||
)
|
)
|
||||||
.set(read.eq(true))
|
.set(person_mention::read.eq(true))
|
||||||
.get_results::<Self>(conn)
|
.get_results::<Self>(conn)
|
||||||
.await
|
.await
|
||||||
}
|
}
|
||||||
|
@ -65,9 +65,9 @@ impl PersonMention {
|
||||||
for_recipient_id: PersonId,
|
for_recipient_id: PersonId,
|
||||||
) -> Result<Self, Error> {
|
) -> Result<Self, Error> {
|
||||||
let conn = &mut get_conn(pool).await?;
|
let conn = &mut get_conn(pool).await?;
|
||||||
person_mention
|
person_mention::table
|
||||||
.filter(comment_id.eq(for_comment_id))
|
.filter(person_mention::comment_id.eq(for_comment_id))
|
||||||
.filter(recipient_id.eq(for_recipient_id))
|
.filter(person_mention::recipient_id.eq(for_recipient_id))
|
||||||
.first::<Self>(conn)
|
.first::<Self>(conn)
|
||||||
.await
|
.await
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue