kopia lustrzana https://github.com/nextcloud/social
using AP object to generate items so UrlCloud is set by default
Signed-off-by: Maxence Lange <maxence@artificial-owl.com>pull/299/head
rodzic
f54b346bd0
commit
3e8694ff53
56
lib/AP.php
56
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;
|
||||
}
|
||||
|
||||
|
||||
|
|
|
@ -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);
|
||||
|
|
|
@ -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) {
|
||||
|
|
|
@ -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');
|
||||
|
||||
|
|
|
@ -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());
|
||||
|
|
Ładowanie…
Reference in New Issue