ActivityPub, Users: Add more functionality to getByShortUrl, add fetching by id[0-9]

This commit is contained in:
veselcraft 2021-12-28 18:24:30 +03:00
parent 6119b92dc2
commit 8dcafff002
No known key found for this signature in database
GPG key ID: AED66BC1AC628A4E
2 changed files with 11 additions and 3 deletions

View file

@ -28,9 +28,17 @@ class Users
return $this->toUser($this->users->get($id)); 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 function getByChandlerUser(ChandlerUser $user): ?User

View file

@ -27,7 +27,7 @@ final class ActivityPubPresenter extends OpenVKPresenter
preg_match('/([a-zA-Z0-9-_]+)@([a-zA-Z0-9-_\.]+)/', $subject, $username); preg_match('/([a-zA-Z0-9-_]+)@([a-zA-Z0-9-_\.]+)/', $subject, $username);
$username = $username[1]; $username = $username[1];
$user = (new Users)->getByShortURL($username); $user = (new Users)->getByShortURL($username, true);
if($user !== null) { if($user !== null) {
$response->subject = $this->requestParam("resource"); $response->subject = $this->requestParam("resource");