2018-09-28 11:41:24 +00:00
|
|
|
<?php
|
2022-04-15 11:34:01 +00:00
|
|
|
|
2018-09-28 11:41:24 +00:00
|
|
|
declare(strict_types=1);
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Nextcloud - Social Support
|
|
|
|
*
|
|
|
|
* This file is licensed under the Affero General Public License version 3 or
|
|
|
|
* later. See the COPYING file.
|
|
|
|
*
|
|
|
|
* @author Maxence Lange <maxence@artificial-owl.com>
|
|
|
|
* @copyright 2018, Maxence Lange <maxence@artificial-owl.com>
|
|
|
|
* @license GNU AGPL version 3 or any later version
|
|
|
|
*
|
|
|
|
* This program is free software: you can redistribute it and/or modify
|
|
|
|
* it under the terms of the GNU Affero General Public License as
|
|
|
|
* published by the Free Software Foundation, either version 3 of the
|
|
|
|
* License, or (at your option) any later version.
|
|
|
|
*
|
|
|
|
* This program is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
* GNU Affero General Public License for more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU Affero General Public License
|
|
|
|
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
|
|
|
*
|
|
|
|
*/
|
|
|
|
|
2018-11-12 22:55:10 +00:00
|
|
|
|
2019-01-21 16:26:01 +00:00
|
|
|
namespace OCA\Social\Model\ActivityPub\Object;
|
2018-09-28 11:41:24 +00:00
|
|
|
|
|
|
|
use JsonSerializable;
|
2018-12-13 09:40:27 +00:00
|
|
|
use OCA\Social\Model\ActivityPub\ACore;
|
2023-05-25 20:45:28 +00:00
|
|
|
use OCA\Social\Tools\IQueryRow;
|
2018-09-28 11:41:24 +00:00
|
|
|
|
2018-11-12 22:55:10 +00:00
|
|
|
/**
|
|
|
|
* Class Follow
|
|
|
|
*
|
2019-01-21 16:26:01 +00:00
|
|
|
* @package OCA\Social\Model\ActivityPub\Object
|
2018-11-12 22:55:10 +00:00
|
|
|
*/
|
2020-10-14 11:23:32 +00:00
|
|
|
class Follow extends ACore implements JsonSerializable, IQueryRow {
|
2022-04-15 11:34:01 +00:00
|
|
|
public const TYPE = 'Follow';
|
2018-11-19 10:34:54 +00:00
|
|
|
|
2022-04-15 11:01:18 +00:00
|
|
|
private string $followId = '';
|
|
|
|
private string $followIdPrim = '';
|
|
|
|
private bool $accepted = false;
|
2018-12-04 23:49:17 +00:00
|
|
|
|
2018-09-28 11:41:24 +00:00
|
|
|
/**
|
2018-11-19 10:34:54 +00:00
|
|
|
* Follow constructor.
|
2018-09-28 11:41:24 +00:00
|
|
|
*
|
2018-11-19 10:34:54 +00:00
|
|
|
* @param ACore $parent
|
2018-09-28 11:41:24 +00:00
|
|
|
*/
|
2018-11-19 10:34:54 +00:00
|
|
|
public function __construct($parent = null) {
|
|
|
|
parent::__construct($parent);
|
2018-09-28 11:41:24 +00:00
|
|
|
|
2018-11-19 10:34:54 +00:00
|
|
|
$this->setType(self::TYPE);
|
2018-11-12 22:55:10 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2018-11-21 19:22:09 +00:00
|
|
|
/**
|
|
|
|
* @return string
|
|
|
|
*/
|
|
|
|
public function getFollowId(): string {
|
|
|
|
return $this->followId;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @param string $followId
|
|
|
|
*
|
|
|
|
* @return Follow
|
|
|
|
*/
|
|
|
|
public function setFollowId(string $followId): Follow {
|
|
|
|
$this->followId = $followId;
|
|
|
|
|
|
|
|
return $this;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2019-09-16 18:34:55 +00:00
|
|
|
/**
|
|
|
|
* @return string
|
|
|
|
*/
|
|
|
|
public function getFollowIdPrim(): string {
|
|
|
|
return $this->followIdPrim;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @param string $followIdPrim
|
|
|
|
*
|
|
|
|
* @return Follow
|
|
|
|
*/
|
|
|
|
public function setFollowIdPrim(string $followIdPrim): Follow {
|
|
|
|
$this->followIdPrim = $followIdPrim;
|
|
|
|
|
|
|
|
return $this;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2018-12-04 23:49:17 +00:00
|
|
|
/**
|
|
|
|
* @return bool
|
|
|
|
*/
|
|
|
|
public function isAccepted(): bool {
|
|
|
|
return $this->accepted;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @param bool $accepted
|
|
|
|
*
|
|
|
|
* @return Follow
|
|
|
|
*/
|
|
|
|
public function setAccepted(bool $accepted): Follow {
|
|
|
|
$this->accepted = $accepted;
|
|
|
|
|
|
|
|
return $this;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2018-11-12 22:55:10 +00:00
|
|
|
/**
|
|
|
|
* @param array $data
|
|
|
|
*/
|
|
|
|
public function import(array $data) {
|
|
|
|
parent::import($data);
|
2018-09-28 11:41:24 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2018-11-30 10:54:48 +00:00
|
|
|
/**
|
|
|
|
* @param array $data
|
|
|
|
*/
|
|
|
|
public function importFromDatabase(array $data) {
|
|
|
|
parent::importFromDatabase($data);
|
|
|
|
|
2018-12-04 23:49:17 +00:00
|
|
|
$this->setAccepted(($this->getInt('accepted', $data, 0) === 1) ? true : false);
|
2018-11-30 10:54:48 +00:00
|
|
|
$this->setFollowId($this->get('follow_id', $data, ''));
|
2019-09-16 18:34:55 +00:00
|
|
|
$this->setFollowIdPrim($this->get('follow_id_prim', $data, ''));
|
2018-11-30 10:54:48 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2018-09-28 11:41:24 +00:00
|
|
|
/**
|
|
|
|
* @return array
|
|
|
|
*/
|
|
|
|
public function jsonSerialize(): array {
|
2018-12-19 01:13:33 +00:00
|
|
|
$result = parent::jsonSerialize();
|
|
|
|
|
|
|
|
if ($this->isCompleteDetails()) {
|
2019-05-17 14:33:35 +00:00
|
|
|
$result = array_merge(
|
2018-12-19 01:13:33 +00:00
|
|
|
$result,
|
|
|
|
[
|
2022-04-15 11:34:01 +00:00
|
|
|
'follow_id' => $this->getFollowId(),
|
2019-09-16 18:34:55 +00:00
|
|
|
'follow_id_prim' => $this->getFollowIdPrim(),
|
2022-04-15 11:34:01 +00:00
|
|
|
'accepted' => $this->isAccepted()
|
2018-12-19 01:13:33 +00:00
|
|
|
]
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
|
|
|
return $result;
|
2018-09-28 11:41:24 +00:00
|
|
|
}
|
|
|
|
}
|