Add exact matches to the search

Signed-off-by: Julius Härtl <jus@bitgrid.net>
pull/18/head
Julius Härtl 2018-11-16 12:47:14 +01:00
rodzic b022dd039d
commit 61d0ce3d46
Nie znaleziono w bazie danych klucza dla tego podpisu
ID klucza GPG: 4C614C6ED2CDE6DF
4 zmienionych plików z 20 dodań i 2 usunięć

Wyświetl plik

@ -35,6 +35,7 @@ use daita\MySmallPhpTools\Traits\Nextcloud\TNCDataResponse;
use Exception;
use OCA\Social\AppInfo\Application;
use OCA\Social\Exceptions\InvalidResourceException;
use OCA\Social\Exceptions\RequestException;
use OCA\Social\Model\Post;
use OCA\Social\Service\ActivityPub\FollowService;
use OCA\Social\Service\ActivityPub\NoteService;
@ -228,10 +229,17 @@ class LocalController extends Controller {
* @return DataResponse
*/
public function accountsSearch(string $search): DataResponse {
/* Look for an exactly matching account */
$match = null;
try {
$match = $this->personService->getFromAccount($search);
} catch (Exception $e) {
}
try {
$accounts = $this->personService->searchCachedAccounts($search);
return $this->success(['accounts' => $accounts]);
return $this->success(['accounts' => $accounts, 'exact' => $match]);
} catch (Exception $e) {
return $this->fail($e);
}

Wyświetl plik

@ -162,6 +162,9 @@ class PersonService implements ICoreService {
$actor = $this->cacheActorsRequest->getFromAccount($account);
} catch (CacheActorDoesNotExistException $e) {
$object = $this->instanceService->retrieveAccount($account);
if ($object === null) {
throw new InvalidResourceException();
}
$actor = new Person();
$actor->import($object);

Wyświetl plik

@ -73,7 +73,10 @@ class CurlService {
// $this->parseRequestResultCode500($code);
// $this->parseRequestResult($result);
$ret = json_decode($result, true);
$ret = json_decode((string)$result, true);
if ($ret === null) {
throw new RequestException('500 Internal server error - could not parse JSON response');
}
if (!is_array($ret)) {
$ret = ['_result' => $result];
}

Wyświetl plik

@ -83,6 +83,10 @@ class InstanceService {
list($username, $host) = explode('@', $account);
if ($username === null || $host === null) {
return;
}
$request = new Request('/.well-known/webfinger');
$request->addData('resource', 'acct:' . $account);
$request->setAddress($host);