Send less useless mention notifications

Users will now receive mention notifs only if they're mentioned outside of their content
This commit is contained in:
celestora 2022-12-11 16:26:12 +02:00
parent 8a893daec0
commit 25be996256
2 changed files with 10 additions and 2 deletions

View file

@ -106,7 +106,11 @@ final class CommentPresenter extends OpenVKPresenter
if(($owner = $entity->getOwner()) instanceof User) if(($owner = $entity->getOwner()) instanceof User)
(new CommentNotification($owner, $comment, $entity, $this->user->identity))->emit(); (new CommentNotification($owner, $comment, $entity, $this->user->identity))->emit();
$mentions = iterator_to_array($comment->resolveMentions([$this->user->identity->getId()])); $excludeMentions = [$this->user->identity->getId()];
if(($owner = $entity->getOwner()) instanceof User)
$excludeMentions[] = $owner->getId();
$mentions = iterator_to_array($comment->resolveMentions($excludeMentions));
foreach($mentions as $mentionee) foreach($mentions as $mentionee)
if($mentionee instanceof User) if($mentionee instanceof User)
(new MentionNotification($mentionee, $entity, $comment->getOwner(), strip_tags($comment->getText())))->emit(); (new MentionNotification($mentionee, $entity, $comment->getOwner(), strip_tags($comment->getText())))->emit();

View file

@ -305,7 +305,11 @@ final class WallPresenter extends OpenVKPresenter
if($wall > 0 && $wall !== $this->user->identity->getId()) if($wall > 0 && $wall !== $this->user->identity->getId())
(new WallPostNotification($wallOwner, $post, $this->user->identity))->emit(); (new WallPostNotification($wallOwner, $post, $this->user->identity))->emit();
$mentions = iterator_to_array($post->resolveMentions([$this->user->identity->getId()])); $excludeMentions = [$this->user->identity->getId()];
if($wall > 0)
$excludeMentions[] = $wall;
$mentions = iterator_to_array($post->resolveMentions($excludeMentions));
foreach($mentions as $mentionee) foreach($mentions as $mentionee)
if($mentionee instanceof User) if($mentionee instanceof User)
(new MentionNotification($mentionee, $post, $post->getOwner(), strip_tags($post->getText())))->emit(); (new MentionNotification($mentionee, $post, $post->getOwner(), strip_tags($post->getText())))->emit();