2018-09-28 11:41:24 +00:00
|
|
|
<?php
|
|
|
|
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/>.
|
|
|
|
*
|
|
|
|
*/
|
|
|
|
|
|
|
|
namespace OCA\Social\Model\ActivityPub;
|
|
|
|
|
|
|
|
|
2018-11-16 10:47:59 +00:00
|
|
|
use DateTime;
|
2018-09-28 11:41:24 +00:00
|
|
|
use JsonSerializable;
|
2018-11-16 10:47:59 +00:00
|
|
|
use OCA\Social\Service\ActivityService;
|
2018-09-28 11:41:24 +00:00
|
|
|
|
2018-11-12 22:55:10 +00:00
|
|
|
class Note extends ACore implements JsonSerializable {
|
2018-09-28 11:41:24 +00:00
|
|
|
|
|
|
|
|
|
|
|
/** @var string */
|
|
|
|
private $content;
|
|
|
|
|
|
|
|
/** @var string */
|
2018-11-12 22:55:10 +00:00
|
|
|
private $attributedTo;
|
2018-09-28 11:41:24 +00:00
|
|
|
|
|
|
|
/** @var string */
|
2018-11-12 22:55:10 +00:00
|
|
|
private $inReplyTo = '';
|
2018-09-28 11:41:24 +00:00
|
|
|
|
2018-11-12 22:55:10 +00:00
|
|
|
/** @var bool */
|
|
|
|
private $sensitive = false;
|
2018-09-28 11:41:24 +00:00
|
|
|
|
|
|
|
/** @var string */
|
2018-11-12 22:55:10 +00:00
|
|
|
private $conversation = '';
|
2018-09-28 11:41:24 +00:00
|
|
|
|
2018-11-16 10:47:59 +00:00
|
|
|
/** @var int */
|
|
|
|
private $publishedTime;
|
|
|
|
|
2018-09-28 11:41:24 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Note constructor.
|
|
|
|
*
|
|
|
|
* @param bool $isTopLevel
|
|
|
|
*/
|
|
|
|
public function __construct(bool $isTopLevel = false) {
|
|
|
|
parent::__construct($isTopLevel);
|
|
|
|
|
|
|
|
$this->setType('Note');
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @return string
|
|
|
|
*/
|
|
|
|
public function getContent(): string {
|
|
|
|
return $this->content;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @param string $content
|
|
|
|
*
|
|
|
|
* @return Note
|
|
|
|
*/
|
|
|
|
public function setContent(string $content): Note {
|
|
|
|
$this->content = $content;
|
|
|
|
|
|
|
|
return $this;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @return string
|
|
|
|
*/
|
2018-11-12 22:55:10 +00:00
|
|
|
public function getAttributedTo(): string {
|
|
|
|
return $this->attributedTo;
|
2018-09-28 11:41:24 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2018-11-12 22:55:10 +00:00
|
|
|
* @param string $attributedTo
|
2018-09-28 11:41:24 +00:00
|
|
|
*
|
|
|
|
* @return Note
|
|
|
|
*/
|
2018-11-12 22:55:10 +00:00
|
|
|
public function setAttributedTo(string $attributedTo): Note {
|
|
|
|
$this->attributedTo = $attributedTo;
|
2018-09-28 11:41:24 +00:00
|
|
|
|
|
|
|
return $this;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @return string
|
|
|
|
*/
|
2018-11-12 22:55:10 +00:00
|
|
|
public function getInReplyTo(): string {
|
|
|
|
return $this->inReplyTo;
|
2018-09-28 11:41:24 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2018-11-12 22:55:10 +00:00
|
|
|
* @param string $inReplyTo
|
2018-09-28 11:41:24 +00:00
|
|
|
*
|
|
|
|
* @return Note
|
|
|
|
*/
|
2018-11-12 22:55:10 +00:00
|
|
|
public function setInReplyTo(string $inReplyTo): Note {
|
|
|
|
$this->inReplyTo = $inReplyTo;
|
2018-09-28 11:41:24 +00:00
|
|
|
|
|
|
|
return $this;
|
|
|
|
}
|
|
|
|
|
2018-11-12 22:55:10 +00:00
|
|
|
|
2018-09-28 11:41:24 +00:00
|
|
|
/**
|
2018-11-12 22:55:10 +00:00
|
|
|
* @return bool
|
2018-09-28 11:41:24 +00:00
|
|
|
*/
|
2018-11-12 22:55:10 +00:00
|
|
|
public function isSensitive(): bool {
|
|
|
|
return $this->sensitive;
|
2018-09-28 11:41:24 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2018-11-12 22:55:10 +00:00
|
|
|
* @param bool $sensitive
|
2018-09-28 11:41:24 +00:00
|
|
|
*
|
|
|
|
* @return Note
|
|
|
|
*/
|
2018-11-12 22:55:10 +00:00
|
|
|
public function setSensitive(bool $sensitive): Note {
|
|
|
|
$this->sensitive = $sensitive;
|
2018-09-28 11:41:24 +00:00
|
|
|
|
|
|
|
return $this;
|
|
|
|
}
|
|
|
|
|
2018-11-12 22:55:10 +00:00
|
|
|
|
2018-09-28 11:41:24 +00:00
|
|
|
/**
|
|
|
|
* @return string
|
|
|
|
*/
|
2018-11-12 22:55:10 +00:00
|
|
|
public function getConversation(): string {
|
|
|
|
return $this->conversation;
|
2018-09-28 11:41:24 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2018-11-12 22:55:10 +00:00
|
|
|
* @param string $conversation
|
2018-09-28 11:41:24 +00:00
|
|
|
*
|
|
|
|
* @return Note
|
|
|
|
*/
|
2018-11-12 22:55:10 +00:00
|
|
|
public function setConversation(string $conversation): Note {
|
|
|
|
$this->conversation = $conversation;
|
2018-09-28 11:41:24 +00:00
|
|
|
|
|
|
|
return $this;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2018-11-16 10:47:59 +00:00
|
|
|
/**
|
|
|
|
* @return int
|
|
|
|
*/
|
|
|
|
public function getPublishedTime(): int {
|
|
|
|
return $this->publishedTime;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @param int $time
|
|
|
|
*
|
|
|
|
* @return Note
|
|
|
|
*/
|
|
|
|
public function setPublishedTime(int $time): Note {
|
|
|
|
$this->publishedTime = $time;
|
|
|
|
|
|
|
|
return $this;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
*
|
|
|
|
*/
|
|
|
|
public function convertPublished() {
|
|
|
|
$dTime = new DateTime($this->getPublished());
|
|
|
|
$dTime->format(ActivityService::DATE_FORMAT);
|
|
|
|
$this->publishedTime = $dTime->getTimestamp();
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2018-11-12 22:55:10 +00:00
|
|
|
/**
|
|
|
|
* @param array $data
|
|
|
|
*/
|
|
|
|
public function import(array $data) {
|
|
|
|
parent::import($data);
|
|
|
|
|
|
|
|
$this->setSummary($this->get('summary', $data, ''));
|
|
|
|
$this->setInReplyTo($this->get('inReplyTo', $data, ''));
|
|
|
|
$this->setAttributedTo($this->get('attributedTo', $data, ''));
|
|
|
|
$this->setSensitive($this->getBool('sensitive', $data, false));
|
|
|
|
$this->setConversation($this->get('conversation', $data, ''));
|
|
|
|
$this->setContent($this->get('content', $data, ''));
|
2018-11-16 10:47:59 +00:00
|
|
|
$this->convertPublished();
|
2018-11-12 22:55:10 +00:00
|
|
|
}
|
2018-09-28 11:41:24 +00:00
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @return array
|
|
|
|
*/
|
|
|
|
public function jsonSerialize(): array {
|
|
|
|
return array_merge(
|
|
|
|
parent::jsonSerialize(),
|
|
|
|
[
|
2018-11-16 10:47:59 +00:00
|
|
|
'content' => $this->getContent(),
|
|
|
|
'publishedTime' => $this->getPublishedTime(),
|
|
|
|
'attributedTo' => $this->getRoot() . $this->getAttributedTo(),
|
|
|
|
'inReplyTo' => $this->getInReplyTo(),
|
|
|
|
'sensitive' => $this->isSensitive(),
|
|
|
|
'conversation' => $this->getConversation()
|
2018-09-28 11:41:24 +00:00
|
|
|
]
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|