Fix unnecessarily duplicated notifs (#4578)
* add check to remove duplicated notifs * added comments
This commit is contained in:
parent
067332553d
commit
60f9a97dfa
1 changed files with 48 additions and 43 deletions
|
@ -112,7 +112,7 @@ pub async fn send_local_notifs(
|
||||||
if let Ok(mention_user_view) = user_view {
|
if let Ok(mention_user_view) = user_view {
|
||||||
// TODO
|
// TODO
|
||||||
// At some point, make it so you can't tag the parent creator either
|
// At some point, make it so you can't tag the parent creator either
|
||||||
// This can cause two notifications, one for reply and the other for mention
|
// Potential duplication of notifications, one for reply and the other for mention, is handled below by checking recipient ids
|
||||||
recipient_ids.push(mention_user_view.local_user.id);
|
recipient_ids.push(mention_user_view.local_user.id);
|
||||||
|
|
||||||
let user_mention_form = PersonMentionInsertForm {
|
let user_mention_form = PersonMentionInsertForm {
|
||||||
|
@ -163,30 +163,33 @@ pub async fn send_local_notifs(
|
||||||
if parent_comment.creator_id != person.id && !check_blocks {
|
if parent_comment.creator_id != person.id && !check_blocks {
|
||||||
let user_view = LocalUserView::read_person(&mut context.pool(), parent_creator_id).await;
|
let user_view = LocalUserView::read_person(&mut context.pool(), parent_creator_id).await;
|
||||||
if let Ok(parent_user_view) = user_view {
|
if let Ok(parent_user_view) = user_view {
|
||||||
recipient_ids.push(parent_user_view.local_user.id);
|
// 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);
|
||||||
|
|
||||||
let comment_reply_form = CommentReplyInsertForm {
|
let comment_reply_form = CommentReplyInsertForm {
|
||||||
recipient_id: parent_user_view.person.id,
|
recipient_id: parent_user_view.person.id,
|
||||||
comment_id: comment.id,
|
comment_id: comment.id,
|
||||||
read: None,
|
read: None,
|
||||||
};
|
};
|
||||||
|
|
||||||
// Allow this to fail softly, since comment edits might re-update or replace it
|
// Allow this to fail softly, since comment edits might re-update or replace it
|
||||||
// Let the uniqueness handle this fail
|
// Let the uniqueness handle this fail
|
||||||
CommentReply::create(&mut context.pool(), &comment_reply_form)
|
CommentReply::create(&mut context.pool(), &comment_reply_form)
|
||||||
.await
|
.await
|
||||||
.ok();
|
.ok();
|
||||||
|
|
||||||
if do_send_email {
|
if do_send_email {
|
||||||
let lang = get_interface_language(&parent_user_view);
|
let lang = get_interface_language(&parent_user_view);
|
||||||
let content = markdown_to_html(&comment.content);
|
let content = markdown_to_html(&comment.content);
|
||||||
send_email_to_user(
|
send_email_to_user(
|
||||||
&parent_user_view,
|
&parent_user_view,
|
||||||
&lang.notification_comment_reply_subject(&person.name),
|
&lang.notification_comment_reply_subject(&person.name),
|
||||||
&lang.notification_comment_reply_body(&content, &inbox_link, &person.name),
|
&lang.notification_comment_reply_body(&content, &inbox_link, &person.name),
|
||||||
context.settings(),
|
context.settings(),
|
||||||
)
|
)
|
||||||
.await
|
.await
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -205,30 +208,32 @@ pub async fn send_local_notifs(
|
||||||
let creator_id = post.creator_id;
|
let creator_id = post.creator_id;
|
||||||
let parent_user = LocalUserView::read_person(&mut context.pool(), creator_id).await;
|
let parent_user = LocalUserView::read_person(&mut context.pool(), creator_id).await;
|
||||||
if let Ok(parent_user_view) = parent_user {
|
if let Ok(parent_user_view) = parent_user {
|
||||||
recipient_ids.push(parent_user_view.local_user.id);
|
if !recipient_ids.contains(&parent_user_view.local_user.id) {
|
||||||
|
recipient_ids.push(parent_user_view.local_user.id);
|
||||||
|
|
||||||
let comment_reply_form = CommentReplyInsertForm {
|
let comment_reply_form = CommentReplyInsertForm {
|
||||||
recipient_id: parent_user_view.person.id,
|
recipient_id: parent_user_view.person.id,
|
||||||
comment_id: comment.id,
|
comment_id: comment.id,
|
||||||
read: None,
|
read: None,
|
||||||
};
|
};
|
||||||
|
|
||||||
// Allow this to fail softly, since comment edits might re-update or replace it
|
// Allow this to fail softly, since comment edits might re-update or replace it
|
||||||
// Let the uniqueness handle this fail
|
// Let the uniqueness handle this fail
|
||||||
CommentReply::create(&mut context.pool(), &comment_reply_form)
|
CommentReply::create(&mut context.pool(), &comment_reply_form)
|
||||||
.await
|
.await
|
||||||
.ok();
|
.ok();
|
||||||
|
|
||||||
if do_send_email {
|
if do_send_email {
|
||||||
let lang = get_interface_language(&parent_user_view);
|
let lang = get_interface_language(&parent_user_view);
|
||||||
let content = markdown_to_html(&comment.content);
|
let content = markdown_to_html(&comment.content);
|
||||||
send_email_to_user(
|
send_email_to_user(
|
||||||
&parent_user_view,
|
&parent_user_view,
|
||||||
&lang.notification_post_reply_subject(&person.name),
|
&lang.notification_post_reply_subject(&person.name),
|
||||||
&lang.notification_post_reply_body(&content, &inbox_link, &person.name),
|
&lang.notification_post_reply_body(&content, &inbox_link, &person.name),
|
||||||
context.settings(),
|
context.settings(),
|
||||||
)
|
)
|
||||||
.await
|
.await
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue