mirror of
https://github.com/LemmyNet/lemmy.git
synced 2024-12-02 14:16:46 +00:00
mark parent as read on reply (#1819)
* mark parent as read on reply * mark as read only if you are the recipient * mark mentions as read on reply
This commit is contained in:
parent
b96ce81f89
commit
e06cd9c0ac
2 changed files with 50 additions and 3 deletions
|
@ -19,8 +19,12 @@ use lemmy_apub::{
|
||||||
generate_apub_endpoint,
|
generate_apub_endpoint,
|
||||||
EndpointType,
|
EndpointType,
|
||||||
};
|
};
|
||||||
use lemmy_db_queries::{source::comment::Comment_, Crud, Likeable};
|
use lemmy_db_queries::{
|
||||||
use lemmy_db_schema::source::comment::*;
|
source::{comment::Comment_, person_mention::PersonMention_},
|
||||||
|
Crud,
|
||||||
|
Likeable,
|
||||||
|
};
|
||||||
|
use lemmy_db_schema::source::{comment::*, person_mention::PersonMention};
|
||||||
use lemmy_db_views::comment_view::CommentView;
|
use lemmy_db_views::comment_view::CommentView;
|
||||||
use lemmy_utils::{
|
use lemmy_utils::{
|
||||||
utils::{remove_slurs, scrape_text_for_mentions},
|
utils::{remove_slurs, scrape_text_for_mentions},
|
||||||
|
@ -168,6 +172,33 @@ impl PerformCrud for CreateComment {
|
||||||
.await?
|
.await?
|
||||||
.map_err(|_| ApiError::err("couldnt_update_comment"))?;
|
.map_err(|_| ApiError::err("couldnt_update_comment"))?;
|
||||||
}
|
}
|
||||||
|
// If its a reply, mark the parent as read
|
||||||
|
if let Some(parent_id) = data.parent_id {
|
||||||
|
let parent_comment = blocking(context.pool(), move |conn| {
|
||||||
|
CommentView::read(conn, parent_id, Some(person_id))
|
||||||
|
})
|
||||||
|
.await??;
|
||||||
|
if local_user_view.person.id == parent_comment.get_recipient_id() {
|
||||||
|
blocking(context.pool(), move |conn| {
|
||||||
|
Comment::update_read(conn, parent_id, true)
|
||||||
|
})
|
||||||
|
.await?
|
||||||
|
.map_err(|_| ApiError::err("couldnt_update_parent_comment"))?;
|
||||||
|
}
|
||||||
|
// If the parent has PersonMentions mark them as read too
|
||||||
|
let person_id = local_user_view.person.id;
|
||||||
|
let person_mention = blocking(context.pool(), move |conn| {
|
||||||
|
PersonMention::read_by_comment_and_person(conn, parent_id, person_id)
|
||||||
|
})
|
||||||
|
.await?;
|
||||||
|
if let Ok(mention) = person_mention {
|
||||||
|
blocking(context.pool(), move |conn| {
|
||||||
|
PersonMention::update_read(conn, mention.id, true)
|
||||||
|
})
|
||||||
|
.await?
|
||||||
|
.map_err(|_| ApiError::err("couldnt_update_person_mentions"))?;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
send_comment_ws_message(
|
send_comment_ws_message(
|
||||||
inserted_comment.id,
|
inserted_comment.id,
|
||||||
|
|
|
@ -1,6 +1,6 @@
|
||||||
use crate::Crud;
|
use crate::Crud;
|
||||||
use diesel::{dsl::*, result::Error, *};
|
use diesel::{dsl::*, result::Error, *};
|
||||||
use lemmy_db_schema::{source::person_mention::*, PersonId, PersonMentionId};
|
use lemmy_db_schema::{source::person_mention::*, CommentId, PersonId, PersonMentionId};
|
||||||
|
|
||||||
impl Crud for PersonMention {
|
impl Crud for PersonMention {
|
||||||
type Form = PersonMentionForm;
|
type Form = PersonMentionForm;
|
||||||
|
@ -44,6 +44,11 @@ pub trait PersonMention_ {
|
||||||
conn: &PgConnection,
|
conn: &PgConnection,
|
||||||
for_recipient_id: PersonId,
|
for_recipient_id: PersonId,
|
||||||
) -> Result<Vec<PersonMention>, Error>;
|
) -> Result<Vec<PersonMention>, Error>;
|
||||||
|
fn read_by_comment_and_person(
|
||||||
|
conn: &PgConnection,
|
||||||
|
for_comment_id: CommentId,
|
||||||
|
for_recipient_id: PersonId,
|
||||||
|
) -> Result<PersonMention, Error>;
|
||||||
}
|
}
|
||||||
|
|
||||||
impl PersonMention_ for PersonMention {
|
impl PersonMention_ for PersonMention {
|
||||||
|
@ -71,6 +76,17 @@ impl PersonMention_ for PersonMention {
|
||||||
.set(read.eq(true))
|
.set(read.eq(true))
|
||||||
.get_results::<Self>(conn)
|
.get_results::<Self>(conn)
|
||||||
}
|
}
|
||||||
|
fn read_by_comment_and_person(
|
||||||
|
conn: &PgConnection,
|
||||||
|
for_comment_id: CommentId,
|
||||||
|
for_recipient_id: PersonId,
|
||||||
|
) -> Result<Self, Error> {
|
||||||
|
use lemmy_db_schema::schema::person_mention::dsl::*;
|
||||||
|
person_mention
|
||||||
|
.filter(comment_id.eq(for_comment_id))
|
||||||
|
.filter(recipient_id.eq(for_recipient_id))
|
||||||
|
.first::<Self>(conn)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
#[cfg(test)]
|
#[cfg(test)]
|
||||||
|
|
Loading…
Reference in a new issue