[COMPONENT][Notification] ->getSubscribers() should not be pre-included

Notification bug fix on Subscription component
Correct docblock
This commit is contained in:
2022-03-28 20:52:12 +01:00
parent ba4230447e
commit 16f51e5143
6 changed files with 46 additions and 23 deletions

View File

@@ -65,25 +65,21 @@ class Notification extends Component
* Enqueues a notification for an Actor (such as person or group) which means
* it shows up in their home feed and such.
* WARNING: It's highly advisable to have flushed any relevant objects before triggering this event.
* OBSERVATION: $sender->getSubscribers() will always be pre-included, thus why $targets=[] is normal
*
* $targets should be of the shape:
* ['source' => (int|Actor)[]] // Prefer Actor whenever possible
* (int|Actor)[] // Prefer Actor whenever possible
* Example of $targets:
* [[42, $actor_alice, $actor_bob]] // Avoid repeating actors or ids
* [42, $actor_alice, $actor_bob] // Avoid repeating actors or ids
*
* @param Actor $sender The one responsible for this activity, take care not to include it in targets
* @param Activity $activity The activity responsible for the object being given to known to targets
* @param array $targets attentions, Mentions, any other source
* @param array $targets Attentions, Mentions, any other source. Should never be empty, you usually want to register an attention to every $sender->getSubscribers()
* @param null|string $reason An optional reason explaining why this notification exists
*/
public function onNewNotification(Actor $sender, Activity $activity, array $targets = [], ?string $reason = null): bool
public function onNewNotification(Actor $sender, Activity $activity, array $targets, ?string $reason = null): bool
{
// Ensure targets are all actor objects and unique
$effective_targets = [];
foreach ($sender->getSubscribers() as $subscriber) {
$effective_targets[$subscriber->getId()] = $subscriber;
}
foreach ($targets as $target) {
if (\is_int($target)) {
$target_id = $target;