Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Next Next commit
using IWebfingerManager
Signed-off-by: Maxence Lange <[email protected]>
  • Loading branch information
ArtificialOwl committed Sep 23, 2020
commit 888d9931413f5ddbb540ca8d9ca4833cf74ddbde
1 change: 1 addition & 0 deletions appinfo/app.php
Original file line number Diff line number Diff line change
Expand Up @@ -37,5 +37,6 @@
$app = \OC::$server->query(Application::class);

$app->checkUpgradeStatus();
$app->registerWebfinger();


24 changes: 24 additions & 0 deletions lib/AppInfo/Application.php
Original file line number Diff line number Diff line change
Expand Up @@ -32,12 +32,16 @@


use OC\DB\SchemaWrapper;
use OC\Webfinger\Event\WebfingerEvent;
use OC\Webfinger\Model\WebfingerObject;
use OCA\Social\Notification\Notifier;
use OCA\Social\Service\ConfigService;
use OCA\Social\Service\UpdateService;
use OCA\Social\Service\WebfingerService;
use OCP\AppFramework\App;
use OCP\AppFramework\IAppContainer;
use OCP\AppFramework\QueryException;
use OCP\EventDispatcher\IEventDispatcher;


/**
Expand Down Expand Up @@ -77,6 +81,26 @@ public function __construct(array $params = []) {
}


/**
*
*/
public function registerWebfinger() {
/** @var IEventDispatcher $eventDispatcher */
$eventDispatcher = \OC::$server->query(IEventDispatcher::class);
$eventDispatcher->addListener(
'\OC\Webfinger::onRequest',
function(WebfingerEvent $e) {
/** @var WebfingerService $webfingerService */
$webfingerService = $this->container->query(WebfingerService::class);
try {
$webfingerService->webfinger($e);
} catch (\Exception $e) {
}
}
);
}


/**
*
*/
Expand Down
4 changes: 1 addition & 3 deletions lib/Db/StreamActionsRequest.php
Original file line number Diff line number Diff line change
Expand Up @@ -96,9 +96,7 @@ public function update(StreamAction $action): int {
$this->limitToActorId($qb, $action->getActorId());
$this->limitToStreamId($qb, $action->getStreamId());

$count = $qb->execute();

return $count;
return $qb->execute();
}


Expand Down
148 changes: 148 additions & 0 deletions lib/Model/WebfingerLink.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,148 @@
<?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 <[email protected]>
* @copyright 2018, Maxence Lange <[email protected]>
* @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;

use JsonSerializable;


/**
* Class WebfingerLink
*
* @package OCA\Social\Model
*/
class WebfingerLink implements JsonSerializable {


/** @var string */
private $href = '';

/** @var string */
private $rel = '';

/** @var string */
private $template = '';

/** @var string */
private $type = '';


/**
* @return string
*/
public function getHref(): string {
return $this->href;
}

/**
* @param string $value
*
* @return WebfingerLink
*/
public function setHref(string $value): self {
$this->href = $value;

return $this;
}


/**
* @return string
*/
public function getType(): string {
return $this->type;
}

/**
* @param string $value
*
* @return WebfingerLink
*/
public function setType(string $value): self {
$this->type = $value;

return $this;
}


/**
* @return string
*/
public function getRel(): string {
return $this->rel;
}

/**
* @param string $value
*
* @return WebfingerLink
*/
public function setRel(string $value): self {
$this->rel = $value;

return $this;
}


/**
* @return string
*/
public function getTemplate(): string {
return $this->template;
}

/**
* @param string $value
*
* @return WebfingerLink
*/
public function setTemplate(string $value): self {
$this->template = $value;

return $this;
}


/**
* @return array
*/
public function jsonSerialize(): array {
$data = [
'rel' => $this->getRel(),
'type' => $this->getType(),
'template' => $this->getTemplate(),
'href' => $this->getHref()
];

return array_filter($data);
}

}

8 changes: 8 additions & 0 deletions lib/Service/ActorService.php
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@
use OCA\Social\Db\CacheDocumentsRequest;
use OCA\Social\Exceptions\CacheActorDoesNotExistException;
use OCA\Social\Exceptions\CacheDocumentDoesNotExistException;
use OCA\Social\Exceptions\ItemAlreadyExistsException;
use OCA\Social\Exceptions\ItemUnknownException;
use OCA\Social\Model\ActivityPub\Actor\Person;

Expand Down Expand Up @@ -92,6 +93,8 @@ public function __construct(

/**
* @param Person $actor
*
* @throws ItemAlreadyExistsException
*/
public function cacheLocalActor(Person $actor) {
$actor->setLocal(true);
Expand All @@ -108,6 +111,8 @@ public function cacheLocalActor(Person $actor) {

/**
* @param Person $actor
*
* @throws ItemAlreadyExistsException
*/
public function save(Person $actor) {
$this->cacheDocumentIfNeeded($actor);
Expand All @@ -119,6 +124,7 @@ public function save(Person $actor) {
* @param Person $actor
*
* @return int
* @throws ItemAlreadyExistsException
*/
public function update(Person $actor): int {
$this->cacheDocumentIfNeeded($actor);
Expand All @@ -129,6 +135,8 @@ public function update(Person $actor): int {

/**
* @param Person $actor
*
* @throws ItemAlreadyExistsException
*/
private function cacheDocumentIfNeeded(Person $actor) {
if ($actor->hasIcon()) {
Expand Down
18 changes: 15 additions & 3 deletions lib/Service/CacheActorService.php
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,7 @@
use OCA\Social\Exceptions\SocialAppConfigException;
use OCA\Social\Exceptions\UnauthorizedFediverseException;
use OCA\Social\Model\ActivityPub\Actor\Person;
use OCP\IURLGenerator;


class CacheActorService {
Expand All @@ -58,12 +59,18 @@ class CacheActorService {
use TArrayTools;


/** @var IURLGenerator */
private $urlGenerator;

/** @var CacheActorsRequest */
private $cacheActorsRequest;

/** @var CurlService */
private $curlService;

/** @var FediverseService */
private $fediverseService;

/** @var ConfigService */
private $configService;

Expand All @@ -74,17 +81,21 @@ class CacheActorService {
/**
* CacheService constructor.
*
* @param IUrlGenerator $urlGenerator
* @param CacheActorsRequest $cacheActorsRequest
* @param CurlService $curlService
* @param FediverseService $fediverseService
* @param ConfigService $configService
* @param MiscService $miscService
*/
public function __construct(
CacheActorsRequest $cacheActorsRequest, CurlService $curlService,
ConfigService $configService, MiscService $miscService
IUrlGenerator $urlGenerator, CacheActorsRequest $cacheActorsRequest, CurlService $curlService,
FediverseService $fediverseService, ConfigService $configService, MiscService $miscService
) {
$this->urlGenerator = $urlGenerator;
$this->cacheActorsRequest = $cacheActorsRequest;
$this->curlService = $curlService;
$this->fediverseService = $fediverseService;
$this->configService = $configService;
$this->miscService = $miscService;
}
Expand Down Expand Up @@ -166,8 +177,9 @@ public function getFromId(string $id, bool $refresh = false): Person {
*/
public function getFromLocalAccount(string $account): Person {
$instance = '';
$account = ltrim($account, '@');
if (strrpos($account, '@')) {
list($account, $instance) = explode('@', $account);
list($account, $instance) = explode('@', $account, 2);
}

if ($instance === ''
Expand Down
Loading