]> git.mxchange.org Git - friendica.git/blobdiff - src/Module/Api/Mastodon/Statuses.php
Merge pull request #12004 from annando/priorities
[friendica.git] / src / Module / Api / Mastodon / Statuses.php
index ad76e3ad7e29b87cd8e7e1d07b483a2785e927b9..8cc3e3ddf2a53af8fbe8e24aeebcd52d2296d246 100644 (file)
@@ -1,6 +1,6 @@
 <?php
 /**
- * @copyright Copyright (C) 2010-2021, the Friendica project
+ * @copyright Copyright (C) 2010-2022, the Friendica project
  *
  * @license GNU AGPL version 3 or any later version
  *
 
 namespace Friendica\Module\Api\Mastodon;
 
-use Friendica\Content\Text\BBCode;
+use Friendica\App\Router;
 use Friendica\Content\Text\Markdown;
+use Friendica\Core\Protocol;
 use Friendica\Core\System;
+use Friendica\Core\Worker;
 use Friendica\Database\DBA;
 use Friendica\DI;
 use Friendica\Model\Contact;
@@ -41,6 +43,14 @@ use Friendica\Util\Images;
  */
 class Statuses extends BaseApi
 {
+       public function put(array $request = [])
+       {
+               self::checkAllowedScope(self::SCOPE_WRITE);
+               $uid = self::getCurrentUserID();
+
+               $this->response->unsupported(Router::PUT, $request);
+       }
+
        protected function post(array $request = [])
        {
                self::checkAllowedScope(self::SCOPE_WRITE);
@@ -63,17 +73,12 @@ class Statuses extends BaseApi
                // The imput is defined as text. So we can use Markdown for some enhancements
                $body = Markdown::toBBCode($request['status']);
 
-               // Avoids potential double expansion of existing links
-               $body = BBCode::performWithEscapedTags($body, ['url'], function ($body) {
-                       return BBCode::expandTags($body);
-               });
-
-               $item = [];
+               $item               = [];
+               $item['network']    = Protocol::DFRN;
                $item['uid']        = $uid;
                $item['verb']       = Activity::POST;
                $item['contact-id'] = $owner['id'];
                $item['author-id']  = $item['owner-id'] = Contact::getPublicIdByUserId($uid);
-               $item['title']      = $request['spoiler_text'];
                $item['body']       = $body;
 
                if (!empty(self::getCurrentApplication()['name'])) {
@@ -114,14 +119,20 @@ class Statuses extends BaseApi
                                $item['private'] = Item::PRIVATE;
                                break;
                        case 'direct':
-                               // Direct messages are currently unsupported
-                               DI::mstdnError()->InternalError('Direct messages are currently unsupported');
+                               // The permissions are assigned in "expandTags"
                                break;
                        default:
-                               $item['allow_cid'] = $owner['allow_cid'];
-                               $item['allow_gid'] = $owner['allow_gid'];
-                               $item['deny_cid']  = $owner['deny_cid'];
-                               $item['deny_gid']  = $owner['deny_gid'];
+                               if (is_numeric($request['visibility']) && Group::exists($request['visibility'], $uid)) {
+                                       $item['allow_cid'] = '';
+                                       $item['allow_gid'] = '<' . $request['visibility'] . '>';
+                                       $item['deny_cid']  = '';
+                                       $item['deny_gid']  = '';
+                               } else {
+                                       $item['allow_cid'] = $owner['allow_cid'];
+                                       $item['allow_gid'] = $owner['allow_gid'];
+                                       $item['deny_cid']  = $owner['deny_cid'];
+                                       $item['deny_gid']  = $owner['deny_gid'];
+                               }
 
                                if (!empty($item['allow_cid'] . $item['allow_gid'] . $item['deny_cid'] . $item['deny_gid'])) {
                                        $item['private'] = Item::PRIVATE;
@@ -139,16 +150,21 @@ class Statuses extends BaseApi
 
                if ($request['in_reply_to_id']) {
                        $parent = Post::selectFirst(['uri'], ['uri-id' => $request['in_reply_to_id'], 'uid' => [0, $uid]]);
+
                        $item['thr-parent']  = $parent['uri'];
                        $item['gravity']     = GRAVITY_COMMENT;
                        $item['object-type'] = Activity\ObjectType::COMMENT;
+                       $item['body']        = '[abstract=' . Protocol::ACTIVITYPUB . ']' . $request['spoiler_text'] . "[/abstract]\n" . $item['body'];
                } else {
                        self::checkThrottleLimit();
 
                        $item['gravity']     = GRAVITY_PARENT;
                        $item['object-type'] = Activity\ObjectType::NOTE;
+                       $item['title']       = $request['spoiler_text'];
                }
 
+               $item = DI::contentItem()->expandTags($item, $request['visibility'] == 'direct');
+
                if (!empty($request['media_ids'])) {
                        $item['object-type'] = Activity\ObjectType::IMAGE;
                        $item['post-type']   = Item::PT_IMAGE;
@@ -188,8 +204,8 @@ class Statuses extends BaseApi
 
                if (!empty($request['scheduled_at'])) {
                        $item['guid'] = Item::guid($item, true);
-                       $item['uri'] = Item::newURI($item['uid'], $item['guid']);
-                       $id = Post\Delayed::add($item['uri'], $item, PRIORITY_HIGH, Post\Delayed::PREPARED, $request['scheduled_at']);
+                       $item['uri'] = Item::newURI($item['guid']);
+                       $id = Post\Delayed::add($item['uri'], $item, Worker::PRIORITY_HIGH, Post\Delayed::PREPARED, $request['scheduled_at']);
                        if (empty($id)) {
                                DI::mstdnError()->InternalError();
                        }