]> git.mxchange.org Git - friendica.git/blobdiff - src/Module/Item/Activity.php
spelling: parameter
[friendica.git] / src / Module / Item / Activity.php
index e731b05b80043bde995c5050c89ca3d831157169..c9d192d249f07458ca66cfe613c0c5126231d0f4 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\Item;
 
 use Friendica\BaseModule;
-use Friendica\Core\Logger;
 use Friendica\Core\Protocol;
 use Friendica\Core\System;
 use Friendica\DI;
 use Friendica\Model\Item;
-use Friendica\Core\Session;
 use Friendica\Model\Post;
 use Friendica\Network\HTTPException;
 use Friendica\Protocol\Diaspora;
@@ -40,7 +38,7 @@ class Activity extends BaseModule
 {
        protected function rawContent(array $request = [])
        {
-               if (!Session::isAuthenticated()) {
+               if (!DI::userSession()->isAuthenticated()) {
                        throw new HTTPException\ForbiddenException();
                }
 
@@ -48,21 +46,26 @@ class Activity extends BaseModule
                        throw new HTTPException\BadRequestException();
                }
 
-               $verb = $this->parameters['verb'];
-               $itemId =  $this->parameters['id'];
-Logger::info('Blubb-1', ['id' => $itemId, 'verb' => $verb]);
+               $verb    = $this->parameters['verb'];
+               $itemId  = $this->parameters['id'];
+               $handled = false;
+
                if (in_array($verb, ['announce', 'unannounce'])) {
-                       $item = Post::selectFirst(['network', 'uri-id', 'uid'], ['id' => $itemId]);
-                       Logger::info('Blubb-2', ['id' => $itemId, 'item' => $item]);
+                       $item = Post::selectFirst(['network', 'uri-id'], ['id' => $itemId, 'uid' => [DI::userSession()->getLocalUserId(), 0]]);
                        if ($item['network'] == Protocol::DIASPORA) {
-                               Logger::info('Blubb-3', ['id' => $itemId]);
-                               $id = Diaspora::performReshare($item['uri-id'], $item['uid']);
-                               Logger::info('Blubb-ende', ['id' => $id]);
+                               $quote = Post::selectFirst(['id'], ['quote-uri-id' => $item['uri-id'], 'body' => '', 'origin' => true, 'uid' => DI::userSession()->getLocalUserId()]);
+                               if (!empty($quote['id'])) {
+                                       if (!Item::markForDeletionById($quote['id'])) {
+                                               throw new HTTPException\BadRequestException();
+                                       }
+                               } else {
+                                       Diaspora::performReshare($item['uri-id'], DI::userSession()->getLocalUserId());
+                               }
+                               $handled = true;
                        }
                }
-               Logger::info('Blubb-activity', ['id' => $itemId]);
 
-               if (!Item::performActivity($itemId, $verb, local_user())) {
+               if (!$handled && !Item::performActivity($itemId, $verb, DI::userSession()->getLocalUserId())) {
                        throw new HTTPException\BadRequestException();
                }