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\Exceptions\InvalidResourceException;
|
||||
use OCA\Social\Exceptions\RequestException;
|
||||
use OCA\Social\Model\ActivityPub\ACore;
|
||||
use OCA\Social\Model\Post;
|
||||
use OCA\Social\Service\ActivityPub\FollowService;
|
||||
use OCA\Social\Service\ActivityPub\NoteService;
|
||||
|
@ -133,9 +134,10 @@ class LocalController extends Controller {
|
|||
$post->addTo($this->get('to', $data, ''));
|
||||
$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) {
|
||||
return $this->fail($e);
|
||||
}
|
||||
|
@ -229,7 +231,7 @@ class LocalController extends Controller {
|
|||
/* Look for an exactly matching account */
|
||||
$match = null;
|
||||
try {
|
||||
$match = $this->personService->getFromAccount($search);
|
||||
$match = $this->personService->getFromAccount($search, false);
|
||||
} catch (Exception $e) {
|
||||
}
|
||||
|
||||
|
|
|
@ -193,7 +193,7 @@ class CoreRequestBuilder {
|
|||
* @param 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 string $field
|
||||
* @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();
|
||||
$pf = ($qb->getType() === QueryBuilder::SELECT) ? $this->defaultSelectAlias . '.' : '';
|
||||
$field = $pf . $field;
|
||||
|
@ -296,7 +297,11 @@ class CoreRequestBuilder {
|
|||
|
||||
$orX = $expr->orX();
|
||||
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);
|
||||
|
@ -312,7 +317,7 @@ class CoreRequestBuilder {
|
|||
$pf = ($qb->getType() === QueryBuilder::SELECT) ? $this->defaultSelectAlias . '.' : '';
|
||||
$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']);
|
||||
|
||||
$instances = json_decode($data['instances'], true);
|
||||
foreach ($instances as $instance) {
|
||||
$note->addInstancePath(new InstancePath($instance['uri'], $instance['type']));
|
||||
if (is_array($instances)) {
|
||||
foreach ($instances as $instance) {
|
||||
$note->addInstancePath(new InstancePath($instance['uri'], $instance['type']));
|
||||
}
|
||||
}
|
||||
|
||||
try {
|
||||
|
|
|
@ -30,6 +30,7 @@ declare(strict_types=1);
|
|||
namespace OCA\Social\Service\ActivityPub;
|
||||
|
||||
|
||||
use Exception;
|
||||
use OC\User\NoUserException;
|
||||
use OCA\Social\Db\NotesRequest;
|
||||
use OCA\Social\Exceptions\ActivityCantBeVerifiedException;
|
||||
|
@ -179,15 +180,17 @@ class NoteService implements ICoreService {
|
|||
* @param Note $note
|
||||
* @param string $type
|
||||
* @param string $account
|
||||
*
|
||||
* @throws RequestException
|
||||
*/
|
||||
public function addRecipient(Note $note, string $type, string $account) {
|
||||
if ($account === '') {
|
||||
return;
|
||||
}
|
||||
|
||||
$actor = $this->personService->getFromAccount($account);
|
||||
try {
|
||||
$actor = $this->personService->getFromAccount($account);
|
||||
} catch (Exception $e) {
|
||||
return;
|
||||
}
|
||||
|
||||
if ($type === self::TYPE_DIRECT) {
|
||||
$note->addToArray($actor->getId());
|
||||
|
|
|
@ -152,19 +152,24 @@ class PersonService implements ICoreService {
|
|||
/**
|
||||
* @param string $account
|
||||
*
|
||||
* @param bool $retrieve
|
||||
*
|
||||
* @return Person
|
||||
* @throws InvalidResourceException
|
||||
* @throws RequestException
|
||||
* @throws Exception
|
||||
* @throws CacheActorDoesNotExistException
|
||||
*/
|
||||
public function getFromAccount(string $account): Person {
|
||||
public function getFromAccount(string $account, bool $retrieve = true): Person {
|
||||
|
||||
try {
|
||||
$actor = $this->cacheActorsRequest->getFromAccount($account);
|
||||
} catch (CacheActorDoesNotExistException $e) {
|
||||
$object = $this->instanceService->retrieveAccount($account);
|
||||
if ($object === null) {
|
||||
throw new InvalidResourceException();
|
||||
if (!$retrieve) {
|
||||
throw new CacheActorDoesNotExistException();
|
||||
}
|
||||
|
||||
$object = $this->instanceService->retrieveAccount($account);
|
||||
|
||||
$actor = new Person();
|
||||
$actor->import($object);
|
||||
|
||||
|
@ -207,11 +212,7 @@ class PersonService implements ICoreService {
|
|||
*/
|
||||
public function parse(ACore $person) {
|
||||
/** @var Person $person */
|
||||
if ($person->isRoot() === false) {
|
||||
return;
|
||||
}
|
||||
|
||||
if ($person->getId() === '') {
|
||||
if ($person->isRoot() === false || $person->getId() === '') {
|
||||
return;
|
||||
}
|
||||
|
||||
|
|
|
@ -74,9 +74,9 @@ class CurlService {
|
|||
// $this->parseRequestResult($result);
|
||||
|
||||
$ret = json_decode((string)$result, true);
|
||||
if ($ret === null) {
|
||||
throw new RequestException('500 Internal server error - could not parse JSON response');
|
||||
}
|
||||
// if ($ret === null) {
|
||||
// throw new RequestException('500 Internal server error - could not parse JSON response');
|
||||
// }
|
||||
if (!is_array($ret)) {
|
||||
$ret = ['_result' => $result];
|
||||
}
|
||||
|
|
|
@ -34,6 +34,7 @@ use daita\MySmallPhpTools\Exceptions\ArrayNotFoundException;
|
|||
use daita\MySmallPhpTools\Model\Request;
|
||||
use daita\MySmallPhpTools\Traits\TArrayTools;
|
||||
use daita\MySmallPhpTools\Traits\TPathTools;
|
||||
use OCA\Social\Exceptions\InvalidResourceException;
|
||||
use OCA\Social\Exceptions\RequestException;
|
||||
use OCA\Social\Model\ActivityPub\ACore;
|
||||
use OCA\Social\Model\Instance;
|
||||
|
@ -77,15 +78,20 @@ class InstanceService {
|
|||
*
|
||||
* @return mixed
|
||||
* @throws RequestException
|
||||
* @throws InvalidResourceException
|
||||
*/
|
||||
public function retrieveAccount(string $account) {
|
||||
$account = $this->withoutBeginAt($account);
|
||||
|
||||
if (strstr(substr($account, 0, -3), '@') === false)
|
||||
{
|
||||
throw new InvalidResourceException();
|
||||
}
|
||||
list($username, $host) = explode('@', $account);
|
||||
|
||||
if ($username === null || $host === null) {
|
||||
return;
|
||||
}
|
||||
// if ($username === null || $host === null) {
|
||||
// throw new InvalidResourceException();
|
||||
// }
|
||||
|
||||
$request = new Request('/.well-known/webfinger');
|
||||
$request->addData('resource', 'acct:' . $account);
|
||||
|
|
Ładowanie…
Reference in New Issue