Exception & models

Signed-off-by: Maxence Lange <maxence@artificial-owl.com>
pull/20/head
Maxence Lange 2018-11-12 21:55:10 -01:00
rodzic 90c0c96990
commit 6b6c1f33c4
12 zmienionych plików z 1388 dodań i 652 usunięć

Wyświetl plik

@ -0,0 +1,8 @@
<?php
namespace OCA\Social\Exceptions;
class UnknownItemException extends \Exception {
}

Wyświetl plik

@ -0,0 +1,8 @@
<?php
namespace OCA\Social\Exceptions;
class WebfingerException extends \Exception {
}

Wyświetl plik

@ -0,0 +1,744 @@
<?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;
use daita\MySmallPhpTools\Traits\TArrayTools;
use JsonSerializable;
use OCA\Social\Model\InstancePath;
use OCA\Social\Service\ICoreService;
abstract class ACore implements JsonSerializable {
use TArrayTools;
const CONTEXT_ACTIVITYSTREAMS = 'https://www.w3.org/ns/activitystreams';
const CONTEXT_SECURITY = 'https://w3id.org/security/v1';
/** @var string */
private $root = '';
/** @var bool */
private $isTopLevel = false;
/** @var array */
private $meta = [];
/** @var string */
private $address = '';
/** @var string */
private $id = '';
/** @var string */
private $type = '';
/** @var string */
private $url = '';
/** @var string */
private $summary = '';
/** @var InstancePath[] */
private $instancePaths = [];
/** @var string */
private $to = '';
/** @var array */
private $toArray = [];
/** @var array */
private $cc = [];
/** @var array */
private $bcc = [];
/** @var string */
private $published = '';
/** @var array */
private $tags = [];
/** @var array */
private $entries = [];
/** @var Person */
private $actor = null;
/** @var string */
private $actorId = '';
/** @var ACore */
private $object = null;
/** @var string */
private $objectId = '';
/** @var ICoreService */
private $saveAs;
/**
* Core constructor.
*
* @param bool $isTopLevel
*/
public function __construct(bool $isTopLevel = false) {
$this->isTopLevel = $isTopLevel;
}
/**
* @return string
*/
public function getId(): string {
return $this->id;
}
/**
* @param string $id
*
* @return ACore
*/
public function setId(string $id): ACore {
$this->id = $id;
return $this;
}
/**
* @return string
*/
public function getType(): string {
return $this->type;
}
/**
* @param string $type
*
* @return ACore
*/
public function setType(string $type): ACore {
$this->type = $type;
return $this;
}
/**
* @param string $meta
* @param string $value
*
* @return ACore
*/
public function addMeta(string $meta, string $value): ACore {
$this->meta[$meta] = $value;
return $this;
}
/**
* @param string $meta
* @param string $value
*
* @return ACore
*/
public function addMetaBool(string $meta, bool $value): ACore {
$this->meta[$meta] = $value;
return $this;
}
/**
* @param string $meta
*
* @return string
*/
public function getMeta(string $meta): string {
return $this->get($meta, $this->meta, '');
}
/**
* @param string $meta
*
* @return bool
*/
public function getMetaBool(string $meta): bool {
return $this->getBool($meta, $this->meta, false);
}
/**
* @param array $meta
*
* @return ACore
*/
public function setMetaAll(array $meta): ACore {
$this->meta = $meta;
return $this;
}
/**
* @return array
*/
public function getMetaAll(): array {
return $this->meta;
}
/**
* @return string
*/
public function getUrl(): string {
return $this->url;
}
/**
* @param string $url
*
* @return ACore
*/
public function setUrl(string $url): ACore {
$this->url = $url;
return $this;
}
/**
* @param InstancePath $instancePath
*
* @return ACore
*/
public function addInstancePath(InstancePath $instancePath): ACore {
$this->instancePaths[] = $instancePath;
return $this;
}
/**
* @param InstancePath[] $path
*
* @return ACore
*/
public function addInstancePaths(array $path): ACore {
$this->instancePaths = array_merge($this->instancePaths, $path);
return $this;
}
/**
* @return InstancePath[]
*/
public function getInstancePaths(): array {
return $this->instancePaths;
}
/**
* @param InstancePath[] $instancePaths
*
* @return ACore
*/
public function setInstancePaths(array $instancePaths): ACore {
$this->instancePaths = $instancePaths;
return $this;
}
/**
* @return string
*/
public function getSummary(): string {
return $this->summary;
}
/**
* @param string $summary
*
* @return ACore
*/
public function setSummary(string $summary): ACore {
$this->summary = $summary;
return $this;
}
/**
* @return Person
*/
public function getActor(): Person {
return $this->actor;
}
/**
* @param Person $actor
*
* @return ACore
*/
public function setActor(Person $actor): ACore {
$this->actor = $actor;
return $this;
}
/**
* @return bool
*/
public function gotActor(): bool {
if ($this->actor === null) {
return false;
}
return true;
}
/**
* @param string $actorId
*
* @return ACore
*/
public function setActorId(string $actorId): ACore {
$this->actorId = $actorId;
return $this;
}
/**
* @return string
*/
public function getActorId(): string {
return $this->actorId;
}
/**
* @return string
*/
public function getRoot(): string {
return $this->root;
}
/**
* @param string $path
*
* @return ACore
*/
public function setRoot(string $path): ACore {
$this->root = $path;
return $this;
}
/**
* @return string
*/
public function getAddress(): string {
return $this->address;
}
/**
* @param string $address
*
* @return ACore
*/
public function setAddress(string $address) {
$this->address = $address;
return $this;
}
/**
* @return string
*/
public function getTo(): string {
return $this->to;
}
/**
* @param string $to
*
* @return ACore
*/
public function setTo(string $to): ACore {
$this->to = $to;
return $this;
}
/**
* @return array
*/
public function getToArray(): array {
return $this->toArray;
}
/**
* @param string $to
*
* @return ACore
*/
public function addToArray(string $to): ACore {
$this->toArray[] = $to;
return $this;
}
/**
* @param array $toArray
*
* @return ACore
*/
public function setToArray(array $toArray): ACore {
$this->toArray = $toArray;
return $this;
}
/**
* @return array
*/
public function getCcArray(): array {
return $this->cc;
}
/**
* @param array $cc
*
* @return ACore
*/
public function setCcArray(array $cc): ACore {
$this->cc = $cc;
return $this;
}
/**
* @return array
*/
public function getBccArray(): array {
return $this->bcc;
}
/**
* @param array $bcc
*
* @return ACore
*/
public function setBccArray(array $bcc): ACore {
$this->bcc = $bcc;
return $this;
}
/**
* @param string $published
*
* @return ACore
*/
public function setPublished(string $published): ACore {
$this->published = $published;
return $this;
}
/**
* @return string
*/
public function getPublished(): string {
return $this->published;
}
/**
* @param array $tag
*
* @return ACore
*/
public function addTag(array $tag): ACore {
$this->tags[] = $tag;
return $this;
}
/**
* @return array
*/
public function getTags(): array {
return $this->tags;
}
/**
* @param array $tag
*
* @return ACore
*/
public function setTags(array $tag): ACore {
$this->tags = $tag;
return $this;
}
/**
* @return bool
*/
public function gotObject(): bool {
if ($this->object === null) {
return false;
}
return true;
}
/**
* @return ACore
*/
public function getObject(): ACore {
return $this->object;
}
/**
* @param ACore $object
*
* @return ACore
*/
public function setObject(ACore $object): ACore {
$this->object = $object;
return $this;
}
/**
* @return string
*/
public function getObjectId(): string {
return $this->objectId;
}
/**
* @param string $objectId
*
* @return ACore
*/
public function setObjectId(string $objectId): ACore {
$this->objectId = $objectId;
return $this;
}
/**
* @param bool $topLevel
*
* @return ACore
*/
public function setTopLevel(bool $topLevel): ACore {
$this->isTopLevel = $topLevel;
return $this;
}
/**
* @return bool
*/
public function isTopLevel(): bool {
return $this->isTopLevel;
}
/**
* @param array $arr
*
* @return ACore
*/
public function setEntries(array $arr): ACore {
$this->entries = $arr;
return $this;
}
/**
* @return array
*/
public function getEntries(): array {
return $this->entries;
}
/**
* @param string $k
* @param string $v
*
* @return ACore
*/
public function addEntry(string $k, string $v): ACore {
if ($v === '') {
// unset($this->entries[$k]);
return $this;
}
$this->entries[$k] = $v;
return $this;
}
/**
* @param string $k
* @param array $v
*
* @return ACore
*/
public function addEntryArray(string $k, array $v): ACore {
if ($v === []) {
// unset($this->entries[$k]);
return $this;
}
$this->entries[$k] = $v;
return $this;
}
/**
* @param string $k
* @param ACore $v
*
* @return ACore
*/
public function addEntryItem(string $k, ACore $v): ACore {
if ($v === null) {
// unset($this->entries[$k]);
return $this;
}
$this->entries[$k] = $v;
return $this;
}
/**
* @param ICoreService $class
*/
public function saveAs(ICoreService $class) {
$this->saveAs = $class;
}
/**
* @return ICoreService
*/
public function savingAs() {
return $this->saveAs;
}
/**
* @param array $data
*/
public function import(array $data) {
$this->setId($this->get('id', $data, ''));
$this->setUrl($this->get('url', $data, ''));
$this->setSummary($this->get('summary', $data, ''));
$this->setToArray($this->getArray('to', $data, []));
$this->setCcArray($this->getArray('cc', $data, []));
$this->setPublished($this->get('published', $data, ''));
$this->setActorId($this->get('actor', $data, ''));
$this->setObjectId($this->get('object', $data, ''));
}
/**
* @return array
*/
public function jsonSerialize(): array {
if ($this->isTopLevel()) {
$this->addEntryArray(
'@context', [
self::CONTEXT_ACTIVITYSTREAMS,
self::CONTEXT_SECURITY
]
);
}
$this->addEntry('id', $this->getId());
$this->addEntry('type', $this->getType());
$this->addEntry('url', $this->getId());
$this->addEntry('to', $this->getTo());
$this->addEntryArray('to', $this->getToArray());
$this->addEntryArray('cc', $this->getCcArray());
if ($this->gotActor()) {
$this->addEntry(
'actor', $this->getActor()
->getId()
);
} else {
$this->addEntry('actor', $this->getActorId());
}
$this->addEntry('summary', $this->getSummary());
$this->addEntry('published', $this->getPublished());
$this->addEntryArray('tag', $this->getTags());
// $arr = $this->getEntries();
if ($this->gotObject()) {
$this->addEntryItem('object', $this->getObject());
} else {
$this->addEntry('object', $this->getObjectId());
}
return $this->getEntries();
}
}

Wyświetl plik

@ -32,11 +32,11 @@ namespace OCA\Social\Model\ActivityPub;
use JsonSerializable;
class ActivityCreate extends Core implements JsonSerializable {
class Activity extends ACore implements JsonSerializable {
/**
* ActivityCreate constructor.
* Activity constructor.
*
* @param bool $isTopLevel
*/
@ -47,6 +47,15 @@ class ActivityCreate extends Core implements JsonSerializable {
}
/**
* @param array $data
*/
public function import(array $data) {
parent::import($data);
$this->setActorId($this->get('actor', $data, ''));
}
/**
* @return array
*/

Wyświetl plik

@ -1,503 +0,0 @@
<?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;
use JsonSerializable;
use OCA\Social\Model\InstancePath;
use OCA\Social\Service\ICoreService;
class Core implements JsonSerializable {
/** @var string */
private $root = '';
/** @var bool */
private $isTopLevel = false;
/** @var string */
private $address = '';
/** @var string */
private $id = '';
/** @var string */
private $type;
/** @var InstancePath[] */
private $instancePaths = [];
/** @var string */
private $to = '';
/** @var array */
private $toArray = [];
/** @var array */
private $cc = [];
/** @var array */
private $bcc = [];
/** @var Actor */
private $actor;
/** @var array */
private $tags = [];
/** @var array */
private $entries = [];
/** @var Core */
private $object = null;
/** @var ICoreService */
private $saveAs;
/**
* Core constructor.
*
* @param bool $isTopLevel
*/
public function __construct(bool $isTopLevel = false) {
$this->isTopLevel = $isTopLevel;
}
/**
* @return string
*/
public function getId(): string {
return $this->id;
}
/**
* @param string $id
*
* @return Core
*/
public function setId(string $id): Core {
$this->id = $id;
return $this;
}
/**
* @return string
*/
public function getType(): string {
return $this->type;
}
/**
* @param string $type
*
* @return Core
*/
public function setType(string $type): Core {
$this->type = $type;
return $this;
}
/**
* @param InstancePath $instancePath
*
* @return Core
*/
public function addInstancePath(InstancePath $instancePath): Core {
$this->instancePaths[] = $instancePath;
return $this;
}
/**
* @param InstancePath[] $path
*
* @return Core
*/
public function addInstancePaths(array $path): Core {
$this->instancePaths = array_merge($this->instancePaths, $path);
return $this;
}
/**
* @return InstancePath[]
*/
public function getInstancePaths(): array {
return $this->instancePaths;
}
/**
* @param InstancePath[] $instancePaths
*
* @return Core
*/
public function setInstancePaths(array $instancePaths): Core {
$this->instancePaths = $instancePaths;
return $this;
}
/**
* @return Actor
*/
public function getActor(): Actor {
return $this->actor;
}
/**
* @param Actor $actor
*
* @return Core
*/
public function setActor(Actor $actor): Core {
$this->actor = $actor;
return $this;
}
/**
* @return bool
*/
public function gotActor(): bool {
if ($this->actor === null) {
return false;
}
return true;
}
/**
* @return string
*/
public function getRoot(): string {
return $this->root;
}
/**
* @param string $path
*
* @return Core
*/
public function setRoot(string $path): Core {
$this->root = $path;
return $this;
}
/**
* @return string
*/
public function getAddress(): string {
return $this->address;
}
/**
* @param string $address
*
* @return Core
*/
public function setAddress(string $address) {
$this->address = $address;
return $this;
}
/**
* @return string
*/
public function getTo(): string {
return $this->to;
}
/**
* @param string $to
*
* @return Core
*/
public function setTo(string $to): Core {
$this->to = $to;
return $this;
}
/**
* @return array
*/
public function getToArray(): array {
return $this->toArray;
}
/**
* @param string $to
*
* @return Core
*/
public function addToArray(string $to): Core {
$this->toArray[] = $to;
return $this;
}
/**
* @param array $toArray
*
* @return Core
*/
public function setToArray(array $toArray): Core {
$this->toArray = $toArray;
return $this;
}
/**
* @return array
*/
public function getCc(): array {
return $this->cc;
}
/**
* @param array $cc
*
* @return Core
*/
public function setCc(array $cc): Core {
$this->cc = $cc;
return $this;
}
/**
* @return array
*/
public function getBcc(): array {
return $this->bcc;
}
/**
* @param array $bcc
*
* @return Core
*/
public function setBcc(array $bcc): Core {
$this->bcc = $bcc;
return $this;
}
/**
* @param array $tag
*
* @return Core
*/
public function addTag(array $tag): Core {
$this->tags[] = $tag;
return $this;
}
/**
* @return array
*/
public function getTags(): array {
return $this->tags;
}
/**
* @param array $tag
*
* @return Core
*/
public function setTags(array $tag): Core {
$this->tags = $tag;
return $this;
}
/**
* @return bool
*/
public function gotObject(): bool {
if ($this->object === null) {
return false;
}
return true;
}
/**
* @return Core
*/
public function getObject(): Core {
return $this->object;
}
/**
* @param Core $object
*
* @return Core
*/
public function setObject(Core $object): Core {
$this->object = $object;
return $this;
}
/**
* @return bool
*/
public function isTopLevel(): bool {
return $this->isTopLevel;
}
/**
* @param array $arr
*
* @return Core
*/
public function setEntries(array $arr): Core {
$this->entries = $arr;
return $this;
}
/**
* @return array
*/
public function getEntries(): array {
return $this->entries;
}
/**
* @param string $k
* @param string $v
*
* @return Core
*/
public function addEntry(string $k, string $v): Core {
if ($v === '') {
unset($this->entries[$k]);
return $this;
}
$this->entries[$k] = $v;
return $this;
}
/**
* @param string $k
* @param array $v
*
* @return Core
*/
public function addEntryArray(string $k, array $v): Core {
$this->entries[$k] = $v;
return $this;
}
/**
* @param ICoreService $class
*/
public function saveAs(ICoreService $class) {
$this->saveAs = $class;
}
/**
* @return ICoreService
*/
public function savingAs() {
return $this->saveAs;
}
/**
* @return array
*/
public function jsonSerialize(): array {
$this->addEntry('id', $this->getId());
$this->addEntry('type', $this->getType());
$this->addEntry('url', $this->getId());
if ($this->getToArray() === []) {
$this->addEntry('to', $this->getTo());
} else {
$this->addEntryArray('to', $this->getToArray());
}
$this->addEntryArray('cc', $this->getCc());
if ($this->gotActor()) {
$this->addEntry(
'actor', $this->getActor()
->getId()
);
}
if ($this->getTags() !== []) {
$this->addEntryArray('tag', $this->getTags());
}
$arr = $this->getEntries();
if ($this->gotObject()) {
$arr['object'] = $this->getObject();
}
return $arr;
}
}

Wyświetl plik

@ -0,0 +1,77 @@
<?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;
use JsonSerializable;
/**
* Class Follow
*
* @package OCA\Social\Model\ActivityPub
*/
class Follow extends ACore implements JsonSerializable {
/**
* Activity constructor.
*
* @param bool $isTopLevel
*/
public function __construct(bool $isTopLevel = false) {
parent::__construct($isTopLevel);
$this->setType('Follow');
}
/**
* @param array $data
*/
public function import(array $data) {
parent::import($data);
}
/**
* @return array
*/
public function jsonSerialize(): array {
return array_merge(
parent::jsonSerialize(),
[
]
);
}
}

Wyświetl plik

@ -32,24 +32,24 @@ namespace OCA\Social\Model\ActivityPub;
use JsonSerializable;
class Note extends Core implements JsonSerializable {
class Note extends ACore implements JsonSerializable {
/** @var string */
private $content;
/** @var string */
private $summary = '';
/** @var string */
private $published;
/** @var string */
private $attributedTo;
/** @var string */
private $inReplyTo = '';
/** @var bool */
private $sensitive = false;
/** @var string */
private $conversation = '';
/**
* Note constructor.
@ -82,43 +82,6 @@ class Note extends Core implements JsonSerializable {
}
/**
* @return string
*/
public function getSummary(): string {
return $this->summary;
}
/**
* @param string $summary
*
* @return Note
*/
public function setSummary(string $summary): Note {
$this->summary = $summary;
return $this;
}
/**
* @return string
*/
public function getPublished(): string {
return $this->published;
}
/**
* @param string $published
*
* @return Note
*/
public function setPublished(string $published): Note {
$this->published = $published;
return $this;
}
/**
* @return string
*/
@ -156,19 +119,57 @@ class Note extends Core implements JsonSerializable {
}
/**
* @return bool
*/
public function isSensitive(): bool {
return $this->sensitive;
}
/**
* @param bool $sensitive
*
* @return Note
*/
public function setSensitive(bool $sensitive): Note {
$this->sensitive = $sensitive;
return $this;
}
/**
* @return string
*/
public function getConversation(): string {
return $this->conversation;
}
/**
* @param string $conversation
*
* @return Note
*/
public function setConversation(string $conversation): Note {
$this->conversation = $conversation;
return $this;
}
/**
* @param array $data
*/
public function import(array $data) {
parent::import($data);
// public function
//"published": "2018-06-23T17:17:11Z",
//"attributedTo": "https://my-example.com/actor",
//"inReplyTo": "https://mastodon.social/@Gargron/100254678717223630",
$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, ''));
}
/**
@ -181,7 +182,9 @@ class Note extends Core implements JsonSerializable {
'content' => $this->getContent(),
'published' => $this->getPublished(),
'attributedTo' => $this->getRoot() . $this->getAttributedTo(),
'inReplyTo' => $this->getInReplyTo()
'inReplyTo' => $this->getInReplyTo(),
'sensitive' => $this->isSensitive(),
'conversation' => $this->getConversation()
]
);
}

Wyświetl plik

@ -0,0 +1,134 @@
<?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;
use JsonSerializable;
/**
* Class OrderedCollection
*
* @package OCA\Social\Model\ActivityPub
*/
class OrderedCollection extends ACore implements JsonSerializable {
/** @var int */
private $totalItems = 0;
/** @var string */
private $first = '';
/**
* Activity constructor.
*
* @param bool $isTopLevel
*/
public function __construct(bool $isTopLevel = false) {
parent::__construct($isTopLevel);
$this->setType('OrderedCollection');
}
/**
* @return int
*/
public function getTotalItems(): int {
return $this->totalItems;
}
/**
* @param int $totalItems
*
* @return OrderedCollection
*/
public function setTotalItems(int $totalItems): OrderedCollection {
$this->totalItems = $totalItems;
return $this;
}
/**
* @return string
*/
public function getFirst(): string {
return $this->first;
}
/**
* @param string $first
*
* @return OrderedCollection
*/
public function setFirst(string $first): OrderedCollection {
$this->first = $first;
return $this;
}
//"id": "https://pub.pontapreta.net/users/admin/following",
//"type": "OrderedCollection",
//"totalItems": 1,
//"first": "https://pub.pontapreta.net/users/admin/following?page=1"
/**
* @param array $data
*/
public function import(array $data) {
parent::import($data);
}
/**
* @return array
*/
public function jsonSerialize(): array {
return array_merge(
parent::jsonSerialize(),
[
'totalItems' => $this->getTotalItems(),
'first' => $this->getFirst()
]
);
}
}

Wyświetl plik

@ -27,17 +27,27 @@ declare(strict_types=1);
*
*/
namespace OCA\Social\Model\ActivityPub;
use JsonSerializable;
use OCA\Social\Service\ActivityPubService;
class Actor extends Core implements JsonSerializable {
/**
* Class Actor
*
* @package OCA\Social\Model\ActivityPub
*/
class Person extends ACore implements JsonSerializable {
/** @var string */
private $userId = '';
/** @var string */
private $name = '';
/** @var string */
private $preferredUsername = '';
@ -68,9 +78,12 @@ class Actor extends Core implements JsonSerializable {
/** @var string */
private $sharedInbox = '';
/** @var string */
private $featured = '';
/**
* Actor constructor.
* Person constructor.
*
* @param bool $isTopLevel
*/
@ -91,15 +104,11 @@ class Actor extends Core implements JsonSerializable {
/**
* @param string $userId
*
* @return Actor
* @return Person
*/
public function setUserId(string $userId): Actor {
public function setUserId(string $userId): Person {
$this->userId = $userId;
if ($this->getPreferredUsername() === '') {
$this->setPreferredUsername($userId);
}
return $this;
}
@ -114,12 +123,10 @@ class Actor extends Core implements JsonSerializable {
/**
* @param string $preferredUsername
*
* @return Actor
* @return Person
*/
public function setPreferredUsername(string $preferredUsername): Actor {
if ($preferredUsername !== '') {
$this->preferredUsername = $preferredUsername;
}
public function setPreferredUsername(string $preferredUsername): Person {
$this->preferredUsername = $preferredUsername;
return $this;
}
@ -135,9 +142,9 @@ class Actor extends Core implements JsonSerializable {
/**
* @param string $publicKey
*
* @return Actor
* @return Person
*/
public function setPublicKey(string $publicKey): Actor {
public function setPublicKey(string $publicKey): Person {
$this->publicKey = $publicKey;
return $this;
@ -154,9 +161,9 @@ class Actor extends Core implements JsonSerializable {
/**
* @param string $privateKey
*
* @return Actor
* @return Person
*/
public function setPrivateKey(string $privateKey): Actor {
public function setPrivateKey(string $privateKey): Person {
$this->privateKey = $privateKey;
return $this;
@ -173,9 +180,9 @@ class Actor extends Core implements JsonSerializable {
/**
* @param int $creation
*
* @return Actor
* @return Person
*/
public function setCreation(int $creation): Actor {
public function setCreation(int $creation): Person {
$this->creation = $creation;
return $this;
@ -192,9 +199,9 @@ class Actor extends Core implements JsonSerializable {
/**
* @param string $following
*
* @return Actor
* @return Person
*/
public function setFollowing(string $following): Actor {
public function setFollowing(string $following): Person {
$this->following = $following;
return $this;
@ -210,9 +217,9 @@ class Actor extends Core implements JsonSerializable {
/**
* @param string $followers
*
* @return Actor
* @return Person
*/
public function setFollowers(string $followers): Actor {
public function setFollowers(string $followers): Person {
$this->followers = $followers;
return $this;
@ -228,9 +235,9 @@ class Actor extends Core implements JsonSerializable {
/**
* @param string $account
*
* @return Actor
* @return Person
*/
public function setAccount(string $account): Actor {
public function setAccount(string $account): Person {
$this->account = $account;
return $this;
@ -247,9 +254,9 @@ class Actor extends Core implements JsonSerializable {
/**
* @param string $inbox
*
* @return Actor
* @return Person
*/
public function setInbox(string $inbox): Actor {
public function setInbox(string $inbox): Person {
$this->inbox = $inbox;
return $this;
@ -265,9 +272,9 @@ class Actor extends Core implements JsonSerializable {
/**
* @param string $outbox
*
* @return Actor
* @return Person
*/
public function setOutbox(string $outbox): Actor {
public function setOutbox(string $outbox): Person {
$this->outbox = $outbox;
return $this;
@ -283,46 +290,98 @@ class Actor extends Core implements JsonSerializable {
/**
* @param string $sharedInbox
*
* @return Actor
* @return Person
*/
public function setSharedInbox(string $sharedInbox): Actor {
public function setSharedInbox(string $sharedInbox): Person {
$this->sharedInbox = $sharedInbox;
return $this;
}
/**
* @return string
*/
public function getName(): string {
return $this->name;
}
/**
* @param string $name
*
* @return Person
*/
public function setName(string $name): Person {
$this->name = $name;
return $this;
}
/**
* @return string
*/
public function getFeatured(): string {
return $this->featured;
}
/**
* @param string $featured
*
* @return Person
*/
public function setFeatured(string $featured): Person {
$this->featured = $featured;
return $this;
}
/**
* @param array $data
*/
public function import(array $data) {
parent::import($data);
$this->setPreferredUsername($this->get('preferred_username', $data, ''))
->setName($this->get('name', $data, ''))
->setAccount($this->get('account', $data, ''))
->setPublicKey($this->get('public_key', $data, ''))
->setPrivateKey($this->get('private_key', $data, ''))
->setInbox($this->get('inbox', $data, ''))
->setOutbox($this->get('outbox', $data, ''))
->setFollowers($this->get('followers', $data, ''))
->setFollowing($this->get('following', $data, ''))
->setSharedInbox($this->get('shared_inbox', $data, ''))
->setFeatured($this->get('featured', $data, ''))
->setCreation($this->getInt('creation', $data, 0));
}
/**
* @return array
*/
public function jsonSerialize(): array {
return [
'@context' => [
ActivityPubService::CONTEXT_ACTIVITYSTREAMS,
ActivityPubService::CONTEXT_SECURITY
],
'aliases' => [
$this->getRoot() . '@' . $this->getPreferredUsername(),
$this->getRoot() . 'users/' . $this->getPreferredUsername()
],
'id' => $this->getId(),
'type' => $this->getType(),
'preferredUsername' => $this->getPreferredUsername(),
'inbox' => $this->getInbox(),
'outbox' => $this->getOutbox(),
'following' => $this->getFollowing(),
'followers' => $this->getFollowers(),
'url' => $this->getId(),
'endpoints' =>
['sharedInbox' => $this->getSharedInbox()],
'publicKey' => [
'id' => $this->getId() . '#main-key',
'owner' => $this->getId(),
'publicKeyPem' => $this->getPublicKey()
return array_merge(
parent::jsonSerialize(),
[
'aliases' => [
$this->getRoot() . '@' . $this->getPreferredUsername(),
$this->getRoot() . 'users/' . $this->getPreferredUsername()
],
'preferredUsername' => $this->getPreferredUsername(),
'name' => $this->getName(),
'inbox' => $this->getInbox(),
'outbox' => $this->getOutbox(),
'following' => $this->getFollowing(),
'followers' => $this->getFollowers(),
'endpoints' =>
['sharedInbox' => $this->getSharedInbox()],
'publicKey' => [
'id' => $this->getId() . '#main-key',
'owner' => $this->getId(),
'publicKeyPem' => $this->getPublicKey()
]
]
];
);
}

Wyświetl plik

@ -0,0 +1,84 @@
<?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;
use JsonSerializable;
/**
* Class Undo
*
* @package OCA\Social\Model\ActivityPub
*/
class Undo extends ACore implements JsonSerializable {
private $actor;
private $object;
/**
* Activity constructor.
*
* @param bool $isTopLevel
*/
public function __construct(bool $isTopLevel = false) {
parent::__construct($isTopLevel);
$this->setType('Undo');
$this->addMetaBool('Undo', true);
}
/**
* @param array $data
*/
public function import(array $data) {
parent::import($data);
}
/**
* @return array
*/
public function jsonSerialize(): array {
return array_merge(
parent::jsonSerialize(),
[
]
);
}
}

Wyświetl plik

@ -33,25 +33,24 @@ namespace OCA\Social\Model;
use daita\MySmallPhpTools\Traits\TArrayTools;
use JsonSerializable;
/**
* Class InstancePath
*
* @package OCA\Social\Model
*/
class InstancePath implements JsonSerializable {
const INBOX = 1;
use TArrayTools;
/** @var string */
private $uri = '';
/** @var int */
private $type;
public function __construct(string $uri, $type = 0) {
public function __construct(string $uri) {
$this->uri = $uri;
$this->type = $type;
}
@ -62,44 +61,22 @@ class InstancePath implements JsonSerializable {
return $this->uri;
}
/**
* @param string $uri
*
* @return InstancePath
*/
public function setUri(string $uri): InstancePath {
$this->uri = $uri;
return $this;
}
/**
* @return int
* @return string
*/
public function getType(): int {
return $this->type;
public function getPath(): string {
$info = parse_url($this->uri);
return $this->get('path', $info, '');
}
/**
* @param int $type
*
* @return InstancePath
*/
public function setType(int $type): InstancePath {
$this->type = $type;
return $this;
}
/**
* @return array
*/
public function jsonSerialize(): array {
return [
'uri' => $this->getUri(),
'type' => $this->getType()
'uri' => $this->getUri()
];
}

136
lib/Model/Post.php 100644
Wyświetl plik

@ -0,0 +1,136 @@
<?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;
use daita\MySmallPhpTools\Traits\TArrayTools;
use JsonSerializable;
class Post implements JsonSerializable {
use TArrayTools;
/** @var string */
private $userId = '';
/** @var array */
private $to = [];
/** @var string */
private $replyTo = '';
/** @var string */
private $content;
public function __construct($userId = '') {
$this->userId = $userId;
}
/**
* @return string
*/
public function getUserId(): string {
return $this->userId;
}
/**
* @param string $to
*/
public function addTo(string $to) {
if ($to === '') {
return;
}
$this->to[] = $to;
}
/**
* @return array
*/
public function getTo(): array {
return $this->to;
}
/**
* @param array $to
*/
public function setTo(array $to) {
$this->to = $to;
}
/**
* @return string
*/
public function getReplyTo(): string {
return $this->replyTo;
}
/**
* @param string $replyTo
*/
public function setReplyTo(string $replyTo) {
$this->replyTo = $replyTo;
}
/**
* @return string
*/
public function getContent(): string {
return $this->content;
}
/**
* @param string $content
*/
public function setContent(string $content) {
$this->content = $content;
}
/**
* @return array
*/
public function jsonSerialize(): array {
return [
'userId' => $this->getUserId(),
'to' => $this->getTo(),
'replyTo' => $this->getReplyTo(),
'content' => $this->getContent()
];
}
}