2020-09-03 18:49:55 +00:00
|
|
|
<?php
|
2022-04-15 11:34:01 +00:00
|
|
|
|
2020-09-03 18:49:55 +00:00
|
|
|
declare(strict_types=1);
|
|
|
|
|
|
|
|
/**
|
2024-09-08 13:46:22 +00:00
|
|
|
* SPDX-FileCopyrightText: 2018 Nextcloud GmbH and Nextcloud contributors
|
|
|
|
* SPDX-License-Identifier: AGPL-3.0-or-later
|
2020-09-03 18:49:55 +00:00
|
|
|
*/
|
|
|
|
|
|
|
|
namespace OCA\Social\Model\Client\Options;
|
|
|
|
|
|
|
|
use JsonSerializable;
|
2022-11-04 13:46:23 +00:00
|
|
|
use OCA\Social\Tools\Traits\TArrayTools;
|
2020-09-03 18:49:55 +00:00
|
|
|
use OCP\IRequest;
|
|
|
|
|
|
|
|
/**
|
2023-03-08 01:17:31 +00:00
|
|
|
* Class ProbeOptions
|
2020-09-03 18:49:55 +00:00
|
|
|
*
|
|
|
|
* @package OCA\Social\Model\Client\Options
|
|
|
|
*/
|
2023-03-08 01:17:31 +00:00
|
|
|
class ProbeOptions extends CoreOptions implements JsonSerializable {
|
2020-09-03 18:49:55 +00:00
|
|
|
use TArrayTools;
|
|
|
|
|
2023-03-08 01:17:31 +00:00
|
|
|
public const HOME = 'home';
|
|
|
|
public const PUBLIC = 'public';
|
|
|
|
public const DIRECT = 'direct';
|
|
|
|
public const ACCOUNT = 'account';
|
|
|
|
public const FAVOURITES = 'favourites';
|
|
|
|
public const HASHTAG = 'hashtag';
|
|
|
|
public const NOTIFICATIONS = 'notifications';
|
2022-12-03 16:55:34 +00:00
|
|
|
|
2023-03-08 01:17:31 +00:00
|
|
|
public const FOLLOWERS = 'followers';
|
|
|
|
public const FOLLOWING = 'following';
|
|
|
|
|
|
|
|
private string $probe = '';
|
2022-04-15 11:01:18 +00:00
|
|
|
private bool $local = false;
|
|
|
|
private bool $remote = false;
|
|
|
|
private bool $onlyMedia = false;
|
|
|
|
private int $minId = 0;
|
|
|
|
private int $maxId = 0;
|
2022-12-03 16:55:34 +00:00
|
|
|
private int $since = 0;
|
2022-04-15 11:01:18 +00:00
|
|
|
private int $limit = 20;
|
|
|
|
private bool $inverted = false;
|
2022-12-03 16:55:34 +00:00
|
|
|
private string $argument = '';
|
|
|
|
private array $types = [];
|
|
|
|
private array $excludeTypes = [];
|
|
|
|
private string $accountId = '';
|
2020-09-03 18:49:55 +00:00
|
|
|
|
2022-11-04 13:46:23 +00:00
|
|
|
|
2020-09-03 18:49:55 +00:00
|
|
|
/**
|
2023-03-08 01:17:31 +00:00
|
|
|
* ProbeOptions constructor.
|
2020-09-03 18:49:55 +00:00
|
|
|
*
|
|
|
|
* @param IRequest|null $request
|
|
|
|
*/
|
2024-10-28 12:53:06 +00:00
|
|
|
public function __construct(?IRequest $request = null) {
|
2020-09-03 18:49:55 +00:00
|
|
|
if ($request !== null) {
|
|
|
|
$this->fromArray($request->getParams());
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @return string
|
|
|
|
*/
|
2023-03-08 01:17:31 +00:00
|
|
|
public function getProbe(): string {
|
|
|
|
return $this->probe;
|
2020-09-03 18:49:55 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2023-03-08 01:17:31 +00:00
|
|
|
* @param string $probe
|
2020-09-03 18:49:55 +00:00
|
|
|
*
|
2023-03-08 01:17:31 +00:00
|
|
|
* @return ProbeOptions
|
2020-09-03 18:49:55 +00:00
|
|
|
*/
|
2023-03-08 01:17:31 +00:00
|
|
|
public function setProbe(string $probe): self {
|
|
|
|
$this->probe = strtolower($probe);
|
2020-09-03 18:49:55 +00:00
|
|
|
|
|
|
|
return $this;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @return bool
|
|
|
|
*/
|
|
|
|
public function isLocal(): bool {
|
|
|
|
return $this->local;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @param bool $local
|
|
|
|
*
|
2023-03-08 01:17:31 +00:00
|
|
|
* @return ProbeOptions
|
2020-09-03 18:49:55 +00:00
|
|
|
*/
|
|
|
|
public function setLocal(bool $local): self {
|
|
|
|
$this->local = $local;
|
|
|
|
|
|
|
|
return $this;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @return bool
|
|
|
|
*/
|
|
|
|
public function isRemote(): bool {
|
|
|
|
return $this->remote;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @param bool $remote
|
|
|
|
*
|
2023-03-08 01:17:31 +00:00
|
|
|
* @return ProbeOptions
|
2020-09-03 18:49:55 +00:00
|
|
|
*/
|
|
|
|
public function setRemote(bool $remote): self {
|
|
|
|
$this->remote = $remote;
|
|
|
|
|
|
|
|
return $this;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @return bool
|
|
|
|
*/
|
|
|
|
public function isOnlyMedia(): bool {
|
|
|
|
return $this->onlyMedia;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @param bool $onlyMedia
|
|
|
|
*
|
2023-03-08 01:17:31 +00:00
|
|
|
* @return ProbeOptions
|
2020-09-03 18:49:55 +00:00
|
|
|
*/
|
|
|
|
public function setOnlyMedia(bool $onlyMedia): self {
|
|
|
|
$this->onlyMedia = $onlyMedia;
|
|
|
|
|
|
|
|
return $this;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @return int
|
|
|
|
*/
|
|
|
|
public function getMinId(): int {
|
|
|
|
return $this->minId;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @param int $minId
|
|
|
|
*
|
2023-03-08 01:17:31 +00:00
|
|
|
* @return ProbeOptions
|
2020-09-03 18:49:55 +00:00
|
|
|
*/
|
|
|
|
public function setMinId(int $minId): self {
|
|
|
|
$this->minId = $minId;
|
|
|
|
|
|
|
|
return $this;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @return int
|
|
|
|
*/
|
|
|
|
public function getMaxId(): int {
|
|
|
|
return $this->maxId;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @param int $maxId
|
|
|
|
*
|
2023-03-08 01:17:31 +00:00
|
|
|
* @return ProbeOptions
|
2020-09-03 18:49:55 +00:00
|
|
|
*/
|
|
|
|
public function setMaxId(int $maxId): self {
|
|
|
|
$this->maxId = $maxId;
|
|
|
|
|
|
|
|
return $this;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @return int
|
|
|
|
*/
|
2022-12-03 16:55:34 +00:00
|
|
|
public function getSince(): int {
|
|
|
|
return $this->since;
|
2020-09-03 18:49:55 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2022-12-03 16:55:34 +00:00
|
|
|
* @param int $since
|
2020-09-03 18:49:55 +00:00
|
|
|
*
|
2023-03-08 01:17:31 +00:00
|
|
|
* @return ProbeOptions
|
2020-09-03 18:49:55 +00:00
|
|
|
*/
|
2022-12-03 16:55:34 +00:00
|
|
|
public function setSince(int $since): self {
|
|
|
|
$this->since = $since;
|
2020-09-03 18:49:55 +00:00
|
|
|
|
|
|
|
return $this;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @return int
|
|
|
|
*/
|
|
|
|
public function getLimit(): int {
|
|
|
|
return $this->limit;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @param int $limit
|
|
|
|
*
|
2023-03-08 01:17:31 +00:00
|
|
|
* @return ProbeOptions
|
2020-09-03 18:49:55 +00:00
|
|
|
*/
|
|
|
|
public function setLimit(int $limit): self {
|
|
|
|
$this->limit = $limit;
|
|
|
|
|
|
|
|
return $this;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @return bool
|
|
|
|
*/
|
|
|
|
public function isInverted(): bool {
|
|
|
|
return $this->inverted;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @param bool $inverted
|
|
|
|
*
|
2023-03-08 01:17:31 +00:00
|
|
|
* @return ProbeOptions
|
2020-09-03 18:49:55 +00:00
|
|
|
*/
|
|
|
|
public function setInverted(bool $inverted): self {
|
|
|
|
$this->inverted = $inverted;
|
|
|
|
|
|
|
|
return $this;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2022-12-03 16:55:34 +00:00
|
|
|
/**
|
|
|
|
* @param string $argument
|
|
|
|
*
|
2023-03-08 01:17:31 +00:00
|
|
|
* @return ProbeOptions
|
2022-12-03 16:55:34 +00:00
|
|
|
*/
|
|
|
|
public function setArgument(string $argument): self {
|
|
|
|
$this->argument = $argument;
|
|
|
|
|
|
|
|
return $this;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @return string
|
|
|
|
*/
|
|
|
|
public function getArgument(): string {
|
|
|
|
return $this->argument;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @param array $types
|
|
|
|
*
|
2023-03-08 01:17:31 +00:00
|
|
|
* @return ProbeOptions
|
2022-12-03 16:55:34 +00:00
|
|
|
*/
|
|
|
|
public function setTypes(array $types): self {
|
|
|
|
$this->types = $types;
|
|
|
|
|
|
|
|
return $this;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @return array
|
|
|
|
*/
|
|
|
|
public function getTypes(): array {
|
|
|
|
return $this->types;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @param array $excludeTypes
|
|
|
|
*
|
2023-03-08 01:17:31 +00:00
|
|
|
* @return ProbeOptions
|
2022-12-03 16:55:34 +00:00
|
|
|
*/
|
|
|
|
public function setExcludeTypes(array $excludeTypes): self {
|
|
|
|
$this->excludeTypes = $excludeTypes;
|
|
|
|
|
|
|
|
return $this;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @return array
|
|
|
|
*/
|
|
|
|
public function getExcludeTypes(): array {
|
|
|
|
return $this->excludeTypes;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @param string $accountId
|
|
|
|
*
|
2023-03-08 01:17:31 +00:00
|
|
|
* @return ProbeOptions
|
2022-12-03 16:55:34 +00:00
|
|
|
*/
|
|
|
|
public function setAccountId(string $accountId): self {
|
|
|
|
$this->accountId = $accountId;
|
|
|
|
|
|
|
|
return $this;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @return string
|
|
|
|
*/
|
|
|
|
public function getAccountId(): string {
|
|
|
|
return $this->accountId;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2020-09-03 18:49:55 +00:00
|
|
|
/**
|
|
|
|
* @param array $arr
|
|
|
|
*
|
2023-03-08 01:17:31 +00:00
|
|
|
* @return ProbeOptions
|
2020-09-03 18:49:55 +00:00
|
|
|
*/
|
|
|
|
public function fromArray(array $arr): self {
|
|
|
|
$this->setLocal($this->getBool('local', $arr, $this->isLocal()));
|
|
|
|
$this->setRemote($this->getBool('remote', $arr, $this->isRemote()));
|
2023-01-16 16:19:26 +00:00
|
|
|
$this->setOnlyMedia($this->getBool('only_media', $arr, $this->isOnlyMedia()));
|
2020-09-03 18:49:55 +00:00
|
|
|
$this->setMinId($this->getInt('min_id', $arr, $this->getMinId()));
|
|
|
|
$this->setMaxId($this->getInt('max_id', $arr, $this->getMaxId()));
|
2022-12-03 16:55:34 +00:00
|
|
|
$this->setSince($this->getInt('since', $arr, $this->getSince()));
|
2020-09-03 18:49:55 +00:00
|
|
|
$this->setLimit($this->getInt('limit', $arr, $this->getLimit()));
|
2022-12-03 16:55:34 +00:00
|
|
|
$this->setArgument($this->get('argument', $arr, $this->getArgument()));
|
2020-09-03 18:49:55 +00:00
|
|
|
|
|
|
|
return $this;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @return array
|
|
|
|
*/
|
|
|
|
public function jsonSerialize(): array {
|
|
|
|
return
|
|
|
|
[
|
2023-03-08 01:17:31 +00:00
|
|
|
'probe' => $this->getProbe(),
|
2023-01-16 16:19:26 +00:00
|
|
|
'accountId' => $this->getAccountId(),
|
2022-04-15 11:34:01 +00:00
|
|
|
'local' => $this->isLocal(),
|
|
|
|
'remote' => $this->isRemote(),
|
2020-09-03 18:49:55 +00:00
|
|
|
'only_media' => $this->isOnlyMedia(),
|
2022-04-15 11:34:01 +00:00
|
|
|
'min_id' => $this->getMinId(),
|
|
|
|
'max_id' => $this->getMaxId(),
|
2022-12-03 16:55:34 +00:00
|
|
|
'since' => $this->getSince(),
|
|
|
|
'limit' => $this->getLimit(),
|
|
|
|
'argument' => $this->getArgument()
|
2020-09-03 18:49:55 +00:00
|
|
|
];
|
|
|
|
}
|
|
|
|
}
|