summaryrefslogtreecommitdiffstats
path: root/lib/Service
diff options
context:
space:
mode:
authorMaxence Lange <maxence@artificial-owl.com>2019-09-17 13:30:06 +0200
committerMaxence Lange <maxence@artificial-owl.com>2019-09-17 13:30:06 +0200
commiteefa99f2879e29846446cc4e945e71771b0fd8dc (patch)
treed4b9dea8327f3b0c685b99e75453136c88f504b0 /lib/Service
parent95c3d8555b231d6daa120a4309302a070026812b (diff)
check social address during local actor
Signed-off-by: Maxence Lange <maxence@artificial-owl.com>
Diffstat (limited to 'lib/Service')
-rw-r--r--lib/Service/CacheActorService.php28
1 files changed, 22 insertions, 6 deletions
diff --git a/lib/Service/CacheActorService.php b/lib/Service/CacheActorService.php
index 7420dda5..9d5c143f 100644
--- a/lib/Service/CacheActorService.php
+++ b/lib/Service/CacheActorService.php
@@ -38,15 +38,16 @@ use OCA\Social\Db\CacheActorsRequest;
use OCA\Social\Exceptions\CacheActorDoesNotExistException;
use OCA\Social\Exceptions\InvalidOriginException;
use OCA\Social\Exceptions\InvalidResourceException;
+use OCA\Social\Exceptions\ItemAlreadyExistsException;
+use OCA\Social\Exceptions\ItemUnknownException;
use OCA\Social\Exceptions\RedundancyLimitException;
use OCA\Social\Exceptions\RequestContentException;
-use OCA\Social\Exceptions\RequestResultNotJsonException;
-use OCA\Social\Exceptions\RetrieveAccountFormatException;
use OCA\Social\Exceptions\RequestNetworkException;
+use OCA\Social\Exceptions\RequestResultNotJsonException;
use OCA\Social\Exceptions\RequestResultSizeException;
use OCA\Social\Exceptions\RequestServerException;
+use OCA\Social\Exceptions\RetrieveAccountFormatException;
use OCA\Social\Exceptions\SocialAppConfigException;
-use OCA\Social\Exceptions\ItemUnknownException;
use OCA\Social\Exceptions\UnauthorizedFediverseException;
use OCA\Social\Model\ActivityPub\Actor\Person;
@@ -166,15 +167,22 @@ class CacheActorService {
*
* @return Person
* @throws CacheActorDoesNotExistException
+ * @throws SocialAppConfigException
*/
public function getFromLocalAccount(string $account): Person {
+ $instance = '';
if (strrpos($account, '@')) {
- $account = substr($account, 0, strrpos($account, '@'));
+ list($account, $instance) = explode('@', $account);
}
- return $this->cacheActorsRequest->getFromLocalAccount($account);
- }
+ if ($instance === ''
+ || $this->configService->getCloudHost() === $instance
+ || $this->configService->getSocialAddress() === $instance) {
+ return $this->cacheActorsRequest->getFromLocalAccount($account);
+ }
+ throw new CacheActorDoesNotExistException();
+ }
/**
* @param string $account
@@ -200,6 +208,10 @@ class CacheActorService {
* @throws UnauthorizedFediverseException
*/
public function getFromAccount(string $account, bool $retrieve = true): Person {
+ try {
+ return $this->getFromLocalAccount($account);
+ } catch (CacheActorDoesNotExistException $e) {
+ }
try {
$actor = $this->cacheActorsRequest->getFromAccount($account);
@@ -270,6 +282,8 @@ class CacheActorService {
/**
* @param Person $actor
+ *
+ * @throws ItemAlreadyExistsException
*/
private function save(Person $actor) {
try {
@@ -278,4 +292,6 @@ class CacheActorService {
} catch (ItemUnknownException $e) {
}
}
+
}
+