From 8dcafff002956b74d41566b4b6d33d6538bec6f4 Mon Sep 17 00:00:00 2001 From: veselcraft Date: Tue, 28 Dec 2021 18:24:30 +0300 Subject: [PATCH] ActivityPub, Users: Add more functionality to getByShortUrl, add fetching by id[0-9] --- Web/Models/Repositories/Users.php | 12 ++++++++++-- Web/Presenters/ActivityPubPresenter.php | 2 +- 2 files changed, 11 insertions(+), 3 deletions(-) diff --git a/Web/Models/Repositories/Users.php b/Web/Models/Repositories/Users.php index 42dd452f..1bf7e987 100644 --- a/Web/Models/Repositories/Users.php +++ b/Web/Models/Repositories/Users.php @@ -28,9 +28,17 @@ class Users return $this->toUser($this->users->get($id)); } - function getByShortURL(string $url): ?User + function getByShortURL(string $url, bool $handleId = false): ?User { - return $this->toUser($this->users->where("shortcode", $url)->fetch()); + $user = $this->toUser($this->users->where("shortcode", $url)->fetch()); + if($user) + return $user + else if ($handleId == true) + { + preg_match("/id([0-9]+)/", $url, $id); + return $this->toUser($this->users->get($id[1])); + } + return null; } function getByChandlerUser(ChandlerUser $user): ?User diff --git a/Web/Presenters/ActivityPubPresenter.php b/Web/Presenters/ActivityPubPresenter.php index dc9bf9bc..3f800114 100755 --- a/Web/Presenters/ActivityPubPresenter.php +++ b/Web/Presenters/ActivityPubPresenter.php @@ -27,7 +27,7 @@ final class ActivityPubPresenter extends OpenVKPresenter preg_match('/([a-zA-Z0-9-_]+)@([a-zA-Z0-9-_\.]+)/', $subject, $username); $username = $username[1]; - $user = (new Users)->getByShortURL($username); + $user = (new Users)->getByShortURL($username, true); if($user !== null) { $response->subject = $this->requestParam("resource");