|
|
|
@ -27,6 +27,7 @@ use lemmy_db_views_actor::structs::CommunityView;
|
|
|
|
|
use lemmy_utils::{
|
|
|
|
|
error::LemmyResult,
|
|
|
|
|
utils::{markdown::markdown_to_html, mention::MentionData},
|
|
|
|
|
LemmyErrorType,
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
pub async fn build_comment_response(
|
|
|
|
@ -36,7 +37,9 @@ pub async fn build_comment_response(
|
|
|
|
|
recipient_ids: Vec<LocalUserId>,
|
|
|
|
|
) -> LemmyResult<CommentResponse> {
|
|
|
|
|
let person_id = local_user_view.map(|l| l.person.id);
|
|
|
|
|
let comment_view = CommentView::read(&mut context.pool(), comment_id, person_id).await?;
|
|
|
|
|
let comment_view = CommentView::read(&mut context.pool(), comment_id, person_id)
|
|
|
|
|
.await?
|
|
|
|
|
.ok_or(LemmyErrorType::CouldntFindComment)?;
|
|
|
|
|
Ok(CommentResponse {
|
|
|
|
|
comment_view,
|
|
|
|
|
recipient_ids,
|
|
|
|
@ -58,7 +61,8 @@ pub async fn build_community_response(
|
|
|
|
|
Some(person_id),
|
|
|
|
|
is_mod_or_admin,
|
|
|
|
|
)
|
|
|
|
|
.await?;
|
|
|
|
|
.await?
|
|
|
|
|
.ok_or(LemmyErrorType::CouldntFindCommunity)?;
|
|
|
|
|
let discussion_languages = CommunityLanguage::read(&mut context.pool(), community_id).await?;
|
|
|
|
|
|
|
|
|
|
Ok(Json(CommunityResponse {
|
|
|
|
@ -82,7 +86,8 @@ pub async fn build_post_response(
|
|
|
|
|
Some(person.id),
|
|
|
|
|
is_mod_or_admin,
|
|
|
|
|
)
|
|
|
|
|
.await?;
|
|
|
|
|
.await?
|
|
|
|
|
.ok_or(LemmyErrorType::CouldntFindPost)?;
|
|
|
|
|
Ok(Json(PostResponse { post_view }))
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
@ -99,7 +104,9 @@ pub async fn send_local_notifs(
|
|
|
|
|
let inbox_link = format!("{}/inbox", context.settings().get_protocol_and_hostname());
|
|
|
|
|
|
|
|
|
|
// Read the comment view to get extra info
|
|
|
|
|
let comment_view = CommentView::read(&mut context.pool(), comment_id, None).await?;
|
|
|
|
|
let comment_view = CommentView::read(&mut context.pool(), comment_id, None)
|
|
|
|
|
.await?
|
|
|
|
|
.ok_or(LemmyErrorType::CouldntFindComment)?;
|
|
|
|
|
let comment = comment_view.comment;
|
|
|
|
|
let post = comment_view.post;
|
|
|
|
|
let community = comment_view.community;
|
|
|
|
@ -111,7 +118,7 @@ pub async fn send_local_notifs(
|
|
|
|
|
{
|
|
|
|
|
let mention_name = mention.name.clone();
|
|
|
|
|
let user_view = LocalUserView::read_from_name(&mut context.pool(), &mention_name).await;
|
|
|
|
|
if let Ok(mention_user_view) = user_view {
|
|
|
|
|
if let Ok(Some(mention_user_view)) = user_view {
|
|
|
|
|
// TODO
|
|
|
|
|
// At some point, make it so you can't tag the parent creator either
|
|
|
|
|
// Potential duplication of notifications, one for reply and the other for mention, is handled below by checking recipient ids
|
|
|
|
@ -146,7 +153,9 @@ pub async fn send_local_notifs(
|
|
|
|
|
|
|
|
|
|
// Send comment_reply to the parent commenter / poster
|
|
|
|
|
if let Some(parent_comment_id) = comment.parent_comment_id() {
|
|
|
|
|
let parent_comment = Comment::read(&mut context.pool(), parent_comment_id).await?;
|
|
|
|
|
let parent_comment = Comment::read(&mut context.pool(), parent_comment_id)
|
|
|
|
|
.await?
|
|
|
|
|
.ok_or(LemmyErrorType::CouldntFindComment)?;
|
|
|
|
|
|
|
|
|
|
// Get the parent commenter local_user
|
|
|
|
|
let parent_creator_id = parent_comment.creator_id;
|
|
|
|
@ -165,7 +174,7 @@ pub async fn send_local_notifs(
|
|
|
|
|
// Don't send a notif to yourself
|
|
|
|
|
if parent_comment.creator_id != person.id && !check_blocks {
|
|
|
|
|
let user_view = LocalUserView::read_person(&mut context.pool(), parent_creator_id).await;
|
|
|
|
|
if let Ok(parent_user_view) = user_view {
|
|
|
|
|
if let Ok(Some(parent_user_view)) = user_view {
|
|
|
|
|
// Don't duplicate notif if already mentioned by checking recipient ids
|
|
|
|
|
if !recipient_ids.contains(&parent_user_view.local_user.id) {
|
|
|
|
|
recipient_ids.push(parent_user_view.local_user.id);
|
|
|
|
@ -212,7 +221,7 @@ pub async fn send_local_notifs(
|
|
|
|
|
if post.creator_id != person.id && !check_blocks {
|
|
|
|
|
let creator_id = post.creator_id;
|
|
|
|
|
let parent_user = LocalUserView::read_person(&mut context.pool(), creator_id).await;
|
|
|
|
|
if let Ok(parent_user_view) = parent_user {
|
|
|
|
|
if let Ok(Some(parent_user_view)) = parent_user {
|
|
|
|
|
if !recipient_ids.contains(&parent_user_view.local_user.id) {
|
|
|
|
|
recipient_ids.push(parent_user_view.local_user.id);
|
|
|
|
|
|
|
|
|
|