Fix unnecessarily duplicated notifs (#4578)

* add check to remove duplicated notifs

* added comments
This commit is contained in:
tracyspacy 2024-03-29 22:09:19 +01:00 committed by GitHub
parent 067332553d
commit 60f9a97dfa
No known key found for this signature in database
GPG key ID: B5690EEEBB952194

View file

@ -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,6 +163,8 @@ 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 {
// 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); recipient_ids.push(parent_user_view.local_user.id);
let comment_reply_form = CommentReplyInsertForm { let comment_reply_form = CommentReplyInsertForm {
@ -190,6 +192,7 @@ pub async fn send_local_notifs(
} }
} }
} }
}
} else { } else {
let check_blocks = check_person_instance_community_block( let check_blocks = check_person_instance_community_block(
person.id, person.id,
@ -205,6 +208,7 @@ 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 {
if !recipient_ids.contains(&parent_user_view.local_user.id) {
recipient_ids.push(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 {
@ -233,6 +237,7 @@ pub async fn send_local_notifs(
} }
} }
} }
}
Ok(recipient_ids) Ok(recipient_ids)
} }