diff options
Diffstat (limited to 'lib/Model')
-rw-r--r-- | lib/Model/ActivityPub/ACore.php | 13 | ||||
-rw-r--r-- | lib/Model/ActivityPub/Actor/Person.php | 78 | ||||
-rw-r--r-- | lib/Model/ActivityPub/Item.php | 36 | ||||
-rw-r--r-- | lib/Model/ActivityPub/Object/Announce.php | 2 | ||||
-rw-r--r-- | lib/Model/ActivityPub/Stream.php | 16 | ||||
-rw-r--r-- | lib/Model/LinkedDataSignature.php | 8 |
6 files changed, 72 insertions, 81 deletions
diff --git a/lib/Model/ActivityPub/ACore.php b/lib/Model/ActivityPub/ACore.php index 89515e11..27c43ae7 100644 --- a/lib/Model/ActivityPub/ACore.php +++ b/lib/Model/ActivityPub/ACore.php @@ -38,8 +38,8 @@ use OCA\Social\Exceptions\ActivityCantBeVerifiedException; use OCA\Social\Exceptions\InvalidOriginException; use OCA\Social\Exceptions\InvalidResourceEntryException; use OCA\Social\Exceptions\UrlCloudException; -use OCA\Social\Model\LinkedDataSignature; use OCA\Social\Model\ActivityPub\Object\Document; +use OCA\Social\Model\LinkedDataSignature; class ACore extends Item implements JsonSerializable { @@ -225,6 +225,15 @@ class ACore extends Item implements JsonSerializable { /** * @return bool */ + public function isPublic(): bool { + return ($this->getTo() === self::CONTEXT_PUBLIC + || in_array(self::CONTEXT_PUBLIC, $this->getCcArray())); + } + + + /** + * @return bool + */ public function gotSignature(): bool { return ($this->signature !== null); } @@ -635,7 +644,7 @@ class ACore extends Item implements JsonSerializable { $this->addEntryArray('to', $this->getToArray()); $this->addEntryArray('cc', $this->getCcArray()); - if ($this->gotActor()) { + if ($this->hasActor()) { $this->addEntry( 'actor', $this->getActor() ->getId() diff --git a/lib/Model/ActivityPub/Actor/Person.php b/lib/Model/ActivityPub/Actor/Person.php index bd94f035..af2ebfd9 100644 --- a/lib/Model/ActivityPub/Actor/Person.php +++ b/lib/Model/ActivityPub/Actor/Person.php @@ -41,6 +41,7 @@ use OCA\Social\Exceptions\SocialAppConfigException; use OCA\Social\Exceptions\UrlCloudException; use OCA\Social\Model\ActivityPub\ACore; use OCA\Social\Model\ActivityPub\Object\Image; +use OCA\Social\Traits\TDetails; /** @@ -51,6 +52,9 @@ use OCA\Social\Model\ActivityPub\Object\Image; class Person extends ACore implements JsonSerializable { + use TDetails; + + const TYPE = 'Person'; @@ -93,9 +97,6 @@ class Person extends ACore implements JsonSerializable { /** @var string */ private $featured = ''; - /** @var array */ - private $details = []; - /** @var int */ private $avatarVersion = -1; @@ -359,73 +360,6 @@ class Person extends ACore implements JsonSerializable { /** - * @return array - */ - public function getDetails(): array { - return $this->details; - } - - /** - * @param string $detail - * @param string $value - * - * @return Person - */ - public function addDetail(string $detail, string $value): Person { - $this->details[$detail] = $value; - - return $this; - } - - /** - * @param string $detail - * @param int $value - * - * @return Person - */ - public function addDetailInt(string $detail, int $value): Person { - $this->details[$detail] = $value; - - return $this; - } - - /** - * @param string $detail - * @param array $value - * - * @return Person - */ - public function addDetailArray(string $detail, array $value): Person { - $this->details[$detail] = $value; - - return $this; - } - - /** - * @param string $detail - * @param bool $value - * - * @return Person - */ - public function addDetailBool(string $detail, bool $value): Person { - $this->details[$detail] = $value; - - return $this; - } - - /** - * @param array $details - * - * @return Person - */ - public function setDetails(array $details): Person { - $this->details = $details; - - return $this; - } - - - /** * @return int */ public function getAvatarVersion(): int { @@ -497,7 +431,7 @@ class Person extends ACore implements JsonSerializable { ->setFollowing($this->validate(self::AS_URL, 'following', $data, '')) ->setSharedInbox($this->validate(self::AS_URL, 'shared_inbox', $data, '')) ->setFeatured($this->validate(self::AS_URL, 'featured', $data, '')) - ->setDetails($this->getArray('details', $data, [])); + ->setDetailsAll($this->getArray('details', $data, [])); try { $dTime = new DateTime($this->get('creation', $data, 'yesterday')); @@ -536,7 +470,7 @@ class Person extends ACore implements JsonSerializable { ); if ($this->isCompleteDetails()) { - $result['details'] = $this->getDetails(); + $result['details'] = $this->getDetailsAll(); } return $result; diff --git a/lib/Model/ActivityPub/Item.php b/lib/Model/ActivityPub/Item.php index 8184ce1c..f1438583 100644 --- a/lib/Model/ActivityPub/Item.php +++ b/lib/Model/ActivityPub/Item.php @@ -261,7 +261,7 @@ class Item { /** * @return bool */ - public function gotActor(): bool { + public function hasActor(): bool { if ($this->actor === null) { return false; } @@ -394,13 +394,45 @@ class Item { } + /** + * @param string $cc + * + * @return Item + */ public function addCc(string $cc): Item { - $this->cc[] = $cc; + if (!$this->hasCc($cc)) { + $this->cc[] = $cc; + } + + return $this; + } + + /** + * @param string $cc + * + * @return Item + */ + public function removeCc(string $cc): Item { + if (!in_array($cc, $this->cc)) { + return $this; + } + + $this->cc = array_diff($this->cc, [$cc]); return $this; } /** + * @param string $cc + * + * @return bool + */ + public function hasCc(string $cc): bool { + return (in_array($cc, $this->cc)); + } + + + /** * @return array */ public function getCcArray(): array { diff --git a/lib/Model/ActivityPub/Object/Announce.php b/lib/Model/ActivityPub/Object/Announce.php index 8cc4c81e..a13e5b6a 100644 --- a/lib/Model/ActivityPub/Object/Announce.php +++ b/lib/Model/ActivityPub/Object/Announce.php @@ -88,7 +88,7 @@ class Announce extends Stream implements JsonSerializable { */ public function jsonSerialize(): array { $result = parent::jsonSerialize(); - $result['actor'] = $this->getAttributedTo(); + //$result['actor'] = $this->getAttributedTo(); return $result; } diff --git a/lib/Model/ActivityPub/Stream.php b/lib/Model/ActivityPub/Stream.php index 8aa2f3c7..d8585927 100644 --- a/lib/Model/ActivityPub/Stream.php +++ b/lib/Model/ActivityPub/Stream.php @@ -36,11 +36,15 @@ use DateTime; use Exception; use JsonSerializable; use OCA\Social\Model\StreamAction; +use OCA\Social\Traits\TDetails; class Stream extends ACore implements JsonSerializable { + use TDetails; + + const TYPE = 'Stream'; @@ -48,6 +52,7 @@ class Stream extends ACore implements JsonSerializable { const TYPE_UNLISTED = 'unlisted'; const TYPE_FOLLOWERS = 'followers'; const TYPE_DIRECT = 'direct'; + const TYPE_ANNOUNCE = 'announce'; /** @var string */ @@ -81,6 +86,11 @@ class Stream extends ACore implements JsonSerializable { private $hiddenOnTimeline = false; + /** + * Stream constructor. + * + * @param null $parent + */ public function __construct($parent = null) { parent::__construct($parent); } @@ -346,6 +356,7 @@ class Stream extends ACore implements JsonSerializable { $this->setObjectId($this->validate(self::AS_ID, 'object_id', $data, '')); $this->setAttributedTo($this->validate(self::AS_ID, 'attributed_to', $data, '')); $this->setInReplyTo($this->validate(self::AS_ID, 'in_reply_to', $data)); + $this->setDetailsAll($this->getArray('details', $data, [])); $this->setHiddenOnTimeline($this->getBool('hidden_on_timeline', $data, false)); $cache = new Cache(); @@ -375,11 +386,16 @@ class Stream extends ACore implements JsonSerializable { $result = array_merge( $result, [ + 'details' => $this->getDetailsAll(), 'action' => ($this->hasAction()) ? $this->getAction() : [], 'cache' => ($this->hasCache()) ? $this->getCache() : '', 'publishedTime' => $this->getPublishedTime() ] ); + + $result['cc'] = ''; + $result['bcc'] = ''; + $result['to'] = ''; } $this->cleanArray($result); diff --git a/lib/Model/LinkedDataSignature.php b/lib/Model/LinkedDataSignature.php index d2e46d20..9baacd64 100644 --- a/lib/Model/LinkedDataSignature.php +++ b/lib/Model/LinkedDataSignature.php @@ -320,13 +320,13 @@ class LinkedDataSignature implements JsonSerializable { */ public function import(array $data) { - if (!in_array(ACore::CONTEXT_SECURITY, $this->getArray('@context', $data, []))) { - throw new LinkedDataSignatureMissingException(); - } +// if (!in_array(ACore::CONTEXT_SECURITY, $this->getArray('@context', $data, []))) { +// throw new LinkedDataSignatureMissingException('no @context security entry'); +// } $signature = $this->getArray('signature', $data, []); if ($signature === []) { - throw new LinkedDataSignatureMissingException(); + throw new LinkedDataSignatureMissingException('missing signature'); } $this->setType($this->get('type', $signature, '')); |