summaryrefslogtreecommitdiffstats
path: root/lib/Service
diff options
context:
space:
mode:
Diffstat (limited to 'lib/Service')
-rw-r--r--lib/Service/AccountService.php2
-rw-r--r--lib/Service/ActivityService.php4
-rw-r--r--lib/Service/BoostService.php47
-rw-r--r--lib/Service/CacheActorService.php1
-rw-r--r--lib/Service/CurlService.php3
-rw-r--r--lib/Service/NoteService.php20
-rw-r--r--lib/Service/SignatureService.php11
-rw-r--r--lib/Service/StreamQueueService.php23
8 files changed, 79 insertions, 32 deletions
diff --git a/lib/Service/AccountService.php b/lib/Service/AccountService.php
index 004aac51..d7ff1941 100644
--- a/lib/Service/AccountService.php
+++ b/lib/Service/AccountService.php
@@ -280,7 +280,7 @@ class AccountService {
'following' => $this->followsRequest->countFollowing($actor->getId()),
'post' => $this->streamRequest->countNotesFromActorId($actor->getId())
];
- $actor->addDetailArray('count', $count);
+ $actor->setDetailArray('count', $count);
}
diff --git a/lib/Service/ActivityService.php b/lib/Service/ActivityService.php
index 513a048b..f4c85288 100644
--- a/lib/Service/ActivityService.php
+++ b/lib/Service/ActivityService.php
@@ -358,7 +358,7 @@ class ActivityService {
$sharedInboxes = [];
$instancePaths = [];
foreach ($follows as $follow) {
- if (!$follow->gotActor()) {
+ if (!$follow->hasActor()) {
// TODO - check if cache can be empty at this point ?
continue;
}
@@ -415,7 +415,7 @@ class ActivityService {
* @return string
*/
private function getAuthorFromItem(Acore $activity): string {
- if ($activity->gotActor()) {
+ if ($activity->hasActor()) {
return $activity->getActor()
->getId();
}
diff --git a/lib/Service/BoostService.php b/lib/Service/BoostService.php
index bf705e4a..7019d6b6 100644
--- a/lib/Service/BoostService.php
+++ b/lib/Service/BoostService.php
@@ -34,6 +34,7 @@ use daita\MySmallPhpTools\Traits\TStringTools;
use Exception;
use OCA\Social\AP;
use OCA\Social\Db\StreamRequest;
+use OCA\Social\Exceptions\ItemUnknownException;
use OCA\Social\Exceptions\SocialAppConfigException;
use OCA\Social\Exceptions\StreamNotFoundException;
use OCA\Social\Model\ActivityPub\ACore;
@@ -114,14 +115,9 @@ class BoostService {
* @throws Exception
*/
public function create(Person $actor, string $postId, &$token = ''): ACore {
-
- try {
- return $this->get($actor, $postId);
- } catch (StreamNotFoundException $e) {
- }
-
+ /** @var Announce $announce */
$announce = AP::$activityPub->getItemFromType(Announce::TYPE);
- $this->noteService->assignItem($announce, $actor, Stream::TYPE_PUBLIC);
+ $this->noteService->assignItem($announce, $actor, Stream::TYPE_ANNOUNCE);
$announce->setActor($actor);
$note = $this->noteService->getNoteById($postId, true);
@@ -129,7 +125,11 @@ class BoostService {
throw new StreamNotFoundException('Stream is not a Note');
}
- $announce->addCc($note->getAttributedTo());
+ if (!$note->isPublic()) {
+ throw new StreamNotFoundException('Stream is not Public');
+ }
+
+ $announce->addCc($actor->getFollowers());
$announce->setObjectId($note->getId());
$announce->setRequestToken($this->uuid());
@@ -148,14 +148,15 @@ class BoostService {
/**
- * @param Person $actor
* @param string $postId
*
* @return Stream
+ * @throws ItemUnknownException
+ * @throws SocialAppConfigException
* @throws StreamNotFoundException
*/
- public function get(Person $actor, string $postId): Stream {
- $stream = $this->streamRequest->getStreamByObjectId($actor, Announce::TYPE, $postId);
+ public function get(string $postId): Stream {
+ $stream = $this->streamRequest->getStreamByObjectId($postId, Announce::TYPE);
return $stream;
}
@@ -167,8 +168,8 @@ class BoostService {
* @param string $token
*
* @return ACore
- * @throws StreamNotFoundException
* @throws SocialAppConfigException
+ * @throws StreamNotFoundException
*/
public function delete(Person $actor, string $postId, &$token = ''): ACore {
$undo = new Undo();
@@ -180,16 +181,24 @@ class BoostService {
throw new StreamNotFoundException('Stream is not a Note');
}
- $announce = $this->streamRequest->getStreamByObjectId($actor, Announce::TYPE, $postId);
+ try {
+ $announce = $this->streamRequest->getStreamByObjectId($postId, Announce::TYPE);
+ $announce->setActor($actor);
- $undo->setObject($announce);
- $undo->setCcArray($announce->getCcArray());
+ $undo->setObjectId($announce->getId());
+ $undo->addCc($actor->getFollowers());
- $this->streamRequest->deleteStreamById($announce->getId(), Announce::TYPE);
- $this->streamActionService->setActionBool($actor->getId(), $postId, 'boosted', false);
- $this->signatureService->signObject($actor, $undo);
+ $interface = AP::$activityPub->getInterfaceFromType(Announce::TYPE);
+ $interface->delete($announce);
+// $this->streamRequest->deleteStreamById($announce->getId(), Announce::TYPE);
+ $this->signatureService->signObject($actor, $undo);
- $token = $this->activityService->request($undo);
+ $token = $this->activityService->request($undo);
+ } catch (ItemUnknownException $e) {
+ } catch (StreamNotFoundException $e) {
+ }
+
+ $this->streamActionService->setActionBool($actor->getId(), $postId, 'boosted', false);
return $undo;
}
diff --git a/lib/Service/CacheActorService.php b/lib/Service/CacheActorService.php
index 2aed18e6..e0c989d8 100644
--- a/lib/Service/CacheActorService.php
+++ b/lib/Service/CacheActorService.php
@@ -195,6 +195,7 @@ class CacheActorService {
* @throws SocialAppConfigException
* @throws ItemUnknownException
* @throws RequestResultNotJsonException
+ * @throws UnauthorizedFediverseException
*/
public function getFromAccount(string $account, bool $retrieve = true): Person {
diff --git a/lib/Service/CurlService.php b/lib/Service/CurlService.php
index ef12a93e..cbea8819 100644
--- a/lib/Service/CurlService.php
+++ b/lib/Service/CurlService.php
@@ -230,6 +230,8 @@ class CurlService {
$this->fediverseService->authorized($request->getAddress());
$this->maxDownloadSizeReached = false;
+ $this->assignUserAgent($request);
+
$curl = $this->initRequest($request);
$this->initRequestPost($curl, $request);
@@ -292,6 +294,7 @@ class CurlService {
try {
$this->request($request);
+ } catch (RequestResultNotJsonException $e) {
} catch (Exception $e) {
$this->miscService->log(
'Cannot initiate AsyncWithToken ' . json_encode($token) . ' (' . get_class($e)
diff --git a/lib/Service/NoteService.php b/lib/Service/NoteService.php
index e865d03b..0e807169 100644
--- a/lib/Service/NoteService.php
+++ b/lib/Service/NoteService.php
@@ -44,6 +44,7 @@ use OCA\Social\Exceptions\RequestResultNotJsonException;
use OCA\Social\Exceptions\RequestResultSizeException;
use OCA\Social\Exceptions\RequestServerException;
use OCA\Social\Exceptions\SocialAppConfigException;
+use OCA\Social\Exceptions\UnauthorizedFediverseException;
use OCA\Social\Model\ActivityPub\ACore;
use OCA\Social\Model\ActivityPub\Actor\Person;
use OCA\Social\Model\ActivityPub\Object\Note;
@@ -158,7 +159,7 @@ class NoteService {
*/
private function setRecipient(ACore $stream, Person $actor, string $type) {
switch ($type) {
- case Note::TYPE_UNLISTED:
+ case Stream::TYPE_UNLISTED:
$stream->setTo($actor->getFollowers());
$stream->addInstancePath(
new InstancePath(
@@ -169,7 +170,7 @@ class NoteService {
$stream->addCc(ACore::CONTEXT_PUBLIC);
break;
- case Note::TYPE_FOLLOWERS:
+ case Stream::TYPE_FOLLOWERS:
$stream->setTo($actor->getFollowers());
$stream->addInstancePath(
new InstancePath(
@@ -179,7 +180,17 @@ class NoteService {
);
break;
- case Note::TYPE_DIRECT:
+ case Stream::TYPE_ANNOUNCE:
+ $stream->addInstancePath(
+ new InstancePath(
+ $actor->getFollowers(), InstancePath::TYPE_FOLLOWERS,
+ InstancePath::PRIORITY_LOW
+ )
+ );
+ $stream->addCc($actor->getFollowers());
+ break;
+
+ case Stream::TYPE_DIRECT:
break;
default:
@@ -215,7 +226,7 @@ class NoteService {
$instancePath = new InstancePath(
$actor->getInbox(), InstancePath::TYPE_INBOX, InstancePath::PRIORITY_MEDIUM
);
- if ($type === Note::TYPE_DIRECT) {
+ if ($type === Stream::TYPE_DIRECT) {
$instancePath->setPriority(InstancePath::PRIORITY_HIGH);
$stream->addToArray($actor->getId());
} else {
@@ -460,6 +471,7 @@ class NoteService {
* @throws RequestResultSizeException
* @throws RequestServerException
* @throws RequestResultNotJsonException
+ * @throws UnauthorizedFediverseException
*/
public function getAuthorFromPostId($noteId) {
$note = $this->streamRequest->getStreamById($noteId);
diff --git a/lib/Service/SignatureService.php b/lib/Service/SignatureService.php
index ac0cdc1e..dc7c1452 100644
--- a/lib/Service/SignatureService.php
+++ b/lib/Service/SignatureService.php
@@ -54,6 +54,7 @@ use OCA\Social\Exceptions\RequestServerException;
use OCA\Social\Exceptions\SignatureException;
use OCA\Social\Exceptions\SignatureIsGoneException;
use OCA\Social\Exceptions\SocialAppConfigException;
+use OCA\Social\Exceptions\UnauthorizedFediverseException;
use OCA\Social\Model\ActivityPub\ACore;
use OCA\Social\Model\ActivityPub\Actor\Person;
use OCA\Social\Model\LinkedDataSignature;
@@ -126,7 +127,7 @@ class SignatureService {
public function generateKeys(Person &$actor) {
$res = openssl_pkey_new(
[
- "digest_alg" => "rsa",
+ "digest_alg" => "rsa",
"private_key_bits" => 2048,
"private_key_type" => OPENSSL_KEYTYPE_RSA,
]
@@ -231,6 +232,7 @@ class SignatureService {
* @throws ItemUnknownException
* @throws RequestResultNotJsonException
* @throws DateTimeException
+ * @throws UnauthorizedFediverseException
*/
public function checkObject(ACore $object): bool {
try {
@@ -262,6 +264,10 @@ class SignatureService {
return true;
} catch (LinkedDataSignatureMissingException $e) {
+ $this->miscService->log(
+ 'LinkedDataSignatureMissingException while checkObject : ' . $e->getMessage()
+ . ' --- ' . json_encode($object), 1
+ );
}
return false;
@@ -402,10 +408,11 @@ class SignatureService {
* @throws RedundancyLimitException
* @throws RequestContentException
* @throws RequestNetworkException
+ * @throws RequestResultNotJsonException
* @throws RequestResultSizeException
* @throws RequestServerException
* @throws SocialAppConfigException
- * @throws RequestResultNotJsonException
+ * @throws UnauthorizedFediverseException
*/
private function retrieveKey(string $keyId, bool $refresh = false): string {
$actor = $this->cacheActorService->getFromId($keyId, $refresh);
diff --git a/lib/Service/StreamQueueService.php b/lib/Service/StreamQueueService.php
index de4edb61..6c0534f3 100644
--- a/lib/Service/StreamQueueService.php
+++ b/lib/Service/StreamQueueService.php
@@ -68,8 +68,12 @@ class StreamQueueService {
/** @var StreamQueueRequest */
private $streamQueueRequest;
+ /** @var ImportService */
private $importService;
+ /** @var CacheActorService */
+ private $cacheActorService;
+
/** @var CurlService */
private $curlService;
@@ -82,17 +86,20 @@ class StreamQueueService {
*
* @param StreamRequest $streamRequest
* @param StreamQueueRequest $streamQueueRequest
+ * @param CacheActorService $cacheActorService
* @param ImportService $importService
* @param CurlService $curlService
* @param MiscService $miscService
*/
public function __construct(
StreamRequest $streamRequest, StreamQueueRequest $streamQueueRequest,
- ImportService $importService, CurlService $curlService, MiscService $miscService
+ CacheActorService $cacheActorService, ImportService $importService,
+ CurlService $curlService, MiscService $miscService
) {
$this->streamRequest = $streamRequest;
$this->streamQueueRequest = $streamQueueRequest;
$this->importService = $importService;
+ $this->cacheActorService = $cacheActorService;
$this->curlService = $curlService;
$this->miscService = $miscService;
}
@@ -309,9 +316,8 @@ class StreamQueueService {
* @throws UnauthorizedFediverseException
*/
private function cacheItem(CacheItem &$item) {
-
try {
- $object = $this->streamRequest->getStreamById($item->getUrl());
+ $note = $this->streamRequest->getStreamById($item->getUrl());
} catch (StreamNotFoundException $e) {
$data = $this->curlService->retrieveObject($item->getUrl());
$object = AP::$activityPub->getItemFromData($data);
@@ -330,11 +336,15 @@ class StreamQueueService {
throw new InvalidResourceException();
}
+ /** @var Stream $object */
+ $this->cacheActorService->getFromId($object->getAttributedTo());
+
$interface = AP::$activityPub->getInterfaceForItem($object);
$interface->save($object);
+
+ $note = $this->streamRequest->getStreamById($object->getId());
}
- $note = $this->streamRequest->getStreamById($object->getId());
$item->setContent(json_encode($note, JSON_UNESCAPED_SLASHES));
}
@@ -347,6 +357,11 @@ class StreamQueueService {
*/
private function updateCache(Stream $stream, Cache $cache): bool {
$this->streamRequest->updateCache($stream, $cache);
+ try {
+ $interface = AP::$activityPub->getInterfaceForItem($stream);
+ $interface->event($stream, 'updateCache');
+ } catch (ItemUnknownException $e) {
+ }
$done = true;
foreach ($cache->getItems() as $item) {