From 1f1524c2b3a8cf11cb7888445c441cb78dafcac9 Mon Sep 17 00:00:00 2001 From: Diogo Peralta Cordeiro Date: Thu, 10 Feb 2022 04:31:06 +0000 Subject: [PATCH] [GROUP] Simplify logic by making Actor::Organisation a type of Actor::Group Some minor bug fixes --- components/Collection/Collection.php | 3 +- components/Group/Controller/Group.php | 90 ++++++++------ components/Group/Entity/GroupAlias.php | 100 ---------------- components/Group/Entity/GroupBlock.php | 110 ------------------ components/Group/Entity/GroupInbox.php | 103 ---------------- components/Group/Entity/LocalGroup.php | 23 +++- components/Group/Group.php | 13 ++- .../cards/group/create_widget.html.twig | 2 +- components/Notification/Notification.php | 15 +-- plugins/ActivityPub/Util/Model/Actor.php | 9 +- plugins/Directory/Controller/Directory.php | 33 +++--- src/Entity/Actor.php | 7 +- 12 files changed, 106 insertions(+), 402 deletions(-) delete mode 100644 components/Group/Entity/GroupAlias.php delete mode 100644 components/Group/Entity/GroupBlock.php delete mode 100644 components/Group/Entity/GroupInbox.php diff --git a/components/Collection/Collection.php b/components/Collection/Collection.php index d58cc3c60a..17485a182a 100644 --- a/components/Collection/Collection.php +++ b/components/Collection/Collection.php @@ -127,8 +127,7 @@ class Collection extends Component foreach ( [ Actor::PERSON => ['person', 'people'], - Actor::GROUP => ['group', 'groups'], - Actor::ORGANISATION => ['org', 'orgs', 'organization', 'organizations', 'organisation', 'organisations'], + Actor::GROUP => ['group', 'groups', 'org', 'orgs', 'organisation', 'organisations', 'organization', 'organizations'], Actor::BOT => ['bot', 'bots'], ] as $type => $match) { if (array_intersect(explode(',', $term[1]), $match) !== []) { diff --git a/components/Group/Controller/Group.php b/components/Group/Controller/Group.php index 0452295ed5..a9c5552fc9 100644 --- a/components/Group/Controller/Group.php +++ b/components/Group/Controller/Group.php @@ -29,15 +29,18 @@ use App\Core\DB\DB; use App\Core\Form; use function App\Core\I18n\_m; use App\Core\Log; +use App\Entity\Actor; use App\Entity as E; use App\Util\Common; use App\Util\Exception\ClientException; +use App\Util\Exception\DuplicateFoundException; use App\Util\Exception\NicknameEmptyException; +use App\Util\Exception\NicknameException; use App\Util\Exception\NicknameInvalidException; use App\Util\Exception\NicknameNotAllowedException; use App\Util\Exception\NicknameTakenException; use App\Util\Exception\NicknameTooLongException; -use App\Util\Exception\NoLoggedInUser; +use App\Util\Exception\NotFoundException; use App\Util\Exception\RedirectException; use App\Util\Exception\ServerException; use App\Util\Form\ActorForms; @@ -46,6 +49,7 @@ use Component\Collection\Util\Controller\FeedController; use Component\Group\Entity\GroupMember; use Component\Group\Entity\LocalGroup; use Component\Subscription\Entity\ActorSubscription; +use Symfony\Component\Form\Extension\Core\Type\ChoiceType; use Symfony\Component\Form\Extension\Core\Type\SubmitType; use Symfony\Component\Form\Extension\Core\Type\TextType; use Symfony\Component\Form\FormInterface; @@ -54,27 +58,14 @@ use Symfony\Component\HttpFoundation\Request; class Group extends FeedController { /** - * View a group feed by its nickname - * - * @param string $nickname The group's nickname to be shown - * - * @throws NicknameEmptyException - * @throws NicknameNotAllowedException - * @throws NicknameTakenException - * @throws NicknameTooLongException * @throws ServerException - * - * @return array */ - public function groupViewNickname(Request $request, string $nickname) + public function handleGroup(Request $request, Actor $group): array { - Nickname::validate($nickname, which: Nickname::CHECK_LOCAL_GROUP); // throws - $group = LocalGroup::getActorByNickname($nickname); $actor = Common::actor(); $subscribe_form = null; - if (!\is_null($group) - && !\is_null($actor) + if (!\is_null($actor) && \is_null(Cache::get( ActorSubscription::cacheKeys($actor, $group)['subscribed'], fn () => DB::findOneBy('actor_subscription', [ @@ -97,35 +88,57 @@ class Group extends FeedController } } - $notes = !\is_null($group) ? DB::dql( - <<<'EOF' - select n from note n - join activity a with n.id = a.object_id - join group_inbox gi with a.id = gi.activity_id - where a.object_type = 'note' and gi.group_id = :group_id - order by a.created desc, a.id desc - EOF, - ['group_id' => $group->getId()], - ) : []; + $notes = DB::dql(<<<'EOF' + SELECT n FROM \App\Entity\Note AS n + WHERE n.id IN ( + SELECT act.object_id FROM \App\Entity\Activity AS act + WHERE act.object_type = 'note' AND act.id IN + (SELECT att.activity_id FROM \Component\Notification\Entity\Notification AS att WHERE att.target_id = :id) + ) + EOF, ['id' => $group->getId()]); return [ '_template' => 'group/view.html.twig', 'actor' => $group, - 'nickname' => $group?->getNickname() ?? $nickname, + 'nickname' => $group->getNickname(), 'notes' => $notes, 'subscribe_form' => $subscribe_form?->createView(), ]; } + public function groupViewId(Request $request, int $id): array + { + return $this->handleGroup($request, Actor::getById($id)); + } + + /** + * View a group feed by its nickname + * + * @param string $nickname The group's nickname to be shown + * + * @throws NicknameEmptyException + * @throws NicknameNotAllowedException + * @throws NicknameTakenException + * @throws NicknameTooLongException + * @throws ServerException + */ + public function groupViewNickname(Request $request, string $nickname): array + { + Nickname::validate($nickname, which: Nickname::CHECK_LOCAL_GROUP); // throws + $group = LocalGroup::getActorByNickname($nickname); + if (\is_null($group)) { + throw new NotFoundException(_m('Group not found.')); + } + return $this->handleGroup($request, $group); + } + /** * Page that allows an actor to create a new group * * @throws RedirectException * @throws ServerException - * - * @return array */ - public function groupCreate(Request $request) + public function groupCreate(Request $request): array { if (\is_null($actor = Common::actor())) { throw new RedirectException('security_login'); @@ -143,19 +156,19 @@ class Group extends FeedController * Settings page for the group with the provided nickname, checks if the current actor can administrate given group * * @throws ClientException + * @throws DuplicateFoundException * @throws NicknameEmptyException + * @throws NicknameException * @throws NicknameInvalidException * @throws NicknameNotAllowedException * @throws NicknameTakenException * @throws NicknameTooLongException - * @throws NoLoggedInUser + * @throws NotFoundException * @throws ServerException - * - * @return array */ - public function groupSettings(Request $request, string $nickname) + public function groupSettings(Request $request, int $id): array { - $local_group = LocalGroup::getByNickname($nickname); + $local_group = DB::findOneBy(LocalGroup::class, ['group_id' => $id]); $group_actor = $local_group->getActor(); $actor = Common::actor(); if (!\is_null($group_actor) && $actor->canAdmin($group_actor)) { @@ -166,7 +179,7 @@ class Group extends FeedController 'open_details_query' => $this->string('open'), ]; } else { - throw new ClientException(_m('You do not have permission to edit settings for the group "{group}"', ['{group}' => $nickname]), code: 404); + throw new ClientException(_m('You do not have permission to edit settings for the group "{group}"', ['{group}' => $id]), code: 404); } } @@ -180,6 +193,10 @@ class Group extends FeedController { $create_form = Form::create([ ['group_nickname', TextType::class, ['label' => _m('Group nickname')]], + ['group_type', ChoiceType::class, ['label' => _m('Type:'), 'multiple' => false, 'expanded' => false, 'choices' => [ + _m('Group') => 'group', + _m('Organisation') => 'organisation', + ]]], ['group_create', SubmitType::class, ['label' => _m('Create this group!')]], ]); @@ -203,6 +220,7 @@ class Group extends FeedController ])); DB::persist(LocalGroup::create([ 'group_id' => $group->getId(), + 'type' => $data['group_type'], 'nickname' => $nickname, ])); DB::persist(ActorSubscription::create([ diff --git a/components/Group/Entity/GroupAlias.php b/components/Group/Entity/GroupAlias.php deleted file mode 100644 index 46ffac6dcf..0000000000 --- a/components/Group/Entity/GroupAlias.php +++ /dev/null @@ -1,100 +0,0 @@ -. -// }}} - -namespace Component\Group\Entity; - -use App\Core\Entity; -use DateTimeInterface; - -/** - * Entity for Group Alias - * - * @category DB - * @package GNUsocial - * - * @author Zach Copley - * @copyright 2010 StatusNet Inc. - * @author Mikael Nordfeldth - * @copyright 2009-2014 Free Software Foundation, Inc http://www.fsf.org - * @author Hugo Sales - * @copyright 2020-2021 Free Software Foundation, Inc http://www.fsf.org - * @license https://www.gnu.org/licenses/agpl.html GNU AGPL v3 or later - */ -class GroupAlias extends Entity -{ - // {{{ Autocode - // @codeCoverageIgnoreStart - private string $alias; - private int $group_id; - private DateTimeInterface $modified; - - public function setAlias(string $alias): self - { - $this->alias = mb_substr($alias, 0, 64); - return $this; - } - - public function getAlias(): string - { - return $this->alias; - } - - public function setGroupId(int $group_id): self - { - $this->group_id = $group_id; - return $this; - } - - public function getGroupId(): int - { - return $this->group_id; - } - - public function setModified(DateTimeInterface $modified): self - { - $this->modified = $modified; - return $this; - } - - public function getModified(): DateTimeInterface - { - return $this->modified; - } - - // @codeCoverageIgnoreEnd - // }}} Autocode - - public static function schemaDef(): array - { - return [ - 'name' => 'group_alias', - 'fields' => [ - 'alias' => ['type' => 'varchar', 'length' => 64, 'not null' => true, 'description' => 'additional nickname for the group'], - 'group_id' => ['type' => 'int', 'foreign key' => true, 'target' => 'Group.id', 'multiplicity' => 'many to one', 'not null' => true, 'description' => 'group id which this is an alias of'], - 'modified' => ['type' => 'timestamp', 'not null' => true, 'default' => 'CURRENT_TIMESTAMP', 'description' => 'date this record was modified'], - ], - 'primary key' => ['alias'], - 'indexes' => [ - 'group_alias_group_id_idx' => ['group_id'], - ], - ]; - } -} diff --git a/components/Group/Entity/GroupBlock.php b/components/Group/Entity/GroupBlock.php deleted file mode 100644 index 76bee7e422..0000000000 --- a/components/Group/Entity/GroupBlock.php +++ /dev/null @@ -1,110 +0,0 @@ -. -// }}} - -namespace Component\Group\Entity; - -use App\Core\Entity; -use DateTimeInterface; - -/** - * Entity for Group Block - * - * @category DB - * @package GNUsocial - * - * @author Zach Copley - * @copyright 2010 StatusNet Inc. - * @author Mikael Nordfeldth - * @copyright 2009-2014 Free Software Foundation, Inc http://www.fsf.org - * @author Hugo Sales - * @copyright 2020-2021 Free Software Foundation, Inc http://www.fsf.org - * @license https://www.gnu.org/licenses/agpl.html GNU AGPL v3 or later - */ -class GroupBlock extends Entity -{ - // {{{ Autocode - // @codeCoverageIgnoreStart - private int $group_id; - private int $blocked_actor; - private int $blocker_user; - private DateTimeInterface $modified; - - public function setGroupId(int $group_id): self - { - $this->group_id = $group_id; - return $this; - } - - public function getGroupId(): int - { - return $this->group_id; - } - - public function setBlockedActor(int $blocked_actor): self - { - $this->blocked_actor = $blocked_actor; - return $this; - } - - public function getBlockedActor(): int - { - return $this->blocked_actor; - } - - public function setBlockerUser(int $blocker_user): self - { - $this->blocker_user = $blocker_user; - return $this; - } - - public function getBlockerUser(): int - { - return $this->blocker_user; - } - - public function setModified(DateTimeInterface $modified): self - { - $this->modified = $modified; - return $this; - } - - public function getModified(): DateTimeInterface - { - return $this->modified; - } - - // @codeCoverageIgnoreEnd - // }}} Autocode - - public static function schemaDef(): array - { - return [ - 'name' => 'group_block', - 'fields' => [ - 'group_id' => ['type' => 'int', 'foreign key' => true, 'target' => 'Group.id', 'multiplicity' => 'many to one', 'not null' => true, 'description' => 'group actor is blocked from'], - 'blocked_actor' => ['type' => 'int', 'foreign key' => true, 'target' => 'Actor.id', 'multiplicity' => 'one to one', 'not null' => true, 'description' => 'actor that is blocked'], - 'blocker_user' => ['type' => 'int', 'foreign key' => true, 'target' => 'LocalUser.id', 'multiplicity' => 'one to one', 'not null' => true, 'description' => 'user making the block'], - 'modified' => ['type' => 'timestamp', 'not null' => true, 'default' => 'CURRENT_TIMESTAMP', 'description' => 'date this record was modified'], - ], - 'primary key' => ['group_id', 'blocked_actor'], - ]; - } -} diff --git a/components/Group/Entity/GroupInbox.php b/components/Group/Entity/GroupInbox.php deleted file mode 100644 index f626a8d40e..0000000000 --- a/components/Group/Entity/GroupInbox.php +++ /dev/null @@ -1,103 +0,0 @@ -. -// }}} - -namespace Component\Group\Entity; - -use App\Core\Entity; -use DateTimeInterface; - -/** - * Entity for Group's inbox - * - * @category DB - * @package GNUsocial - * - * @author Zach Copley - * @copyright 2010 StatusNet Inc. - * @author Mikael Nordfeldth - * @copyright 2009-2014 Free Software Foundation, Inc http://www.fsf.org - * @author Hugo Sales - * @copyright 2020-2021 Free Software Foundation, Inc http://www.fsf.org - * @license https://www.gnu.org/licenses/agpl.html GNU AGPL v3 or later - */ -class GroupInbox extends Entity -{ - // {{{ Autocode - // @codeCoverageIgnoreStart - private int $group_id; - private int $activity_id; - private DateTimeInterface $created; - - public function setGroupId(int $group_id): self - { - $this->group_id = $group_id; - return $this; - } - - public function getGroupId(): int - { - return $this->group_id; - } - - public function setActivityId(int $activity_id): self - { - $this->activity_id = $activity_id; - return $this; - } - - public function getActivityId(): int - { - return $this->activity_id; - } - - public function setCreated(DateTimeInterface $created): self - { - $this->created = $created; - return $this; - } - - public function getCreated(): DateTimeInterface - { - return $this->created; - } - - // @codeCoverageIgnoreEnd - // }}} Autocode - - public static function schemaDef(): array - { - return [ - 'name' => 'group_inbox', - 'description' => 'Many-many table listing activities posted to a given group, or which groups a given activity was posted to', - 'fields' => [ - 'group_id' => ['type' => 'int', 'foreign key' => true, 'target' => 'Group.id', 'multiplicity' => 'one to one', 'name' => 'group_inbox_group_id_fkey', 'not null' => true, 'description' => 'group receiving the activity'], - 'activity_id' => ['type' => 'int', 'foreign key' => true, 'target' => 'Activity.id', 'multiplicity' => 'many to one', 'name' => 'group_inbox_activity_id_fkey', 'not null' => true, 'description' => 'activity received'], - 'created' => ['type' => 'datetime', 'not null' => true, 'default' => 'CURRENT_TIMESTAMP', 'description' => 'date this record was created'], - ], - 'primary key' => ['group_id', 'activity_id'], - 'indexes' => [ - 'group_inbox_activity_id_idx' => ['activity_id'], - 'group_inbox_group_id_created_activity_id_idx' => ['group_id', 'created', 'activity_id'], - 'group_inbox_created_idx' => ['created'], - ], - ]; - } -} diff --git a/components/Group/Entity/LocalGroup.php b/components/Group/Entity/LocalGroup.php index eb04677c6e..059679e783 100644 --- a/components/Group/Entity/LocalGroup.php +++ b/components/Group/Entity/LocalGroup.php @@ -54,7 +54,8 @@ class LocalGroup extends Entity // {{{ Autocode // @codeCoverageIgnoreStart private int $group_id; - private ?string $nickname = null; + private string $nickname; + private string $type; private DateTimeInterface $created; private DateTimeInterface $modified; @@ -69,17 +70,28 @@ class LocalGroup extends Entity return $this->group_id; } - public function setNickname(?string $nickname): self + public function setNickname(string $nickname): self { - $this->nickname = \is_null($nickname) ? null : mb_substr($nickname, 0, 64); + $this->nickname = mb_substr($nickname, 0, 64); return $this; } - public function getNickname(): ?string + public function getNickname(): string { return $this->nickname; } + public function setType(string $type): self + { + $this->type = $type; + return $this; + } + + public function getType(): string + { + return $this->type; + } + public function setCreated(DateTimeInterface $created): self { $this->created = $created; @@ -152,7 +164,8 @@ class LocalGroup extends Entity 'description' => 'Record for a user group on the local site, with some additional info not in user_group', 'fields' => [ 'group_id' => ['type' => 'int', 'foreign key' => true, 'target' => 'Group.id', 'multiplicity' => 'one to one', 'name' => 'local_group_group_id_fkey', 'not null' => true, 'description' => 'group represented'], - 'nickname' => ['type' => 'varchar', 'length' => 64, 'description' => 'group represented'], + 'nickname' => ['type' => 'varchar', 'not null' => true, 'length' => 64, 'description' => 'group represented'], + 'type' => ['type' => 'varchar', 'not null' => true, 'default' => 'group', 'length' => 64, 'description' => 'Group or Organisation'], 'created' => ['type' => 'datetime', 'not null' => true, 'default' => 'CURRENT_TIMESTAMP', 'description' => 'date this record was created'], 'modified' => ['type' => 'datetime', 'not null' => true, 'default' => 'CURRENT_TIMESTAMP', 'description' => 'date this record was modified'], ], diff --git a/components/Group/Group.php b/components/Group/Group.php index 0ee8c45b02..c5394dc065 100644 --- a/components/Group/Group.php +++ b/components/Group/Group.php @@ -40,8 +40,9 @@ class Group extends Component public function onAddRoute(RouteLoader $r): bool { $r->connect(id: 'group_create', uri_path: '/group/new', target: [C\Group::class, 'groupCreate']); - $r->connect(id: 'group_actor_view_nickname', uri_path: '/!{nickname<' . Nickname::DISPLAY_FMT . '>}', target: [C\Group::class, 'groupViewNickname'], options: ['is_system_path' => false]); - $r->connect(id: 'group_settings', uri_path: '/!{nickname<' . Nickname::DISPLAY_FMT . '>}/settings', target: [C\Group::class, 'groupSettings'], options: ['is_system_path' => false]); + $r->connect(id: 'group_actor_view_id', uri_path: '/group/{id<\d+>}', target: [C\Group::class, 'groupViewId']); + $r->connect(id: 'group_settings', uri_path: '/group/{id<\d+>}/settings', target: [C\Group::class, 'groupSettings']); + $r->connect(id: 'group_actor_view_nickname', uri_path: '/!{nickname<' . Nickname::DISPLAY_FMT . '>}', target: [C\Group::class, 'groupViewNickname']); return Event::next; } @@ -53,7 +54,7 @@ class Group extends Component $actor = Common::actor(); $group = $vars['actor']; if (!\is_null($actor) && $group->isGroup() && $actor->canAdmin($group)) { - $url = Router::url('group_settings', ['nickname' => $group->getNickname()]); + $url = Router::url('group_settings', ['id' => $group->getId()]); $res[] = HTML::html(['a' => ['attrs' => ['href' => $url, 'title' => _m('Edit group settings'), 'class' => 'profile-extra-actions'], _m('Group settings')]]); } return Event::next; @@ -62,8 +63,8 @@ class Group extends Component public function onPopulateSettingsTabs(Request $request, string $section, array &$tabs) { if ($section === 'profile' && $request->get('_route') === 'group_settings') { - $nickname = $request->get('nickname'); - $group = LocalGroup::getActorByNickname($nickname); + $group_id = $request->get('id'); + $group = Actor::getById($group_id); $tabs[] = [ 'title' => 'Self tags', 'desc' => 'Add or remove tags on this group', @@ -95,7 +96,7 @@ class Group extends Component { $group = $this->getGroupFromContext($request); if (!\is_null($group)) { - $nick = '!' . $group->getNickname(); + $nick = "!{$group->getNickname()}"; $targets[$nick] = $group->getId(); } return Event::next; diff --git a/components/Group/templates/cards/group/create_widget.html.twig b/components/Group/templates/cards/group/create_widget.html.twig index 3cf183b7e7..a3a50b047b 100644 --- a/components/Group/templates/cards/group/create_widget.html.twig +++ b/components/Group/templates/cards/group/create_widget.html.twig @@ -4,7 +4,7 @@ {% trans %}Create a group{% endtrans %} -
+ {{ form(create_form) }}
\ No newline at end of file diff --git a/components/Notification/Notification.php b/components/Notification/Notification.php index f1b098c58f..84179130b2 100644 --- a/components/Notification/Notification.php +++ b/components/Notification/Notification.php @@ -32,7 +32,6 @@ use App\Entity\Activity; use App\Entity\Actor; use App\Entity\LocalUser; use Component\FreeNetwork\FreeNetwork; -use Component\Group\Entity\GroupInbox; use Component\Notification\Controller\Feed; class Notification extends Component @@ -75,17 +74,9 @@ class Notification extends Component $remote_targets = []; foreach ($targets as $target) { if ($target->getIsLocal()) { - if ($target->isGroup()) { - // FIXME: Make sure we check (for both local and remote) users are in the groups they send to! - DB::persist(GroupInbox::create([ - 'group_id' => $target->getId(), - 'activity_id' => $activity->getId(), - ])); - } else { - if ($target->hasBlocked($activity->getActor())) { - Log::info("Not saving reply to actor {$target->getId()} from sender {$sender->getId()} because of a block."); - continue; - } + if ($target->hasBlocked($activity->getActor())) { + Log::info("Not saving reply to actor {$target->getId()} from sender {$sender->getId()} because of a block."); + continue; } if (Event::handle('NewNotificationShould', [$activity, $target]) === Event::next) { // TODO: use https://symfony.com/doc/current/notifier.html diff --git a/plugins/ActivityPub/Util/Model/Actor.php b/plugins/ActivityPub/Util/Model/Actor.php index c995522bac..6f340e59a7 100644 --- a/plugins/ActivityPub/Util/Model/Actor.php +++ b/plugins/ActivityPub/Util/Model/Actor.php @@ -62,15 +62,14 @@ use Plugin\ActivityPub\Util\Model; class Actor extends Model { private static array $_gs_actor_type_to_as2_actor_type = [ - GSActor::PERSON => 'Person', - GSActor::GROUP => 'Group', - GSActor::ORGANISATION => 'Organization', - GSActor::BOT => 'Application', + GSActor::PERSON => 'Person', + GSActor::GROUP => 'Group', + GSActor::BOT => 'Application', ]; private static array $_as2_actor_type_to_gs_actor_type = [ 'Person' => GSActor::PERSON, 'Group' => GSActor::GROUP, - 'Organization' => GSActor::ORGANISATION, + 'Organization' => GSActor::GROUP, 'Application' => GSActor::BOT, 'Service' => null, ]; diff --git a/plugins/Directory/Controller/Directory.php b/plugins/Directory/Controller/Directory.php index b41f52d70b..1271661ffd 100644 --- a/plugins/Directory/Controller/Directory.php +++ b/plugins/Directory/Controller/Directory.php @@ -29,6 +29,7 @@ use App\Entity\Actor; use App\Util\Common; use App\Util\Exception\BugFoundException; use App\Util\Exception\ClientException; +use App\Util\Exception\ServerException; use Component\Collection\Util\Controller\CircleController; use Symfony\Component\HttpFoundation\Request; @@ -39,8 +40,12 @@ class Directory extends CircleController /** * Function responsible for displaying a list of actors of a given * $actor_type, sorted by the `order_by` GET parameter, if given + * + * @throws BugFoundException + * @throws ClientException + * @throws ServerException */ - private function impl(Request $request, int $actor_type, string $title, string $empty_message): array + private function magic(Request $request, int $actor_type, string $title, string $empty_message): array { if ($actor_type !== Actor::PERSON && $actor_type !== Actor::GROUP) { throw new BugFoundException("Unimplemented for actor type: {$actor_type}"); @@ -99,7 +104,7 @@ class Directory extends CircleController 'limit' => $limit, 'offset' => $offset, ], - ['actr' => Actor::class], + ['actor' => Actor::class], ); }; // -------- *** -------- @@ -114,22 +119,16 @@ class Directory extends CircleController $query_fn = match ($order_by_field) { 'nickname', 'created' => $actor_query_fn, // select only from actors - 'modified' => match ($actor_type) { // select by most/least recent activity - Actor::PERSON => $minmax_query_fn(table: 'activity', join_field: 'actor_id', aggregate_field: 'created'), - Actor::GROUP => $minmax_query_fn(table: 'group_inbox', join_field: 'group_id', aggregate_field: 'created'), - }, + // select by most/least recent activity + 'modified' => $minmax_query_fn(table: 'activity', join_field: 'actor_id', aggregate_field: 'created'), - 'activity' => match ($actor_type) { // select by most/least activity amount - Actor::PERSON => $count_query_fn(table: 'activity', join_field: 'actor_id', aggregate_field: 'created'), - Actor::GROUP => $count_query_fn(table: 'group_inbox', join_field: 'group_id', aggregate_field: 'created'), - }, + // select by most/least activity amount + 'activity' => $count_query_fn(table: 'activity', join_field: 'actor_id', aggregate_field: 'created'), - 'subscribers' => match ($actor_type) { // select by actors with most/least subscribers/members - Actor::PERSON => $count_query_fn(table: 'subscription', join_field: 'subscribed_id', aggregate_field: 'subscriber_id'), - Actor::GROUP => $count_query_fn(table: 'group_member', join_field: 'group_id', aggregate_field: 'actor_id'), - }, + // select by actors with most/least subscribers/members + 'subscribers' => $count_query_fn(table: 'subscription', join_field: 'subscribed_id', aggregate_field: 'subscriber_id'), - default => throw new BugFoundException("Unkown order by found, but should have been validated: {$order_by_field}"), + default => throw new BugFoundException("Unknown order by found, but should have been validated: {$order_by_field}"), }; // -------- *** -------- @@ -154,11 +153,11 @@ class Directory extends CircleController public function people(Request $request): array { - return $this->impl($request, Actor::PERSON, title: _m('People'), empty_message: _m('No people here')); + return $this->magic($request, Actor::PERSON, title: _m('People'), empty_message: _m('No people here')); } public function groups(Request $request): array { - return $this->impl($request, Actor::GROUP, title: _m('Groups'), empty_message: _m('No groups here')); + return $this->magic($request, Actor::GROUP, title: _m('Groups'), empty_message: _m('No groups here')); } } diff --git a/src/Entity/Actor.php b/src/Entity/Actor.php index dd314b393e..9f362696b4 100644 --- a/src/Entity/Actor.php +++ b/src/Entity/Actor.php @@ -243,8 +243,7 @@ class Actor extends Entity public const PERSON = 1; public const GROUP = 2; - public const ORGANISATION = 3; - public const BOT = 4; + public const BOT = 3; public static function cacheKeys(int|self $actor_id, mixed $other = null): array { @@ -421,7 +420,6 @@ class Actor extends Entity if (Event::handle('StartGetActorUri', [$this, $type, &$uri]) === Event::next) { switch ($this->type) { case self::PERSON: - case self::ORGANISATION: case self::BOT: case self::GROUP: $uri = Router::url('actor_view_id', ['id' => $this->getId()], $type); @@ -447,7 +445,7 @@ class Actor extends Entity $url = null; if (Event::handle('StartGetActorUrl', [$this, $type, &$url]) === Event::next) { $url = match ($this->type) { - self::PERSON, self::ORGANISATION, self::BOT => Router::url('actor_view_nickname', ['nickname' => mb_strtolower($this->getNickname())], $type), + self::PERSON, self::BOT => Router::url('actor_view_nickname', ['nickname' => mb_strtolower($this->getNickname())], $type), self::GROUP => Router::url('group_actor_view_nickname', ['nickname' => $this->getNickname()], $type), default => throw new BugFoundException('Actor type added but `Actor::getUrl` was not updated'), }; @@ -529,7 +527,6 @@ class Actor extends Entity /** * @method bool isPerson() * @method bool isGroup() - * @method bool isOrganization() * @method bool isBot() */ public function __call(string $name, array $arguments): mixed