From 764a30695de64d38f587fbf4c59751f82329e95c Mon Sep 17 00:00:00 2001 From: Hugo Sales Date: Thu, 23 Dec 2021 14:36:12 +0000 Subject: [PATCH] [ENTITY][ActorTag][Actor][Activity] Add Actor::getActorCircles --- src/Entity/Activity.php | 23 +++++++++-------------- src/Entity/Actor.php | 15 ++++++++++++--- src/Entity/ActorCircle.php | 5 +++-- 3 files changed, 24 insertions(+), 19 deletions(-) diff --git a/src/Entity/Activity.php b/src/Entity/Activity.php index 015ce7cea5..6e80d31129 100644 --- a/src/Entity/Activity.php +++ b/src/Entity/Activity.php @@ -1,5 +1,7 @@ getObjectType(), ['id' => $this->getObjectId()]); } - /** - * @return array - */ public function getNotificationTargetIdsFromActorTags(): array { - [$actor_circles, $actor_tags] = $this->getActor()->getSelfTags(); + $actor_circles = $this->getActor()->getActorCircles(); return F\flat_map($actor_circles, fn ($circle) => $circle->getSubscribedActors()); } @@ -163,31 +158,31 @@ class Activity extends Entity $target_ids = []; // Actor Circles - if (array_key_exists('actor_circle', $ids_already_known)) { + if (\array_key_exists('actor_circle', $ids_already_known)) { array_push($target_ids, ...$ids_already_known['actor_circle']); } else { array_push($target_ids, ...$this->getNotificationTargetIdsFromActorTags()); } // Notifications - if (array_key_exists('notification_activity', $ids_already_known)) { + if (\array_key_exists('notification_activity', $ids_already_known)) { array_push($target_ids, ...$ids_already_known['notification_activity']); } else { array_push($target_ids, ...Notification::getNotificationTargetIdsByActivity($this->getId())); } // Object's targets - if (array_key_exists('object', $ids_already_known)) { + if (\array_key_exists('object', $ids_already_known)) { array_push($target_ids, ...$ids_already_known['object']); } else { - if (!is_null($author = $this->getObject()?->getActorId()) && $author !== $sender_id) { + if (!\is_null($author = $this->getObject()?->getActorId()) && $author !== $sender_id) { $target_ids[] = $this->getObject()->getActorId(); } array_push($target_ids, ...$this->getObject()->getNotificationTargetIds($ids_already_known)); } // Additional actors that should know about this - if (array_key_exists('additional', $ids_already_known)) { + if (\array_key_exists('additional', $ids_already_known)) { array_push($target_ids, ...$ids_already_known['additional']); } diff --git a/src/Entity/Actor.php b/src/Entity/Actor.php index 422915100d..fd5f7e49f2 100644 --- a/src/Entity/Actor.php +++ b/src/Entity/Actor.php @@ -258,7 +258,8 @@ class Actor extends Entity 'id' => "actor-id-{$actor_id}", 'nickname' => "actor-nickname-id-{$actor_id}", 'fullname' => "actor-fullname-id-{$actor_id}", - 'tags' => \is_null($other) ? "actor-circles-and-tags-{$actor_id}" : "actor-circles-and-tags-{$actor_id}-by-{$other}", // $other is $context_id + 'tags' => \is_null($other) ? "actor-tags-{$actor_id}" : "actor-tags-{$actor_id}-by-{$other}", // $other is $context_id + 'circles' => "actor-circles-{$actor_id}", 'subscriber' => "subscriber-{$actor_id}", 'subscribed' => "subscribed-{$actor_id}", 'relative-nickname' => "actor-{$actor_id}-relative-nickname-{$other}", // $other is $nickname @@ -362,7 +363,7 @@ class Actor extends Entity public function getOtherTags(self|int|null $context = null, ?int $offset = null, ?int $limit = null, bool $_test_force_recompute = false): array { if (\is_null($context)) { - return Cache::get( + return Cache::getList( self::cacheKeys($this->getId())['tags'], fn () => DB::dql( <<< 'EOQ' @@ -377,7 +378,7 @@ class Actor extends Entity ); } else { $context_id = \is_int($context) ? $context : $context->getId(); - return Cache::get( + return Cache::getList( self::cacheKeys($this->getId(), $context_id)['tags'], fn () => DB::dql( <<< 'EOQ' @@ -393,6 +394,14 @@ class Actor extends Entity } } + public function getActorCircles() + { + return Cache::getList( + self::cacheKeys($this->getId())['circles'], + fn () => DB::findBy('actor_circle', ['tagger' => $this->getId()]), + ); + } + private function getSubCount(string $which, string $column): int { return Cache::get( diff --git a/src/Entity/ActorCircle.php b/src/Entity/ActorCircle.php index f217dc43fd..10fd8d46d4 100644 --- a/src/Entity/ActorCircle.php +++ b/src/Entity/ActorCircle.php @@ -167,9 +167,9 @@ class ActorCircle extends Entity 'name' => 'actor_circle', 'description' => 'a actor can have lists of actors, to separate their feed', 'fields' => [ - 'id' => ['type' => 'serial', 'not null' => true, 'description' => 'unique identifier'], + 'id' => ['type' => 'serial', 'not null' => true, 'description' => 'unique identifier'], // An actor can be tagged by many actors - 'tagger' => ['type' => 'int', 'foreign key' => true, 'target' => 'Actor.id', 'multiplicity' => 'many to one', 'name' => 'actor_list_tagger_fkey', 'not null' => true, 'description' => 'user making the tag'], + 'tagger' => ['type' => 'int', 'foreign key' => true, 'target' => 'Actor.id', 'multiplicity' => 'many to one', 'name' => 'actor_list_tagger_fkey', 'not null' => true, 'description' => 'user making the tag'], // Many Actor Circles can reference (and probably will) an Actor Tag 'tag' => ['type' => 'varchar', 'length' => 64, 'foreign key' => true, 'target' => 'ActorTag.tag', 'multiplicity' => 'many to one', 'not null' => true, 'description' => 'actor tag'], // Join with ActorTag // // so, Doctrine doesn't like that the target is not unique, even though the pair is 'description' => ['type' => 'text', 'description' => 'description of the people tag'], @@ -182,6 +182,7 @@ class ActorCircle extends Entity 'actor_list_modified_idx' => ['modified'], 'actor_list_tag_idx' => ['tag'], 'actor_list_tagger_tag_idx' => ['tagger', 'tag'], + 'actor_list_tagger_idx' => ['tagger'], ], ]; }