cleaning Actions

Signed-off-by: Maxence Lange <maxence@artificial-owl.com>
pull/462/head
Maxence Lange 2019-04-08 20:36:40 -01:00
rodzic a39d223535
commit 0f714cfda1
5 zmienionych plików z 68 dodań i 10 usunięć

Wyświetl plik

@ -171,7 +171,7 @@ class CoreRequestBuilder {
* @param string $streamId
*/
protected function limitToStreamId(IQueryBuilder &$qb, string $streamId) {
$this->limitToDBField($qb, 'user_id', $streamId, false);
$this->limitToDBField($qb, 'stream_id', $streamId, false);
}

Wyświetl plik

@ -66,8 +66,10 @@ class StreamActionsRequest extends StreamActionsRequestBuilder {
* create a new Queue in the database.
*
* @param StreamAction $action
*
* @return int
*/
public function update(StreamAction $action) {
public function update(StreamAction $action): int {
$qb = $this->getStreamActionUpdateSql();
$values = json_encode($action->getValues(), JSON_UNESCAPED_SLASHES);
@ -76,7 +78,7 @@ class StreamActionsRequest extends StreamActionsRequestBuilder {
$this->limitToActorId($qb, $action->getActorId());
$this->limitToStreamId($qb, $action->getStreamId());
$qb->execute();
return $qb->execute();
}
@ -88,7 +90,7 @@ class StreamActionsRequest extends StreamActionsRequestBuilder {
* @throws StreamActionDoesNotExistException
*/
public function getAction(string $actorId, string $streamId): StreamAction {
$qb = $this->getStreamActionDeleteSql();
$qb = $this->getStreamActionSelectSql();
$this->limitToActorId($qb, $actorId);
$this->limitToStreamId($qb, $streamId);

Wyświetl plik

@ -63,8 +63,13 @@ class StreamAction implements JsonSerializable {
/**
* StreamAction constructor.
*
* @param string $actorId
* @param string $streamId
*/
public function __construct() {
public function __construct(string $actorId = '', string $streamId = '') {
$this->actorId = $actorId;
$this->streamId = $streamId;
}
@ -141,6 +146,14 @@ class StreamAction implements JsonSerializable {
$this->values[$key] = $value;
}
/**
* @param string $key
* @param bool $value
*/
public function updateValueBool(string $key, bool $value) {
$this->values[$key] = $value;
}
/**
* @param string $key
*
@ -168,6 +181,15 @@ class StreamAction implements JsonSerializable {
return $this->values[$key];
}
/**
* @param string $key
*
* @return bool
*/
public function getValueBool(string $key): bool {
return $this->values[$key];
}
/**
* @return array
*/

Wyświetl plik

@ -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);

Wyświetl plik

@ -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);
}
}
}