summaryrefslogtreecommitdiffstats
path: root/lib/Service
diff options
context:
space:
mode:
authorMaxence Lange <maxence@artificial-owl.com>2019-04-08 20:36:40 -0100
committerMaxence Lange <maxence@artificial-owl.com>2019-05-03 16:31:15 -0100
commit0f714cfda1fae9c8c1d9703fd7cc1a1070b5b1b2 (patch)
treeddf0d11d97439506c6c5a2ff6c38a2a2522508e4 /lib/Service
parenta39d22353532703403ae2c15012c8bac68e939ca (diff)
cleaning Actions
Signed-off-by: Maxence Lange <maxence@artificial-owl.com>
Diffstat (limited to 'lib/Service')
-rw-r--r--lib/Service/BoostService.php4
-rw-r--r--lib/Service/StreamActionService.php38
2 files changed, 38 insertions, 4 deletions
diff --git a/lib/Service/BoostService.php b/lib/Service/BoostService.php
index 829bc3e1..7a16bd27 100644
--- a/lib/Service/BoostService.php
+++ b/lib/Service/BoostService.php
@@ -133,7 +133,7 @@ class BoostService {
$this->notesRequest->save($announce);
- $this->streamActionService->setActionBool($actor->getActorId(), $postId, 'boosted', true);
+ $this->streamActionService->setActionBool($actor->getId(), $postId, 'boosted', true);
$this->signatureService->signObject($actor, $announce);
$token = $this->activityService->request($announce);
@@ -182,7 +182,7 @@ class BoostService {
$undo->setCcArray($announce->getCcArray());
$this->notesRequest->deleteNoteById($announce->getId());
- $this->streamActionService->setActionBool($actor->getActorId(), $postId, 'boosted', false);
+ $this->streamActionService->setActionBool($actor->getId(), $postId, 'boosted', false);
$this->signatureService->signObject($actor, $undo);
$token = $this->activityService->request($undo);
diff --git a/lib/Service/StreamActionService.php b/lib/Service/StreamActionService.php
index 978b9952..55bab13d 100644
--- a/lib/Service/StreamActionService.php
+++ b/lib/Service/StreamActionService.php
@@ -45,12 +45,14 @@ use OCA\Social\Exceptions\RequestResultNotJsonException;
use OCA\Social\Exceptions\RequestResultSizeException;
use OCA\Social\Exceptions\RequestServerException;
use OCA\Social\Exceptions\SocialAppConfigException;
+use OCA\Social\Exceptions\StreamActionDoesNotExistException;
use OCA\Social\Model\ActivityPub\ACore;
use OCA\Social\Model\ActivityPub\Actor\Person;
use OCA\Social\Model\ActivityPub\Object\Announce;
use OCA\Social\Model\ActivityPub\Object\Note;
use OCA\Social\Model\ActivityPub\Stream;
use OCA\Social\Model\InstancePath;
+use OCA\Social\Model\StreamAction;
/**
@@ -88,7 +90,9 @@ class StreamActionService {
* @param string $value
*/
public function setAction(string $actorId, string $streamId, string $key, string $value) {
-
+ $action = $this->loadAction($actorId, $streamId);
+ $action->updateValue($key, $value);
+ $this->saveAction($action);
}
@@ -99,7 +103,9 @@ class StreamActionService {
* @param int $value
*/
public function setActionInt(string $actorId, string $streamId, string $key, int $value) {
-
+ $action = $this->loadAction($actorId, $streamId);
+ $action->updateValueInt($key, $value);
+ $this->saveAction($action);
}
@@ -110,8 +116,36 @@ class StreamActionService {
* @param bool $value
*/
public function setActionBool(string $actorId, string $streamId, string $key, bool $value) {
+ $action = $this->loadAction($actorId, $streamId);
+ $action->updateValueBool($key, $value);
+ $this->saveAction($action);
+ }
+
+ /**
+ * @param string $actorId
+ * @param string $streamId
+ *
+ * @return StreamAction
+ */
+ private function loadAction(string $actorId, string $streamId): StreamAction {
+ try {
+ $action = $this->streamActionsRequest->getAction($actorId, $streamId);
+ } catch (StreamActionDoesNotExistException $e) {
+ $action = new StreamAction($actorId, $streamId);
+ }
+
+ return $action;
}
+
+ /**
+ * @param StreamAction $action
+ */
+ private function saveAction(StreamAction $action) {
+ if ($this->streamActionsRequest->update($action) === 0) {
+ $this->streamActionsRequest->create($action);
+ }
+ }
}