]> git.mxchange.org Git - friendica.git/commitdiff
Respect the postopts values for scheduled posts
authorMichael <heluecht@pirati.ca>
Fri, 6 Aug 2021 18:49:17 +0000 (18:49 +0000)
committerMichael <heluecht@pirati.ca>
Fri, 6 Aug 2021 18:49:17 +0000 (18:49 +0000)
mod/item.php
src/Model/Item.php
src/Model/Post/Delayed.php
src/Module/Api/Mastodon/Statuses.php
src/Protocol/Feed.php
src/Worker/DelayedPublish.php

index 2a365f3da2ec85592e22d4cac0b331462c71af9a..809d6a18c20ad3b55835d3561a7cf4446116e613 100644 (file)
@@ -681,7 +681,11 @@ function item_post(App $a) {
                $o = conversation($a, [array_merge($contact_record, $datarray)], 'search', false, true);
 
                System::jsonExit(['preview' => $o]);
-       } elseif (!empty($_REQUEST['scheduled_at'])) {
+       }
+
+       Hook::callAll('post_local',$datarray);
+
+       if (!empty($_REQUEST['scheduled_at'])) {
                $scheduled_at = DateTimeFormat::convert($_REQUEST['scheduled_at'], 'UTC', $a->getTimezone());
                if ($scheduled_at > DateTimeFormat::utcNow()) {
                        unset($datarray['created']);
@@ -692,16 +696,12 @@ function item_post(App $a) {
                        unset($datarray['edit']);
                        unset($datarray['self']);
                        unset($datarray['api_source']);
-               
-                       Post\Delayed::add($datarray['uri'], $datarray, PRIORITY_HIGH, false, $scheduled_at);
+
+                       Post\Delayed::add($datarray['uri'], $datarray, PRIORITY_HIGH, Post\Delayed::PREPARED_NO_HOOK, $scheduled_at);
                        item_post_return(DI::baseUrl(), $api_source, $return_path);
                }
        }
 
-       $datarray['uri-id'] = ItemURI::getIdByURI($datarray['uri']);
-
-       Hook::callAll('post_local',$datarray);
-
        if (!empty($datarray['cancel'])) {
                Logger::info('mod_item: post cancelled by addon.');
                if ($return_path) {
@@ -716,6 +716,8 @@ function item_post(App $a) {
                System::jsonExit($json);
        }
 
+       $datarray['uri-id'] = ItemURI::getIdByURI($datarray['uri']);
+
        if ($orig_post) {
                // Fill the cache field
                // This could be done in Item::update as well - but we have to check for the existance of some fields.
index 3e0faddf75bac667b98427023366150c5b02fc18..441808ea91116fd91be00de98554c39d15d51fa0 100644 (file)
@@ -706,7 +706,7 @@ class Item
                return GRAVITY_UNKNOWN;   // Should not happen
        }
 
-       public static function insert($item, $notify = false, $dontcache = false)
+       public static function insert(array $item, bool $notify = false, bool $post_local = true)
        {
                $orig_item = $item;
 
@@ -931,7 +931,7 @@ class Item
                        $item["private"] = self::PRIVATE;
                }
 
-               if ($notify) {
+               if ($notify && $post_local) {
                        $item['edit'] = false;
                        $item['parent'] = $parent_id;
 
@@ -953,7 +953,7 @@ class Item
                                unset($_SESSION['authenticated']);
                                unset($_SESSION['uid']);
                        }
-               } else {
+               } elseif (!$notify) {
                        Hook::callAll('post_remote', $item);
                }
 
@@ -1141,15 +1141,13 @@ class Item
                        return 0;
                }
 
-               if (!$dontcache) {
-                       if ($notify) {
-                               if (!\Friendica\Content\Feature::isEnabled($posted_item['uid'], 'explicit_mentions') && ($posted_item['gravity'] == GRAVITY_COMMENT)) {
-                                       Tag::createImplicitMentions($posted_item['uri-id'], $posted_item['thr-parent-id']);
-                               }
-                               Hook::callAll('post_local_end', $posted_item);
-                       } else {
-                               Hook::callAll('post_remote_end', $posted_item);
+               if ($notify) {
+                       if (!\Friendica\Content\Feature::isEnabled($posted_item['uid'], 'explicit_mentions') && ($posted_item['gravity'] == GRAVITY_COMMENT)) {
+                               Tag::createImplicitMentions($posted_item['uri-id'], $posted_item['thr-parent-id']);
                        }
+                       Hook::callAll('post_local_end', $posted_item);
+               } else {
+                       Hook::callAll('post_remote_end', $posted_item);
                }
 
                if ($posted_item['gravity'] === GRAVITY_PARENT) {
@@ -1465,7 +1463,7 @@ class Item
                        }
                }
 
-               $distributed = self::insert($item, $notify, true);
+               $distributed = self::insert($item, $notify);
 
                if (!$distributed) {
                        Logger::info("Distributed item wasn't stored", ['uri-id' => $item['uri-id'], 'user' => $uid]);
@@ -1534,7 +1532,7 @@ class Item
                                $item['contact-id'] = $item['author-id'];
                        }
 
-                       $public_shadow = self::insert($item, false, true);
+                       $public_shadow = self::insert($item);
 
                        Logger::info('Stored public shadow', ['thread' => $itemid, 'id' => $public_shadow]);
                }
@@ -1593,7 +1591,7 @@ class Item
                unset($item['post-reason']);
                $item['contact-id'] = Contact::getIdForURL($item['author-link']);
 
-               $public_shadow = self::insert($item, false, true);
+               $public_shadow = self::insert($item);
 
                Logger::info('Stored public shadow', ['uri-id' => $item['uri-id'], 'id' => $public_shadow]);
 
index 669c365cded4e8c18e48296d21b0f4421456a9c9..24b9989a4b2fca4db4a515e77ec51b048dc3dbd0 100644 (file)
@@ -33,19 +33,23 @@ use Friendica\Util\DateTimeFormat;
 
 class Delayed
 {
+       const PREPARED = 0;
+       const UNPREPARED = 1;
+       const PREPARED_NO_HOOK = 2;
+
        /**
         * Insert a new delayed post
         *
-        * @param string  $uri
-        * @param array   $item
-        * @param integer $notify
-        * @param bool    $unprepared
-        * @param string  $delayed
-        * @param array   $taglist
-        * @param array   $attachments
-        * @return int    ID of the created delayed post entry
+        * @param string $uri
+        * @param array  $item
+        * @param int    $notify
+        * @param int    $preparation_mode
+        * @param string $delayed
+        * @param array  $taglist
+        * @param array  $attachments
+        * @return int   ID of the created delayed post entry
         */
-       public static function add(string $uri, array $item, int $notify = 0, bool $unprepared = false, string $delayed = '', array $taglist = [], array $attachments = [])
+       public static function add(string $uri, array $item, int $notify = 0, int $preparation_mode = self::PREPARED, string $delayed = '', array $taglist = [], array $attachments = [])
        {
                if (empty($item['uid']) || self::exists($uri, $item['uid'])) {
                        Logger::notice('No uid or already found');
@@ -63,7 +67,7 @@ class Delayed
 
                Logger::notice('Adding post for delayed publishing', ['uid' => $item['uid'], 'delayed' => $delayed, 'uri' => $uri]);
 
-               $wid = Worker::add(['priority' => PRIORITY_HIGH, 'delayed' => $delayed], 'DelayedPublish', $item, $notify, $taglist, $attachments, $unprepared, $uri);
+               $wid = Worker::add(['priority' => PRIORITY_HIGH, 'delayed' => $delayed], 'DelayedPublish', $item, $notify, $taglist, $attachments, $preparation_mode, $uri);
                if (!$wid) {
                        return 0;
                }
@@ -168,21 +172,21 @@ class Delayed
        /**
         * Publish a delayed post
         *
-        * @param array $item
-        * @param integer $notify
-        * @param array $taglist
-        * @param array $attachments
-        * @param bool  $unprepared
+        * @param array  $item
+        * @param int    $notify
+        * @param array  $taglist
+        * @param array  $attachments
+        * @param int    $preparation_mode
         * @param string $uri
         * @return bool
         */
-       public static function publish(array $item, int $notify = 0, array $taglist = [], array $attachments = [], bool $unprepared = false, string $uri = '')
+       public static function publish(array $item, int $notify = 0, array $taglist = [], array $attachments = [], int $preparation_mode = self::PREPARED, string $uri = '')
        {
                if (!empty($attachments)) {
                        $item['attachments'] = $attachments;
                }
 
-               if ($unprepared) {
+               if ($preparation_mode == self::UNPREPARED) {
                        $_SESSION['authenticated'] = true;
                        $_SESSION['uid'] = $item['uid'];
 
@@ -209,7 +213,8 @@ class Delayed
 
                        return $id;
                }
-               $id = Item::insert($item, $notify);
+
+               $id = Item::insert($item, $notify, $preparation_mode == self::PREPARED);
 
                Logger::notice('Post stored', ['id' => $id, 'uid' => $item['uid'], 'cid' => $item['contact-id']]);
 
index cd6bbda3f890e6c2b68b7475ca768dd58b5912dd..6ae076733435aeebc18a339c8cb61a007cec0506 100644 (file)
@@ -186,7 +186,7 @@ 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, false, $request['scheduled_at']);
+                       $id = Post\Delayed::add($item['uri'], $item, PRIORITY_HIGH, Post\Delayed::PREPARED, $request['scheduled_at']);
                        if (empty($id)) {
                                DI::mstdnError()->InternalError();
                        }
index 69ca1bfce29f767e5df363183218cb8320b9d6ad..0801498f21f1cc5c166a92c216a9ca8a07945cdf 100644 (file)
@@ -601,7 +601,7 @@ class Feed
                                }
                                $publish_at = date(DateTimeFormat::MYSQL, $publish_time);
 
-                               if (Post\Delayed::add($posting['item']['uri'], $posting['item'], $posting['notify'], false, $publish_at, $posting['taglist'], $posting['attachments'])) {
+                               if (Post\Delayed::add($posting['item']['uri'], $posting['item'], $posting['notify'], Post\Delayed::PREPARED, $publish_at, $posting['taglist'], $posting['attachments'])) {
                                        DI::pConfig()->set($item['uid'], 'system', 'last_publish', $publish_time);
                                }
                        }
index 3707cf53b2c8f7e152bb4d4b709e6e050c783c46..cd2bb1ff0f9539afe8f903dfd0e46762d69c2914 100644 (file)
@@ -29,17 +29,17 @@ class DelayedPublish
         /**
         * Publish a post, used for delayed postings
          *
-         * @param array $item
-         * @param integer $notify
-         * @param array $taglist
-         * @param array $attachments
-         * @param bool  $unprepared
+         * @param array  $item
+         * @param int    $notify
+         * @param array  $taglist
+         * @param array  $attachments
+         * @param int    $preparation_mode
          * @param string $uri
          * @return void
          */
-       public static function execute(array $item, int $notify = 0, array $taglist = [], array $attachments = [], bool $unprepared = false, string $uri = '')
+       public static function execute(array $item, int $notify = 0, array $taglist = [], array $attachments = [], int $preparation_mode = Post\Delayed::PREPARED, string $uri = '')
        {
-               $id = Post\Delayed::publish($item, $notify, $taglist, $attachments, $unprepared, $uri);
-               Logger::notice('Post published', ['id' => $id, 'uid' => $item['uid'], 'notify' => $notify, 'unprepared' => $unprepared]);
+               $id = Post\Delayed::publish($item, $notify, $taglist, $attachments, $preparation_mode, $uri);
+               Logger::notice('Post published', ['id' => $id, 'uid' => $item['uid'], 'notify' => $notify, 'unprepared' => $preparation_mode]);
        }
 }