[COMPONENT][Notification] Make logic more generic and robust

Fixed various bugs

Some important concepts to bear in mind:

* Notification: Associated with activities, won't be reconstructed
together with objects, can be thought of as transient

* Attention: Associated with objects, will be reconstructed with them, can
be thought as persistent

* Notifications and Attentions have no direct implications.

* Mentions are a specific form of attentions in notes, leads to the creation of Attentions.

Finally,

Potential PHP issue detected and reported: https://github.com/php/php-src/issues/8199
`static::method()` from a non static context (such as a class method) calls `__call`, rather than
the expected `__callStatic`. Can be fixed by using `(static fn() => static::method())()`, but the
usage of the magic method is strictly unnecessary in this case.
This commit is contained in:
2022-03-13 18:23:19 +00:00
parent e1cceac150
commit 888c3798b7
32 changed files with 438 additions and 494 deletions

View File

@@ -101,27 +101,17 @@ class ActivitypubActivity extends Entity
public function getActivity(): Activity
{
return DB::findOneBy('activity', ['id' => $this->getActivityId()]);
return DB::findOneBy(Activity::class, ['id' => $this->getActivityId()]);
}
public array $_object_mention_ids = [];
public function setObjectMentionIds(array $mentions): self
public function getAttentionTargetIds(): array
{
$this->_object_mention_ids = $mentions;
return $this;
return $this->getActivity()->getAttentionTargetIds();
}
/**
* @see Entity->getNotificationTargetIds
*/
public function getNotificationTargetIds(array $ids_already_known = [], ?int $sender_id = null, bool $include_additional = true): array
public function getAttentionTargets(): array
{
// Additional actors that should know about this
if (\array_key_exists('additional', $ids_already_known)) {
return $ids_already_known['additional'];
} else {
return $this->_object_mention_ids;
}
return $this->getActivity()->getAttentionTargets();
}
public static function schemaDef(): array