kopia lustrzana https://github.com/nextcloud/social
fixing replyTo and @context generation
Signed-off-by: Maxence Lange <maxence@artificial-owl.com>pull/206/head
rodzic
c470f7f6d1
commit
840326aab7
|
@ -133,7 +133,7 @@ class NotesRequest extends NotesRequestBuilder {
|
|||
$cursor->closeCursor();
|
||||
|
||||
if ($data === false) {
|
||||
throw new NoteNotFoundException();
|
||||
throw new NoteNotFoundException('Post not found');
|
||||
}
|
||||
|
||||
return $this->parseNotesSelectSql($data);
|
||||
|
|
|
@ -538,13 +538,20 @@ abstract class ACore extends Item implements JsonSerializable {
|
|||
* @return array
|
||||
*/
|
||||
public function jsonSerialize(): array {
|
||||
$context = [self::CONTEXT_ACTIVITYSTREAMS];
|
||||
|
||||
if ($this->gotSignature()) {
|
||||
$this->entries['signature'] = $this->getSignature();
|
||||
array_push($context, self::CONTEXT_SECURITY);
|
||||
}
|
||||
|
||||
if ($this->isRoot()) {
|
||||
$context = [self::CONTEXT_ACTIVITYSTREAMS];
|
||||
|
||||
if ($this->gotObject()
|
||||
&& $this->getObject()
|
||||
->gotSignature()) {
|
||||
array_push($context, self::CONTEXT_SECURITY);
|
||||
}
|
||||
|
||||
$this->addEntryArray('@context', $context);
|
||||
}
|
||||
|
||||
|
|
|
@ -32,6 +32,7 @@ namespace OCA\Social\Model\ActivityPub;
|
|||
|
||||
use DateTime;
|
||||
use JsonSerializable;
|
||||
use OCA\Social\Exceptions\InvalidResourceEntryException;
|
||||
use OCA\Social\Service\ActivityService;
|
||||
|
||||
class Note extends ACore implements JsonSerializable {
|
||||
|
@ -195,6 +196,8 @@ class Note extends ACore implements JsonSerializable {
|
|||
|
||||
/**
|
||||
* @param array $data
|
||||
*
|
||||
* @throws InvalidResourceEntryException
|
||||
*/
|
||||
public function import(array $data) {
|
||||
parent::import($data);
|
||||
|
|
|
@ -31,14 +31,18 @@ declare(strict_types=1);
|
|||
namespace OCA\Social\Service\ActivityPub;
|
||||
|
||||
|
||||
use daita\MySmallPhpTools\Exceptions\MalformedArrayException;
|
||||
use Exception;
|
||||
use OC\User\NoUserException;
|
||||
use OCA\Social\Db\NotesRequest;
|
||||
use OCA\Social\Exceptions\ActorDoesNotExistException;
|
||||
use OCA\Social\Exceptions\InvalidOriginException;
|
||||
use OCA\Social\Exceptions\InvalidResourceException;
|
||||
use OCA\Social\Exceptions\NoteNotFoundException;
|
||||
use OCA\Social\Exceptions\Request410Exception;
|
||||
use OCA\Social\Exceptions\RequestException;
|
||||
use OCA\Social\Exceptions\SocialAppConfigException;
|
||||
use OCA\Social\Exceptions\UrlCloudException;
|
||||
use OCA\Social\Model\ActivityPub\ACore;
|
||||
use OCA\Social\Model\ActivityPub\Activity\Create;
|
||||
use OCA\Social\Model\ActivityPub\Note;
|
||||
|
@ -258,16 +262,27 @@ class NoteService implements ICoreService {
|
|||
/**
|
||||
* @param Note $note
|
||||
* @param string $replyTo
|
||||
*
|
||||
* @throws InvalidResourceException
|
||||
* @throws MalformedArrayException
|
||||
* @throws NoteNotFoundException
|
||||
* @throws Request410Exception
|
||||
* @throws RequestException
|
||||
* @throws SocialAppConfigException
|
||||
* @throws UrlCloudException
|
||||
*/
|
||||
public function replyTo(Note $note, string $replyTo) {
|
||||
if ($replyTo === '') {
|
||||
return;
|
||||
}
|
||||
|
||||
$author = $this->getAuthorFromPostId($replyTo);
|
||||
$note->setInReplyTo($replyTo);
|
||||
// TODO - type can be NOT public !
|
||||
$note->addInstancePath(
|
||||
new InstancePath($replyTo, InstancePath::TYPE_PUBLIC, InstancePath::PRIORITY_HIGH)
|
||||
new InstancePath(
|
||||
$author->getSharedInbox(), InstancePath::TYPE_INBOX, InstancePath::PRIORITY_HIGH
|
||||
)
|
||||
);
|
||||
}
|
||||
|
||||
|
@ -417,5 +432,23 @@ class NoteService implements ICoreService {
|
|||
return $this->notesRequest->getStreamTimeline($since, $limit, false);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @param $noteId
|
||||
*
|
||||
* @return Person
|
||||
* @throws NoteNotFoundException
|
||||
* @throws RequestException
|
||||
* @throws SocialAppConfigException
|
||||
* @throws InvalidResourceException
|
||||
* @throws Request410Exception
|
||||
* @throws UrlCloudException
|
||||
* @throws MalformedArrayException
|
||||
*/
|
||||
public function getAuthorFromPostId($noteId) {
|
||||
$note = $this->notesRequest->getNoteById($noteId);
|
||||
|
||||
return $this->personService->getFromId($note->getAttributedTo());
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -159,6 +159,7 @@ class ActivityService {
|
|||
public function createActivity(Person $actor, ACore $item, ACore &$activity = null): string {
|
||||
|
||||
$activity = new Create();
|
||||
$item->setParent($activity);
|
||||
|
||||
// $this->activityStreamsService->initCore($activity);
|
||||
$this->signObject($actor, $item);
|
||||
|
|
Ładowanie…
Reference in New Issue