summaryrefslogtreecommitdiffstats
path: root/lib
diff options
context:
space:
mode:
authorMaxence Lange <maxence@artificial-owl.com>2019-09-26 12:32:49 +0200
committerGitHub <noreply@github.com>2019-09-26 12:32:49 +0200
commite0e26d9a4971406c9e68c94a8c7800a31dc73fcd (patch)
tree2b3ecee914b7b76a21e62686a36728dbc1a038f3 /lib
parentf5c43764858b484ad6b91b7575c7bfcb5d568bab (diff)
parent2f7683a0aed54b45d304c324314bf36ad1f6916a (diff)
Merge pull request #746 from nextcloud/bugfix/745/social-address-on-local-account
check social address during local actor
Diffstat (limited to 'lib')
-rw-r--r--lib/Controller/SocialPubController.php2
-rw-r--r--lib/Service/CacheActorService.php28
2 files changed, 23 insertions, 7 deletions
diff --git a/lib/Controller/SocialPubController.php b/lib/Controller/SocialPubController.php
index 6194a209..d83fd3b2 100644
--- a/lib/Controller/SocialPubController.php
+++ b/lib/Controller/SocialPubController.php
@@ -125,7 +125,7 @@ class SocialPubController extends Controller {
$status = Http::STATUS_OK;
try {
- $actor = $this->cacheActorService->getFromLocalAccount($username);
+ $actor = $this->cacheActorService->getFromAccount($username);
$displayName = $actor->getName() !== '' ? $actor->getName() : $actor->getPreferredUsername();
$data['application'] = $displayName . ' - ' . $data['application'];
} catch (CacheActorDoesNotExistException $e) {
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) {
}
}
+
}
+