[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:
@@ -24,11 +24,21 @@ namespace Component\Notification\Entity;
|
||||
use App\Core\Entity;
|
||||
|
||||
/**
|
||||
* Entity for note attentions
|
||||
* Entity for object attentions
|
||||
*
|
||||
* An attention is a form of persistent notification.
|
||||
* It exists together and for as long as the object it belongs to.
|
||||
* Creating an attention requires creating a Notification.
|
||||
*
|
||||
* @category DB
|
||||
* @package GNUsocial
|
||||
*
|
||||
* @author Zach Copley <zach@status.net>
|
||||
* @copyright 2010 StatusNet Inc.
|
||||
* @author Mikael Nordfeldth <mmn@hethane.se>
|
||||
* @copyright 2009-2014 Free Software Foundation, Inc http://www.fsf.org
|
||||
* @author Diogo Peralta Cordeiro <@diogo.site>
|
||||
* @copyright 2021-2022 Free Software Foundation, Inc http://www.fsf.org
|
||||
* @author Diogo Peralta Cordeiro <@diogo.site>
|
||||
* @copyright 2022 Free Software Foundation, Inc http://www.fsf.org
|
||||
* @license https://www.gnu.org/licenses/agpl.html GNU AGPL v3 or later
|
||||
@@ -37,18 +47,30 @@ class Attention extends Entity
|
||||
{
|
||||
// {{{ Autocode
|
||||
// @codeCoverageIgnoreStart
|
||||
private int $note_id;
|
||||
private string $object_type;
|
||||
private int $object_id;
|
||||
private int $target_id;
|
||||
|
||||
public function setNoteId(int $note_id): self
|
||||
public function setObjectType(string $object_type): self
|
||||
{
|
||||
$this->note_id = $note_id;
|
||||
$this->object_type = mb_substr($object_type, 0, 32);
|
||||
return $this;
|
||||
}
|
||||
|
||||
public function getNoteId(): int
|
||||
public function getObjectType(): string
|
||||
{
|
||||
return $this->note_id;
|
||||
return $this->object_type;
|
||||
}
|
||||
|
||||
public function setObjectId(int $object_id): self
|
||||
{
|
||||
$this->object_id = $object_id;
|
||||
return $this;
|
||||
}
|
||||
|
||||
public function getObjectId(): int
|
||||
{
|
||||
return $this->object_id;
|
||||
}
|
||||
|
||||
public function setTargetId(int $target_id): self
|
||||
@@ -68,15 +90,16 @@ class Attention extends Entity
|
||||
public static function schemaDef(): array
|
||||
{
|
||||
return [
|
||||
'name' => 'note_attention',
|
||||
'description' => 'Note attentions to actors (that are not a mention)',
|
||||
'name' => 'attention',
|
||||
'description' => 'Attentions to actors (these are not mentions)',
|
||||
'fields' => [
|
||||
'note_id' => ['type' => 'int', 'foreign key' => true, 'target' => 'Note.id', 'multiplicity' => 'one to one', 'not null' => true, 'description' => 'note_id to give attention'],
|
||||
'target_id' => ['type' => 'int', 'foreign key' => true, 'target' => 'Actor.id', 'multiplicity' => 'one to one', 'not null' => true, 'description' => 'actor_id for feed receiver'],
|
||||
'object_type' => ['type' => 'varchar', 'length' => 32, 'not null' => true, 'description' => 'the name of the table this object refers to'],
|
||||
'object_id' => ['type' => 'int', 'not null' => true, 'description' => 'id in the referenced table'],
|
||||
'target_id' => ['type' => 'int', 'foreign key' => true, 'target' => 'Actor.id', 'multiplicity' => 'one to one', 'not null' => true, 'description' => 'actor_id for feed receiver'],
|
||||
],
|
||||
'primary key' => ['note_id', 'target_id'],
|
||||
'primary key' => ['object_type', 'object_id', 'target_id'],
|
||||
'indexes' => [
|
||||
'attention_note_id_idx' => ['note_id'],
|
||||
'attention_object_id_idx' => ['object_id'],
|
||||
'attention_target_id_idx' => ['target_id'],
|
||||
],
|
||||
];
|
||||
|
@@ -28,17 +28,17 @@ use App\Entity\Actor;
|
||||
use DateTimeInterface;
|
||||
|
||||
/**
|
||||
* Entity for attentions
|
||||
* Entity for Notifications
|
||||
*
|
||||
* A Notification when isolated is a form of transient notification.
|
||||
* When together with a persistent form of notification such as attentions or mentions,
|
||||
* it records that the target was notified - which avoids re-notifying upon objects reconstructions.
|
||||
*
|
||||
* @category DB
|
||||
* @package GNUsocial
|
||||
*
|
||||
* @author Zach Copley <zach@status.net>
|
||||
* @copyright 2010 StatusNet Inc.
|
||||
* @author Mikael Nordfeldth <mmn@hethane.se>
|
||||
* @copyright 2009-2014 Free Software Foundation, Inc http://www.fsf.org
|
||||
* @author Hugo Sales <hugo@hsal.es>
|
||||
* @copyright 2020-2021 Free Software Foundation, Inc http://www.fsf.org
|
||||
* @author Diogo Peralta Cordeiro <@diogo.site>
|
||||
* @copyright 2021-2022 Free Software Foundation, Inc http://www.fsf.org
|
||||
* @license https://www.gnu.org/licenses/agpl.html GNU AGPL v3 or later
|
||||
*/
|
||||
class Notification extends Entity
|
||||
|
Reference in New Issue
Block a user