]> git.mxchange.org Git - friendica.git/blobdiff - src/Module/Diaspora/Receive.php
spelling: protocol
[friendica.git] / src / Module / Diaspora / Receive.php
index 088d6a3b63c0a05fd6223a2d347c21ff556a65a3..4df2192d394c06dfe34cbf698342f89a2df476df 100644 (file)
@@ -1,6 +1,6 @@
 <?php
 /**
- * @copyright Copyright (C) 2010-2021, the Friendica project
+ * @copyright Copyright (C) 2010-2023, the Friendica project
  *
  * @license GNU AGPL version 3 or any later version
  *
 
 namespace Friendica\Module\Diaspora;
 
+use Friendica\App;
 use Friendica\BaseModule;
 use Friendica\Core\Config\Capability\IManageConfigValues;
 use Friendica\Core\L10n;
 use Friendica\Model\User;
+use Friendica\Module\Response;
 use Friendica\Network\HTTPException;
 use Friendica\Protocol\Diaspora;
 use Friendica\Util\Network;
+use Friendica\Util\Profiler;
 use Psr\Log\LoggerInterface;
 
 /**
@@ -36,25 +39,22 @@ use Psr\Log\LoggerInterface;
  */
 class Receive extends BaseModule
 {
-       /** @var LoggerInterface */
-       protected $logger;
        /** @var IManageConfigValues */
        protected $config;
 
-       public function __construct(LoggerInterface $logger, IManageConfigValues $config, L10n $l10n, array $parameters = [])
+       public function __construct(L10n $l10n, App\BaseURL $baseUrl, App\Arguments $args, LoggerInterface $logger, Profiler $profiler, Response $response, IManageConfigValues $config, array $server, array $parameters = [])
        {
-               parent::__construct($l10n, $parameters);
-               
-               $this->logger = $logger;
+               parent::__construct($l10n, $baseUrl, $args, $logger, $profiler, $response, $server, $parameters);
+
                $this->config = $config;
        }
 
-       public function post()
+       protected function post(array $request = [])
        {
                $enabled = $this->config->get('system', 'diaspora_enabled', false);
                if (!$enabled) {
                        $this->logger->info('Diaspora disabled.');
-                       throw new HTTPException\ForbiddenException($this->l10n->t('Access denied.'));
+                       throw new HTTPException\ForbiddenException($this->t('Access denied.'));
                }
 
                if ($this->parameters['type'] === 'public') {
@@ -67,6 +67,7 @@ class Receive extends BaseModule
        /**
         * Receive a public Diaspora posting
         *
+        * @return void
         * @throws HTTPException\InternalServerErrorException
         * @throws \ImagickException
         */
@@ -78,12 +79,13 @@ class Receive extends BaseModule
 
                $this->logger->info('Diaspora: Dispatching.');
 
-               Diaspora::dispatchPublic($msg);
+               Diaspora::dispatchPublic($msg, Diaspora::PUSHED);
        }
 
        /**
         * Receive a Diaspora posting for a user
         *
+        * @return void
         * @throws HTTPException\InternalServerErrorException
         * @throws \ImagickException
         */
@@ -92,8 +94,19 @@ class Receive extends BaseModule
                $this->logger->info('Diaspora: Receiving post.');
 
                $importer = User::getByGuid($this->parameters['guid']);
+               if (empty($importer)) {
+                       // We haven't found the user.
+                       // To avoid the remote system trying again we send the message that we accepted the content.
+                       throw new HTTPException\AcceptedException();
+               }
+
+               if ($importer['account-type'] == User::ACCOUNT_TYPE_COMMUNITY) {
+                       // Communities aren't working with the Diaspora protocol
+                       // We throw an "accepted" here, so that the sender doesn't repeat the delivery
+                       throw new HTTPException\AcceptedException();
+               }
 
-               $msg = $this->decodePost(false, $importer['prvkey'] ?? '');
+               $msg = $this->decodePost(false, $importer['prvkey']);
 
                $this->logger->info('Diaspora: Dispatching.');
 
@@ -116,7 +129,7 @@ class Receive extends BaseModule
         * @throws HTTPException\InternalServerErrorException
         * @throws \ImagickException
         */
-       private function decodePost(bool $public = true, string $privKey = '')
+       private function decodePost(bool $public = true, string $privKey = ''): array
        {
                if (empty($_POST['xml'])) {