kopia lustrzana https://github.com/nextcloud/social
cleaning/renaming
Signed-off-by: Maxence Lange <maxence@artificial-owl.com>pull/53/head
rodzic
f6f7f2cd6a
commit
7b65c3b0f4
|
@ -64,7 +64,7 @@ class ActorsRequest extends ActorsRequestBuilder {
|
|||
*/
|
||||
public function create(Person $actor): string {
|
||||
|
||||
$id = $this->configService->getUrlRoot() . '@' . $actor->getPreferredUsername();
|
||||
$id = $this->configService->getUrlSocial() . '@' . $actor->getPreferredUsername();
|
||||
|
||||
try {
|
||||
$qb = $this->getActorsInsertSql();
|
||||
|
|
|
@ -109,10 +109,10 @@ class ActorsRequestBuilder extends CoreRequestBuilder {
|
|||
* @throws SocialAppConfigException
|
||||
*/
|
||||
protected function parseActorsSelectSql($data): Person {
|
||||
$root = $this->configService->getUrlRoot();
|
||||
$root = $this->configService->getUrlSocial();
|
||||
|
||||
$actor = new Person();
|
||||
$actor->import($data);
|
||||
$actor->importFromDatabase($data);
|
||||
$actor->setInbox($actor->getId() . '/inbox')
|
||||
->setOutbox($actor->getId() . '/outbox')
|
||||
->setFollowers($actor->getId() . '/followers')
|
||||
|
@ -122,7 +122,7 @@ class ActorsRequestBuilder extends CoreRequestBuilder {
|
|||
->setAccount(
|
||||
$actor->getPreferredUsername() . '@' . $this->configService->getCloudAddress(true)
|
||||
);
|
||||
$actor->setUrlRoot($root)
|
||||
$actor->setUrlSocial($root)
|
||||
->setUrl($actor->getId());
|
||||
|
||||
return $actor;
|
||||
|
|
|
@ -31,7 +31,7 @@ namespace OCA\Social\Db;
|
|||
|
||||
|
||||
use daita\MySmallPhpTools\Traits\TArrayTools;
|
||||
use OCA\Social\Model\ActivityPub\Cache\CacheActor;
|
||||
use OCA\Social\Exceptions\InvalidResourceException;
|
||||
use OCA\Social\Model\ActivityPub\Person;
|
||||
use OCP\DB\QueryBuilder\IQueryBuilder;
|
||||
|
||||
|
@ -110,7 +110,7 @@ class CacheActorsRequestBuilder extends CoreRequestBuilder {
|
|||
*/
|
||||
protected function parseCacheActorsSelectSql(array $data): Person {
|
||||
$actor = new Person();
|
||||
$actor->import($data);
|
||||
$actor->importFromDatabase($data);
|
||||
|
||||
return $actor;
|
||||
}
|
||||
|
|
|
@ -27,24 +27,36 @@ declare(strict_types=1);
|
|||
*
|
||||
*/
|
||||
|
||||
|
||||
namespace OCA\Social\Db;
|
||||
|
||||
|
||||
use Doctrine\DBAL\Query\QueryBuilder;
|
||||
use OCA\Social\Exceptions\InvalidResourceException;
|
||||
use OCA\Social\Exceptions\UrlCloudException;
|
||||
use OCA\Social\Model\ActivityPub\Document;
|
||||
use OCA\Social\Model\ActivityPub\Image;
|
||||
use OCA\Social\Model\ActivityPub\Person;
|
||||
use OCA\Social\Service\ConfigService;
|
||||
use OCA\Social\Service\MiscService;
|
||||
use OCP\DB\QueryBuilder\IQueryBuilder;
|
||||
use OCP\IDBConnection;
|
||||
|
||||
|
||||
/**
|
||||
* Class CoreRequestBuilder
|
||||
*
|
||||
* @package OCA\Social\Db
|
||||
*/
|
||||
class CoreRequestBuilder {
|
||||
|
||||
|
||||
const TABLE_SERVER_ACTORS = 'social_server_actors';
|
||||
const TABLE_SERVER_NOTES = 'social_server_notes';
|
||||
const TABLE_SERVER_FOLLOWS = 'social_server_follows';
|
||||
|
||||
const TABLE_CACHE_ACTORS = 'social_cache_actors';
|
||||
const TABLE_CACHE_DOCUMENTS = 'social_cache_documents';
|
||||
|
||||
|
||||
/** @var IDBConnection */
|
||||
|
@ -425,7 +437,7 @@ class CoreRequestBuilder {
|
|||
}
|
||||
|
||||
$actor = new Person();
|
||||
$actor->import($new);
|
||||
$actor->importFromDatabase($new);
|
||||
|
||||
if ($actor->getType() !== Person::TYPE) {
|
||||
throw new InvalidResourceException();
|
||||
|
|
|
@ -160,6 +160,7 @@ class NotesRequestBuilder extends CoreRequestBuilder {
|
|||
protected function parseNotesSelectSql($data): Note {
|
||||
$dTime = new DateTime($this->get('published_time', $data, 'yesterday'));
|
||||
|
||||
// TODO - use $note->importFromDatabase() ?
|
||||
$note = new Note();
|
||||
$note->setId($data['id'])
|
||||
->setTo($data['to'])
|
||||
|
|
|
@ -0,0 +1,8 @@
|
|||
<?php
|
||||
|
||||
namespace OCA\Social\Exceptions;
|
||||
|
||||
class UrlCloudException extends \Exception {
|
||||
|
||||
}
|
||||
|
|
@ -1,157 +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\Cache;
|
||||
|
||||
|
||||
class CacheActor {
|
||||
|
||||
/** @var int */
|
||||
private $id;
|
||||
|
||||
/** @var string */
|
||||
private $account = '';
|
||||
|
||||
/** @var string */
|
||||
private $url;
|
||||
|
||||
/** @var array */
|
||||
private $actor = [];
|
||||
|
||||
/** @var int */
|
||||
private $creation = 0;
|
||||
|
||||
|
||||
/**
|
||||
* CacheActor constructor.
|
||||
*
|
||||
* @param int $id
|
||||
*/
|
||||
public function __construct($id = 0) {
|
||||
$this->id = $id;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @return int
|
||||
*/
|
||||
public function getId(): int {
|
||||
return $this->id;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param int $id
|
||||
*
|
||||
* @return CacheActor
|
||||
*/
|
||||
public function setId(int $id): CacheActor {
|
||||
$this->account = $id;
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @return string
|
||||
*/
|
||||
public function getAccount(): string {
|
||||
return $this->account;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param string $account
|
||||
*
|
||||
* @return CacheActor
|
||||
*/
|
||||
public function setAccount(string $account): CacheActor {
|
||||
$this->account = $account;
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @return string
|
||||
*/
|
||||
public function getUrl(): string {
|
||||
return $this->url;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param string $url
|
||||
*
|
||||
* @return CacheActor
|
||||
*/
|
||||
public function setUrl(string $url): CacheActor {
|
||||
$this->url = $url;
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @return array
|
||||
*/
|
||||
public function getActor(): array {
|
||||
return $this->actor;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param array $actor
|
||||
*
|
||||
* @return CacheActor
|
||||
*/
|
||||
public function setActor(array $actor): CacheActor {
|
||||
$this->actor = $actor;
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @return int
|
||||
*/
|
||||
public function getCreation(): int {
|
||||
return $this->creation;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param int $creation
|
||||
*
|
||||
* @return CacheActor
|
||||
*/
|
||||
public function setCreation(int $creation): CacheActor {
|
||||
$this->creation = $creation;
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
|
@ -199,7 +199,6 @@ class Note extends ACore implements JsonSerializable {
|
|||
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));
|
||||
|
@ -219,7 +218,7 @@ class Note extends ACore implements JsonSerializable {
|
|||
parent::jsonSerialize(),
|
||||
[
|
||||
'content' => $this->getContent(),
|
||||
'attributedTo' => $this->getUrlRoot() . $this->getAttributedTo(),
|
||||
'attributedTo' => $this->getUrlSocial() . $this->getAttributedTo(),
|
||||
'inReplyTo' => $this->getInReplyTo(),
|
||||
'sensitive' => $this->isSensitive(),
|
||||
'conversation' => $this->getConversation()
|
||||
|
|
|
@ -32,6 +32,7 @@ namespace OCA\Social\Model\ActivityPub;
|
|||
|
||||
|
||||
use JsonSerializable;
|
||||
use OCA\Social\Exceptions\UrlCloudException;
|
||||
|
||||
|
||||
/**
|
||||
|
@ -340,9 +341,44 @@ class Person extends ACore implements JsonSerializable {
|
|||
|
||||
/**
|
||||
* @param array $data
|
||||
*
|
||||
* @throws UrlCloudException
|
||||
*/
|
||||
public function import(array $data) {
|
||||
parent::import($data);
|
||||
$this->setPreferredUsername($this->get('preferredUsername', $data, ''))
|
||||
->setPublicKey($this->get('publicKey.publicKeyPem', $data))
|
||||
->setSharedInbox($this->get('endpoints.sharedInbox', $data))
|
||||
->setName($this->get('name', $data, ''))
|
||||
->setAccount($this->get('account', $data, ''))
|
||||
->setInbox($this->get('inbox', $data, ''))
|
||||
->setOutbox($this->get('outbox', $data, ''))
|
||||
->setFollowers($this->get('followers', $data, ''))
|
||||
->setFollowing($this->get('following', $data, ''))
|
||||
->setFeatured($this->get('featured', $data, ''));
|
||||
|
||||
$icon = new Image($this);
|
||||
$icon->setUrlCloud($this->getUrlCloud());
|
||||
$icon->import($this->getArray('icon', $data, []));
|
||||
|
||||
if ($icon->getType() === Image::TYPE) {
|
||||
$this->setIcon($icon);
|
||||
}
|
||||
|
||||
|
||||
// ->setCreation($this->getInt('creation', $data, 0));
|
||||
|
||||
// if ($this->getPreferredUsername() === '') {
|
||||
// $this->setType('Invalid');
|
||||
// }
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @param array $data
|
||||
*/
|
||||
public function importFromDatabase(array $data) {
|
||||
parent::importFromDatabase($data);
|
||||
$this->setPreferredUsername($this->get('preferred_username', $data, ''))
|
||||
->setName($this->get('name', $data, ''))
|
||||
->setAccount($this->get('account', $data, ''))
|
||||
|
@ -370,8 +406,8 @@ class Person extends ACore implements JsonSerializable {
|
|||
parent::jsonSerialize(),
|
||||
[
|
||||
'aliases' => [
|
||||
$this->getUrlRoot() . '@' . $this->getPreferredUsername(),
|
||||
$this->getUrlRoot() . 'users/' . $this->getPreferredUsername()
|
||||
$this->getUrlSocial() . '@' . $this->getPreferredUsername(),
|
||||
$this->getUrlSocial() . 'users/' . $this->getPreferredUsername()
|
||||
],
|
||||
'preferredUsername' => $this->getPreferredUsername(),
|
||||
'name' => $this->getName(),
|
||||
|
|
|
@ -34,7 +34,9 @@ namespace OCA\Social\Service\ActivityPub;
|
|||
use Exception;
|
||||
use OCA\Social\Db\FollowsRequest;
|
||||
use OCA\Social\Exceptions\ActorDoesNotExistException;
|
||||
use OCA\Social\Exceptions\CacheActorDoesNotExistException;
|
||||
use OCA\Social\Exceptions\FollowDoesNotExistException;
|
||||
use OCA\Social\Exceptions\InvalidResourceException;
|
||||
use OCA\Social\Exceptions\RequestException;
|
||||
use OCA\Social\Exceptions\SocialAppConfigException;
|
||||
use OCA\Social\Model\ActivityPub\ACore;
|
||||
|
@ -96,14 +98,17 @@ class FollowService implements ICoreService {
|
|||
* @param Person $actor
|
||||
* @param string $account
|
||||
*
|
||||
* @throws ActorDoesNotExistException
|
||||
* @throws RequestException
|
||||
* @throws SocialAppConfigException
|
||||
* @throws ActorDoesNotExistException
|
||||
* @throws CacheActorDoesNotExistException
|
||||
* @throws InvalidResourceException
|
||||
*/
|
||||
public function followAccount(Person $actor, string $account) {
|
||||
$remoteActor = $this->personService->getFromAccount($account);
|
||||
$follow = new Follow();
|
||||
$follow->generateUniqueId($this->configService->getCloudAddress());
|
||||
$follow->setUrlCloud($this->configService->getCloudAddress());
|
||||
$follow->generateUniqueId();
|
||||
$follow->setActorId($actor->getId());
|
||||
$follow->setObjectId($remoteActor->getId());
|
||||
|
||||
|
@ -124,6 +129,8 @@ class FollowService implements ICoreService {
|
|||
* @param Person $actor
|
||||
* @param string $account
|
||||
*
|
||||
* @throws CacheActorDoesNotExistException
|
||||
* @throws InvalidResourceException
|
||||
* @throws RequestException
|
||||
*/
|
||||
public function unfollowAccount(Person $actor, string $account) {
|
||||
|
|
|
@ -126,7 +126,7 @@ class NoteService implements ICoreService {
|
|||
$note->setId($this->configService->generateId('@' . $actor->getPreferredUsername()));
|
||||
$note->setPublished(date("c"));
|
||||
$note->setAttributedTo(
|
||||
$this->configService->getUrlRoot() . '@' . $actor->getPreferredUsername()
|
||||
$this->configService->getUrlSocial() . '@' . $actor->getPreferredUsername()
|
||||
);
|
||||
|
||||
$this->setRecipient($note, $actor, $type);
|
||||
|
|
|
@ -309,7 +309,7 @@ class ActivityService {
|
|||
$localActor = $this->getActorFromItem($activity);
|
||||
|
||||
$localActorLink =
|
||||
$this->configService->getUrlRoot() . '@' . $localActor->getPreferredUsername();
|
||||
$this->configService->getUrlSocial() . '@' . $localActor->getPreferredUsername();
|
||||
$signature = "(request-target): post " . $path->getPath() . "\nhost: " . $path->getAddress()
|
||||
. "\ndate: " . $date;
|
||||
|
||||
|
|
|
@ -153,6 +153,7 @@ class ImportService {
|
|||
throw new UnknownItemException();
|
||||
}
|
||||
|
||||
$item->setUrlCloud($this->configService->getCloudAddress());
|
||||
$item->import($data);
|
||||
$item->setSource(json_encode($data, JSON_UNESCAPED_SLASHES));
|
||||
|
||||
|
|
Ładowanie…
Reference in New Issue