sforkowany z mirror/social
saving document throw interface
Signed-off-by: Maxence Lange <maxence@artificial-owl.com>feature/573/request-on-host-meta
rodzic
524c7aa141
commit
145d748b03
|
@ -202,14 +202,6 @@ class AP {
|
|||
} catch (ItemUnknownException $e) {
|
||||
}
|
||||
|
||||
try {
|
||||
// TODO: move to Model/Person if 'icon' is specific to Person object ?
|
||||
/** @var Document $icon */
|
||||
$icon = $this->getItemFromData($this->getArray('icon', $data, []), $item, $level);
|
||||
$item->setIcon($icon);
|
||||
} catch (ItemUnknownException $e) {
|
||||
}
|
||||
|
||||
return $item;
|
||||
}
|
||||
|
||||
|
|
|
@ -31,7 +31,11 @@ namespace OCA\Social\Model\ActivityPub\Object;
|
|||
|
||||
|
||||
use DateTime;
|
||||
use Exception;
|
||||
use JsonSerializable;
|
||||
use OCA\Social\AP;
|
||||
use OCA\Social\Exceptions\InvalidResourceEntryException;
|
||||
use OCA\Social\Exceptions\ItemUnknownException;
|
||||
use OCA\Social\Model\ActivityPub\ACore;
|
||||
|
||||
|
||||
|
@ -52,6 +56,9 @@ class Note extends ACore implements JsonSerializable {
|
|||
/** @var string */
|
||||
private $attributedTo = '';
|
||||
|
||||
/** @var array */
|
||||
private $attachments = [];
|
||||
|
||||
/** @var string */
|
||||
private $inReplyTo = '';
|
||||
|
||||
|
@ -133,6 +140,25 @@ class Note extends ACore implements JsonSerializable {
|
|||
}
|
||||
|
||||
|
||||
/**
|
||||
* @return array
|
||||
*/
|
||||
public function getAttachments(): array {
|
||||
return $this->attachments;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param array $attachments
|
||||
*
|
||||
* @return Note
|
||||
*/
|
||||
public function setAttachments(array $attachments): Note {
|
||||
$this->attachments = $attachments;
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @return bool
|
||||
*/
|
||||
|
@ -210,6 +236,44 @@ class Note extends ACore implements JsonSerializable {
|
|||
$this->setConversation($this->validate(ACore::AS_ID, 'conversation', $data, ''));
|
||||
$this->setContent($this->get('content', $data, ''));
|
||||
$this->convertPublished();
|
||||
|
||||
$this->importAttachments($this->getArray('attachment', $data, []));
|
||||
}
|
||||
|
||||
|
||||
public function importAttachments(array $list) {
|
||||
foreach ($list as $item) {
|
||||
try {
|
||||
$attachment = AP::$activityPub->getItemFromData($item, $this);
|
||||
} catch (Exception $e) {
|
||||
continue;
|
||||
}
|
||||
|
||||
if ($attachment->getType() !== Document::TYPE
|
||||
&& $attachment->getType() !== Image::TYPE) {
|
||||
continue;
|
||||
}
|
||||
|
||||
try {
|
||||
$attachment->setUrl(
|
||||
$this->validateEntryString(ACore::AS_URL, $attachment->getUrl())
|
||||
);
|
||||
} catch (InvalidResourceEntryException $e) {
|
||||
continue;
|
||||
}
|
||||
|
||||
if ($attachment->getUrl() === '') {
|
||||
continue;
|
||||
}
|
||||
|
||||
try {
|
||||
$interface = AP::$activityPub->getInterfaceFromType($attachment->getType());
|
||||
} catch (ItemUnknownException $e) {
|
||||
continue;
|
||||
}
|
||||
|
||||
$interface->save($attachment);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
@ -224,6 +288,7 @@ class Note extends ACore implements JsonSerializable {
|
|||
$this->setContent($this->validate(self::AS_STRING, 'content', $data, ''));;
|
||||
|
||||
$this->setPublishedTime($dTime->getTimestamp());
|
||||
$this->setAttachments($this->getArray('attachments', $data, []));
|
||||
$this->setAttributedTo($this->validate(self::AS_ID, 'attributed_to', $data, ''));
|
||||
$this->setInReplyTo($this->validate(self::AS_ID, 'in_reply_to', $data));
|
||||
}
|
||||
|
@ -238,10 +303,10 @@ class Note extends ACore implements JsonSerializable {
|
|||
return array_merge(
|
||||
parent::jsonSerialize(),
|
||||
[
|
||||
'content' => $this->getContent(),
|
||||
'content' => $this->getContent(),
|
||||
'attributedTo' => $this->getUrlSocial() . $this->getAttributedTo(),
|
||||
'inReplyTo' => $this->getInReplyTo(),
|
||||
'sensitive' => $this->isSensitive(),
|
||||
'inReplyTo' => $this->getInReplyTo(),
|
||||
'sensitive' => $this->isSensitive(),
|
||||
'conversation' => $this->getConversation()
|
||||
]
|
||||
);
|
||||
|
|
|
@ -31,9 +31,11 @@ namespace OCA\Social\Service;
|
|||
|
||||
|
||||
use daita\MySmallPhpTools\Traits\TArrayTools;
|
||||
use OCA\Social\AP;
|
||||
use OCA\Social\Db\CacheActorsRequest;
|
||||
use OCA\Social\Db\CacheDocumentsRequest;
|
||||
use OCA\Social\Exceptions\CacheDocumentDoesNotExistException;
|
||||
use OCA\Social\Exceptions\ItemUnknownException;
|
||||
use OCA\Social\Model\ActivityPub\Actor\Person;
|
||||
|
||||
|
||||
|
@ -148,7 +150,11 @@ class ActorService {
|
|||
$cache = $this->cacheDocumentsRequest->getByUrl($icon->getUrl());
|
||||
$actor->setIcon($cache);
|
||||
} catch (CacheDocumentDoesNotExistException $e) {
|
||||
$this->cacheDocumentsRequest->save($actor->getIcon());
|
||||
try {
|
||||
$interface = AP::$activityPub->getInterfaceFromType($icon->getType());
|
||||
$interface->save($icon);
|
||||
} catch (ItemUnknownException $e) {
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
Ładowanie…
Reference in New Issue