summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorJulius Härtl <jus@bitgrid.net>2019-01-03 12:59:22 +0100
committerGitHub <noreply@github.com>2019-01-03 12:59:22 +0100
commite31a8a1aca717dae02d8821e410b85686f525c66 (patch)
tree23aaa8d32ec5f4364bd1b8dc9a2bac65f42b04f8
parentf54b346bd033e46ef3cc19d6f5b4c0ade11e6c37 (diff)
parenta1410b7ed83b9bc9c90ffb41d1d2e42577914595 (diff)
Merge pull request #299 from nextcloud/bugfix/noid/better-setup-of-items
setUrlCloud on item creation
-rw-r--r--lib/AP.php56
-rw-r--r--lib/Interfaces/Activity/FollowInterface.php4
-rw-r--r--lib/Model/ActivityPub/Actor/Person.php9
-rw-r--r--lib/Service/DocumentService.php9
-rw-r--r--lib/Service/FollowService.php9
5 files changed, 59 insertions, 28 deletions
diff --git a/lib/AP.php b/lib/AP.php
index c205a2a3..a5f3b50f 100644
--- a/lib/AP.php
+++ b/lib/AP.php
@@ -32,9 +32,9 @@ namespace OCA\Social;
use daita\MySmallPhpTools\Traits\TArrayTools;
+use OCA\Social\Exceptions\ItemUnknownException;
use OCA\Social\Exceptions\RedundancyLimitException;
use OCA\Social\Exceptions\SocialAppConfigException;
-use OCA\Social\Exceptions\ItemUnknownException;
use OCA\Social\Interfaces\Activity\AcceptInterface;
use OCA\Social\Interfaces\Activity\AddInterface;
use OCA\Social\Interfaces\Activity\BlockInterface;
@@ -212,7 +212,6 @@ class AP {
*/
public function getSimpleItemFromData(array $data): Acore {
$item = $this->getItemFromType($this->get('type', $data, ''));
- $item->setUrlCloud($this->configService->getCloudAddress());
$item->import($data);
$item->setSource(json_encode($data, JSON_UNESCAPED_SLASHES));
@@ -224,57 +223,78 @@ class AP {
*
* @return ACore
* @throws ItemUnknownException
+ * @throws SocialAppConfigException
*/
- public function getItemFromType(string $type) {
+ public function getItemFromType(string $type): ACore {
+
switch ($type) {
case Accept::TYPE:
- return new Accept();
+ $item = new Accept();
+ break;
case Add::TYPE:
- return new Add();
+ $item = new Add();
+ break;
case Block::TYPE:
- return new Block();
+ $item = new Block();
+ break;
case Create::TYPE:
- return new Create();
+ $item = new Create();
+ break;
case Delete::TYPE:
- return new Delete();
+ $item = new Delete();
+ break;
case Follow::TYPE:
- return new Follow();
+ $item = new Follow();
+ break;
case Image::TYPE:
- return new Image();
+ $item = new Image();
+ break;
case Like::TYPE:
- return new Like();
+ $item = new Like();
+ break;
case Note::TYPE:
- return new Note();
+ $item = new Note();
+ break;
case Person::TYPE:
- return new Person();
+ $item = new Person();
+ break;
case Reject::TYPE:
- return new Reject();
+ $item = new Reject();
+ break;
case Remove::TYPE:
- return new Remove();
+ $item = new Remove();
+ break;
case Tombstone::TYPE:
- return new Tombstone();
+ $item = new Tombstone();
+ break;
case Undo::TYPE:
- return new Undo();
+ $item = new Undo();
+ break;
case Update::TYPE:
- return new Update();
+ $item = new Update();
+ break;
default:
throw new ItemUnknownException();
}
+
+ $item->setUrlCloud($this->configService->getCloudAddress());
+
+ return $item;
}
diff --git a/lib/Interfaces/Activity/FollowInterface.php b/lib/Interfaces/Activity/FollowInterface.php
index b88381ff..d73070a0 100644
--- a/lib/Interfaces/Activity/FollowInterface.php
+++ b/lib/Interfaces/Activity/FollowInterface.php
@@ -33,6 +33,7 @@ namespace OCA\Social\Interfaces\Activity;
use daita\MySmallPhpTools\Exceptions\MalformedArrayException;
use Exception;
+use OCA\Social\AP;
use OCA\Social\Db\FollowsRequest;
use OCA\Social\Exceptions\FollowDoesNotExistException;
use OCA\Social\Exceptions\InvalidOriginException;
@@ -112,8 +113,7 @@ class FollowInterface implements IActivityPubInterface {
try {
$remoteActor = $this->cacheActorService->getFromId($follow->getActorId());
- $accept = new Accept();
- $accept->setUrlCloud($this->configService->getCloudAddress());
+ $accept = AP::$activityPub->getItemFromType(Accept::TYPE);
$accept->generateUniqueId('#accept/follows');
$accept->setActorId($follow->getObjectId());
$accept->setObject($follow);
diff --git a/lib/Model/ActivityPub/Actor/Person.php b/lib/Model/ActivityPub/Actor/Person.php
index 6383ca03..0024eb69 100644
--- a/lib/Model/ActivityPub/Actor/Person.php
+++ b/lib/Model/ActivityPub/Actor/Person.php
@@ -33,6 +33,9 @@ namespace OCA\Social\Model\ActivityPub\Actor;
use DateTime;
use JsonSerializable;
+use OCA\Social\AP;
+use OCA\Social\Exceptions\ItemUnknownException;
+use OCA\Social\Exceptions\SocialAppConfigException;
use OCA\Social\Exceptions\UrlCloudException;
use OCA\Social\Model\ActivityPub\ACore;
use OCA\Social\Model\ActivityPub\Object\Image;
@@ -442,6 +445,8 @@ class Person extends ACore implements JsonSerializable {
/**
* @param array $data
*
+ * @throws ItemUnknownException
+ * @throws SocialAppConfigException
* @throws UrlCloudException
*/
public function import(array $data) {
@@ -459,8 +464,8 @@ class Person extends ACore implements JsonSerializable {
->setFollowing($this->validate(ACore::AS_URL, 'following', $data, ''))
->setFeatured($this->validate(ACore::AS_URL, 'featured', $data, ''));
- $icon = new Image($this);
- $icon->setUrlCloud($this->getUrlCloud());
+ /** @var Image $icon */
+ $icon = AP::$activityPub->getItemFromType(Image::TYPE);
$icon->import($this->getArray('icon', $data, []));
if ($icon->getType() === Image::TYPE) {
diff --git a/lib/Service/DocumentService.php b/lib/Service/DocumentService.php
index 650b8d4f..07b86f6c 100644
--- a/lib/Service/DocumentService.php
+++ b/lib/Service/DocumentService.php
@@ -33,11 +33,13 @@ namespace OCA\Social\Service;
use daita\MySmallPhpTools\Exceptions\MalformedArrayException;
use Exception;
+use OCA\Social\AP;
use OCA\Social\Db\ActorsRequest;
use OCA\Social\Db\CacheDocumentsRequest;
use OCA\Social\Exceptions\CacheContentException;
use OCA\Social\Exceptions\CacheContentMimeTypeException;
use OCA\Social\Exceptions\CacheDocumentDoesNotExistException;
+use OCA\Social\Exceptions\ItemUnknownException;
use OCA\Social\Exceptions\RequestContentException;
use OCA\Social\Exceptions\RequestNetworkException;
use OCA\Social\Exceptions\RequestResultSizeException;
@@ -216,6 +218,7 @@ class DocumentService {
* @return string
* @throws SocialAppConfigException
* @throws UrlCloudException
+ * @throws ItemUnknownException
*/
public function cacheLocalAvatarByUsername(Person $actor): string {
$url = $this->urlGenerator->linkToRouteAbsolute(
@@ -226,10 +229,10 @@ class DocumentService {
(int)$this->configService->getUserValue('version', $actor->getUserId(), 'avatar');
$versionCached = $actor->getAvatarVersion();
if ($versionCurrent > $versionCached) {
- $icon = new Image();
- $icon->setUrl($url);
- $icon->setUrlcloud($this->configService->getCloudAddress());
+ /** @var Image $icon */
+ $icon = AP::$activityPub->getItemFromType(Image::TYPE);
$icon->generateUniqueId('/documents/avatar');
+ $icon->setUrl($url);
$icon->setMediaType('');
$icon->setLocalCopy('avatar');
diff --git a/lib/Service/FollowService.php b/lib/Service/FollowService.php
index 21d48627..f6a2c45c 100644
--- a/lib/Service/FollowService.php
+++ b/lib/Service/FollowService.php
@@ -32,6 +32,7 @@ namespace OCA\Social\Service;
use daita\MySmallPhpTools\Exceptions\MalformedArrayException;
use daita\MySmallPhpTools\Traits\TArrayTools;
+use OCA\Social\AP;
use OCA\Social\Db\FollowsRequest;
use OCA\Social\Exceptions\CacheActorDoesNotExistException;
use OCA\Social\Exceptions\FollowDoesNotExistException;
@@ -139,8 +140,8 @@ class FollowService {
throw new FollowSameAccountException("Don't follow yourself, be your own lead");
}
- $follow = new Follow();
- $follow->setUrlCloud($this->configService->getCloudAddress());
+ /** @var Follow $follow */
+ $follow = AP::$activityPub->getItemFromType(Follow::TYPE);
$follow->generateUniqueId();
$follow->setActorId($actor->getId());
$follow->setObjectId($remoteActor->getId());
@@ -179,6 +180,7 @@ class FollowService {
* @throws RequestServerException
* @throws SocialAppConfigException
* @throws ItemUnknownException
+ * @throws UrlCloudException
*/
public function unfollowAccount(Person $actor, string $account) {
$remoteActor = $this->cacheActorService->getFromAccount($account);
@@ -187,8 +189,9 @@ class FollowService {
$follow = $this->followsRequest->getByPersons($actor->getId(), $remoteActor->getId());
$this->followsRequest->delete($follow);
- $undo = new Undo();
+ $undo = AP::$activityPub->getItemFromType(Undo::TYPE);
$follow->setParent($undo);
+ $undo->generateUniqueId('#undo/follows');
$undo->setObject($follow);
$undo->setActorId($actor->getId());