kopia lustrzana https://github.com/nextcloud/social
fixing stuff
Signed-off-by: Maxence Lange <maxence@artificial-owl.com>pull/50/head
rodzic
21d7cbf613
commit
ffde0920cf
|
@ -36,6 +36,7 @@ use Exception;
|
||||||
use OCA\Social\AppInfo\Application;
|
use OCA\Social\AppInfo\Application;
|
||||||
use OCA\Social\Exceptions\InvalidResourceException;
|
use OCA\Social\Exceptions\InvalidResourceException;
|
||||||
use OCA\Social\Exceptions\RequestException;
|
use OCA\Social\Exceptions\RequestException;
|
||||||
|
use OCA\Social\Model\ActivityPub\ACore;
|
||||||
use OCA\Social\Model\Post;
|
use OCA\Social\Model\Post;
|
||||||
use OCA\Social\Service\ActivityPub\FollowService;
|
use OCA\Social\Service\ActivityPub\FollowService;
|
||||||
use OCA\Social\Service\ActivityPub\NoteService;
|
use OCA\Social\Service\ActivityPub\NoteService;
|
||||||
|
@ -133,9 +134,10 @@ class LocalController extends Controller {
|
||||||
$post->addTo($this->get('to', $data, ''));
|
$post->addTo($this->get('to', $data, ''));
|
||||||
$post->setType($this->get('type', $data, NoteService::TYPE_PUBLIC));
|
$post->setType($this->get('type', $data, NoteService::TYPE_PUBLIC));
|
||||||
|
|
||||||
$result = $this->postService->createPost($post);
|
/** @var ACore $activity */
|
||||||
|
$result = $this->postService->createPost($post, $activity);
|
||||||
|
|
||||||
return $this->success($result);
|
return $this->directSuccess($activity->getObject());
|
||||||
} catch (Exception $e) {
|
} catch (Exception $e) {
|
||||||
return $this->fail($e);
|
return $this->fail($e);
|
||||||
}
|
}
|
||||||
|
@ -229,7 +231,7 @@ class LocalController extends Controller {
|
||||||
/* Look for an exactly matching account */
|
/* Look for an exactly matching account */
|
||||||
$match = null;
|
$match = null;
|
||||||
try {
|
try {
|
||||||
$match = $this->personService->getFromAccount($search);
|
$match = $this->personService->getFromAccount($search, false);
|
||||||
} catch (Exception $e) {
|
} catch (Exception $e) {
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -193,7 +193,7 @@ class CoreRequestBuilder {
|
||||||
* @param string $account
|
* @param string $account
|
||||||
*/
|
*/
|
||||||
protected function limitToAccount(IQueryBuilder &$qb, string $account) {
|
protected function limitToAccount(IQueryBuilder &$qb, string $account) {
|
||||||
$this->limitToDBField($qb, 'account', $account);
|
$this->limitToDBField($qb, 'account', $account, false);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@ -284,8 +284,9 @@ class CoreRequestBuilder {
|
||||||
* @param IQueryBuilder $qb
|
* @param IQueryBuilder $qb
|
||||||
* @param string $field
|
* @param string $field
|
||||||
* @param string|integer|array $values
|
* @param string|integer|array $values
|
||||||
|
* @param bool $cs Case Sensitive
|
||||||
*/
|
*/
|
||||||
private function limitToDBField(IQueryBuilder &$qb, $field, $values) {
|
private function limitToDBField(IQueryBuilder &$qb, string $field, $values, bool $cs = true) {
|
||||||
$expr = $qb->expr();
|
$expr = $qb->expr();
|
||||||
$pf = ($qb->getType() === QueryBuilder::SELECT) ? $this->defaultSelectAlias . '.' : '';
|
$pf = ($qb->getType() === QueryBuilder::SELECT) ? $this->defaultSelectAlias . '.' : '';
|
||||||
$field = $pf . $field;
|
$field = $pf . $field;
|
||||||
|
@ -296,7 +297,11 @@ class CoreRequestBuilder {
|
||||||
|
|
||||||
$orX = $expr->orX();
|
$orX = $expr->orX();
|
||||||
foreach ($values as $value) {
|
foreach ($values as $value) {
|
||||||
$orX->add($expr->eq($field, $qb->createNamedParameter($value)));
|
if ($cs) {
|
||||||
|
$orX->add($expr->eq($field, $qb->createNamedParameter($value)));
|
||||||
|
} else {
|
||||||
|
$orX->add($expr->iLike($field, $qb->createNamedParameter($value)));
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
$qb->andWhere($orX);
|
$qb->andWhere($orX);
|
||||||
|
@ -312,7 +317,7 @@ class CoreRequestBuilder {
|
||||||
$pf = ($qb->getType() === QueryBuilder::SELECT) ? $this->defaultSelectAlias . '.' : '';
|
$pf = ($qb->getType() === QueryBuilder::SELECT) ? $this->defaultSelectAlias . '.' : '';
|
||||||
$field = $pf . $field;
|
$field = $pf . $field;
|
||||||
|
|
||||||
$qb->andWhere($expr->like($field, $qb->createNamedParameter($value)));
|
$qb->andWhere($expr->iLike($field, $qb->createNamedParameter($value)));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -126,8 +126,10 @@ class NotesRequestBuilder extends CoreRequestBuilder {
|
||||||
->setInReplyTo($data['in_reply_to']);
|
->setInReplyTo($data['in_reply_to']);
|
||||||
|
|
||||||
$instances = json_decode($data['instances'], true);
|
$instances = json_decode($data['instances'], true);
|
||||||
foreach ($instances as $instance) {
|
if (is_array($instances)) {
|
||||||
$note->addInstancePath(new InstancePath($instance['uri'], $instance['type']));
|
foreach ($instances as $instance) {
|
||||||
|
$note->addInstancePath(new InstancePath($instance['uri'], $instance['type']));
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
try {
|
try {
|
||||||
|
|
|
@ -30,6 +30,7 @@ declare(strict_types=1);
|
||||||
namespace OCA\Social\Service\ActivityPub;
|
namespace OCA\Social\Service\ActivityPub;
|
||||||
|
|
||||||
|
|
||||||
|
use Exception;
|
||||||
use OC\User\NoUserException;
|
use OC\User\NoUserException;
|
||||||
use OCA\Social\Db\NotesRequest;
|
use OCA\Social\Db\NotesRequest;
|
||||||
use OCA\Social\Exceptions\ActivityCantBeVerifiedException;
|
use OCA\Social\Exceptions\ActivityCantBeVerifiedException;
|
||||||
|
@ -179,15 +180,17 @@ class NoteService implements ICoreService {
|
||||||
* @param Note $note
|
* @param Note $note
|
||||||
* @param string $type
|
* @param string $type
|
||||||
* @param string $account
|
* @param string $account
|
||||||
*
|
|
||||||
* @throws RequestException
|
|
||||||
*/
|
*/
|
||||||
public function addRecipient(Note $note, string $type, string $account) {
|
public function addRecipient(Note $note, string $type, string $account) {
|
||||||
if ($account === '') {
|
if ($account === '') {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
$actor = $this->personService->getFromAccount($account);
|
try {
|
||||||
|
$actor = $this->personService->getFromAccount($account);
|
||||||
|
} catch (Exception $e) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
if ($type === self::TYPE_DIRECT) {
|
if ($type === self::TYPE_DIRECT) {
|
||||||
$note->addToArray($actor->getId());
|
$note->addToArray($actor->getId());
|
||||||
|
|
|
@ -152,19 +152,24 @@ class PersonService implements ICoreService {
|
||||||
/**
|
/**
|
||||||
* @param string $account
|
* @param string $account
|
||||||
*
|
*
|
||||||
|
* @param bool $retrieve
|
||||||
|
*
|
||||||
* @return Person
|
* @return Person
|
||||||
|
* @throws InvalidResourceException
|
||||||
* @throws RequestException
|
* @throws RequestException
|
||||||
* @throws Exception
|
* @throws CacheActorDoesNotExistException
|
||||||
*/
|
*/
|
||||||
public function getFromAccount(string $account): Person {
|
public function getFromAccount(string $account, bool $retrieve = true): Person {
|
||||||
|
|
||||||
try {
|
try {
|
||||||
$actor = $this->cacheActorsRequest->getFromAccount($account);
|
$actor = $this->cacheActorsRequest->getFromAccount($account);
|
||||||
} catch (CacheActorDoesNotExistException $e) {
|
} catch (CacheActorDoesNotExistException $e) {
|
||||||
$object = $this->instanceService->retrieveAccount($account);
|
if (!$retrieve) {
|
||||||
if ($object === null) {
|
throw new CacheActorDoesNotExistException();
|
||||||
throw new InvalidResourceException();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
$object = $this->instanceService->retrieveAccount($account);
|
||||||
|
|
||||||
$actor = new Person();
|
$actor = new Person();
|
||||||
$actor->import($object);
|
$actor->import($object);
|
||||||
|
|
||||||
|
@ -207,11 +212,7 @@ class PersonService implements ICoreService {
|
||||||
*/
|
*/
|
||||||
public function parse(ACore $person) {
|
public function parse(ACore $person) {
|
||||||
/** @var Person $person */
|
/** @var Person $person */
|
||||||
if ($person->isRoot() === false) {
|
if ($person->isRoot() === false || $person->getId() === '') {
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
if ($person->getId() === '') {
|
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -74,9 +74,9 @@ class CurlService {
|
||||||
// $this->parseRequestResult($result);
|
// $this->parseRequestResult($result);
|
||||||
|
|
||||||
$ret = json_decode((string)$result, true);
|
$ret = json_decode((string)$result, true);
|
||||||
if ($ret === null) {
|
// if ($ret === null) {
|
||||||
throw new RequestException('500 Internal server error - could not parse JSON response');
|
// throw new RequestException('500 Internal server error - could not parse JSON response');
|
||||||
}
|
// }
|
||||||
if (!is_array($ret)) {
|
if (!is_array($ret)) {
|
||||||
$ret = ['_result' => $result];
|
$ret = ['_result' => $result];
|
||||||
}
|
}
|
||||||
|
|
|
@ -34,6 +34,7 @@ use daita\MySmallPhpTools\Exceptions\ArrayNotFoundException;
|
||||||
use daita\MySmallPhpTools\Model\Request;
|
use daita\MySmallPhpTools\Model\Request;
|
||||||
use daita\MySmallPhpTools\Traits\TArrayTools;
|
use daita\MySmallPhpTools\Traits\TArrayTools;
|
||||||
use daita\MySmallPhpTools\Traits\TPathTools;
|
use daita\MySmallPhpTools\Traits\TPathTools;
|
||||||
|
use OCA\Social\Exceptions\InvalidResourceException;
|
||||||
use OCA\Social\Exceptions\RequestException;
|
use OCA\Social\Exceptions\RequestException;
|
||||||
use OCA\Social\Model\ActivityPub\ACore;
|
use OCA\Social\Model\ActivityPub\ACore;
|
||||||
use OCA\Social\Model\Instance;
|
use OCA\Social\Model\Instance;
|
||||||
|
@ -77,15 +78,20 @@ class InstanceService {
|
||||||
*
|
*
|
||||||
* @return mixed
|
* @return mixed
|
||||||
* @throws RequestException
|
* @throws RequestException
|
||||||
|
* @throws InvalidResourceException
|
||||||
*/
|
*/
|
||||||
public function retrieveAccount(string $account) {
|
public function retrieveAccount(string $account) {
|
||||||
$account = $this->withoutBeginAt($account);
|
$account = $this->withoutBeginAt($account);
|
||||||
|
|
||||||
|
if (strstr(substr($account, 0, -3), '@') === false)
|
||||||
|
{
|
||||||
|
throw new InvalidResourceException();
|
||||||
|
}
|
||||||
list($username, $host) = explode('@', $account);
|
list($username, $host) = explode('@', $account);
|
||||||
|
|
||||||
if ($username === null || $host === null) {
|
// if ($username === null || $host === null) {
|
||||||
return;
|
// throw new InvalidResourceException();
|
||||||
}
|
// }
|
||||||
|
|
||||||
$request = new Request('/.well-known/webfinger');
|
$request = new Request('/.well-known/webfinger');
|
||||||
$request->addData('resource', 'acct:' . $account);
|
$request->addData('resource', 'acct:' . $account);
|
||||||
|
|
Ładowanie…
Reference in New Issue