Respect the postopts values for scheduled posts

This commit is contained in:
Michael 2021-08-06 18:49:17 +00:00
parent 266ee26240
commit 6a23b17c95
6 changed files with 54 additions and 49 deletions

View File

@ -681,7 +681,11 @@ function item_post(App $a) {
$o = conversation($a, [array_merge($contact_record, $datarray)], 'search', false, true); $o = conversation($a, [array_merge($contact_record, $datarray)], 'search', false, true);
System::jsonExit(['preview' => $o]); 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()); $scheduled_at = DateTimeFormat::convert($_REQUEST['scheduled_at'], 'UTC', $a->getTimezone());
if ($scheduled_at > DateTimeFormat::utcNow()) { if ($scheduled_at > DateTimeFormat::utcNow()) {
unset($datarray['created']); unset($datarray['created']);
@ -693,15 +697,11 @@ function item_post(App $a) {
unset($datarray['self']); unset($datarray['self']);
unset($datarray['api_source']); 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); 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'])) { if (!empty($datarray['cancel'])) {
Logger::info('mod_item: post cancelled by addon.'); Logger::info('mod_item: post cancelled by addon.');
if ($return_path) { if ($return_path) {
@ -716,6 +716,8 @@ function item_post(App $a) {
System::jsonExit($json); System::jsonExit($json);
} }
$datarray['uri-id'] = ItemURI::getIdByURI($datarray['uri']);
if ($orig_post) { if ($orig_post) {
// Fill the cache field // Fill the cache field
// This could be done in Item::update as well - but we have to check for the existance of some fields. // This could be done in Item::update as well - but we have to check for the existance of some fields.

View File

@ -706,7 +706,7 @@ class Item
return GRAVITY_UNKNOWN; // Should not happen 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; $orig_item = $item;
@ -931,7 +931,7 @@ class Item
$item["private"] = self::PRIVATE; $item["private"] = self::PRIVATE;
} }
if ($notify) { if ($notify && $post_local) {
$item['edit'] = false; $item['edit'] = false;
$item['parent'] = $parent_id; $item['parent'] = $parent_id;
@ -953,7 +953,7 @@ class Item
unset($_SESSION['authenticated']); unset($_SESSION['authenticated']);
unset($_SESSION['uid']); unset($_SESSION['uid']);
} }
} else { } elseif (!$notify) {
Hook::callAll('post_remote', $item); Hook::callAll('post_remote', $item);
} }
@ -1141,7 +1141,6 @@ class Item
return 0; return 0;
} }
if (!$dontcache) {
if ($notify) { if ($notify) {
if (!\Friendica\Content\Feature::isEnabled($posted_item['uid'], 'explicit_mentions') && ($posted_item['gravity'] == GRAVITY_COMMENT)) { 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']); Tag::createImplicitMentions($posted_item['uri-id'], $posted_item['thr-parent-id']);
@ -1150,7 +1149,6 @@ class Item
} else { } else {
Hook::callAll('post_remote_end', $posted_item); Hook::callAll('post_remote_end', $posted_item);
} }
}
if ($posted_item['gravity'] === GRAVITY_PARENT) { if ($posted_item['gravity'] === GRAVITY_PARENT) {
self::addShadow($post_user_id); self::addShadow($post_user_id);
@ -1465,7 +1463,7 @@ class Item
} }
} }
$distributed = self::insert($item, $notify, true); $distributed = self::insert($item, $notify);
if (!$distributed) { if (!$distributed) {
Logger::info("Distributed item wasn't stored", ['uri-id' => $item['uri-id'], 'user' => $uid]); 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']; $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]); Logger::info('Stored public shadow', ['thread' => $itemid, 'id' => $public_shadow]);
} }
@ -1593,7 +1591,7 @@ class Item
unset($item['post-reason']); unset($item['post-reason']);
$item['contact-id'] = Contact::getIdForURL($item['author-link']); $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]); Logger::info('Stored public shadow', ['uri-id' => $item['uri-id'], 'id' => $public_shadow]);

View File

@ -33,19 +33,23 @@ use Friendica\Util\DateTimeFormat;
class Delayed class Delayed
{ {
const PREPARED = 0;
const UNPREPARED = 1;
const PREPARED_NO_HOOK = 2;
/** /**
* Insert a new delayed post * Insert a new delayed post
* *
* @param string $uri * @param string $uri
* @param array $item * @param array $item
* @param integer $notify * @param int $notify
* @param bool $unprepared * @param int $preparation_mode
* @param string $delayed * @param string $delayed
* @param array $taglist * @param array $taglist
* @param array $attachments * @param array $attachments
* @return int ID of the created delayed post entry * @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'])) { if (empty($item['uid']) || self::exists($uri, $item['uid'])) {
Logger::notice('No uid or already found'); 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]); 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) { if (!$wid) {
return 0; return 0;
} }
@ -169,20 +173,20 @@ class Delayed
* Publish a delayed post * Publish a delayed post
* *
* @param array $item * @param array $item
* @param integer $notify * @param int $notify
* @param array $taglist * @param array $taglist
* @param array $attachments * @param array $attachments
* @param bool $unprepared * @param int $preparation_mode
* @param string $uri * @param string $uri
* @return bool * @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)) { if (!empty($attachments)) {
$item['attachments'] = $attachments; $item['attachments'] = $attachments;
} }
if ($unprepared) { if ($preparation_mode == self::UNPREPARED) {
$_SESSION['authenticated'] = true; $_SESSION['authenticated'] = true;
$_SESSION['uid'] = $item['uid']; $_SESSION['uid'] = $item['uid'];
@ -209,7 +213,8 @@ class Delayed
return $id; 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']]); Logger::notice('Post stored', ['id' => $id, 'uid' => $item['uid'], 'cid' => $item['contact-id']]);

View File

@ -186,7 +186,7 @@ class Statuses extends BaseApi
if (!empty($request['scheduled_at'])) { if (!empty($request['scheduled_at'])) {
$item['guid'] = Item::guid($item, true); $item['guid'] = Item::guid($item, true);
$item['uri'] = Item::newURI($item['uid'], $item['guid']); $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)) { if (empty($id)) {
DI::mstdnError()->InternalError(); DI::mstdnError()->InternalError();
} }

View File

@ -601,7 +601,7 @@ class Feed
} }
$publish_at = date(DateTimeFormat::MYSQL, $publish_time); $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); DI::pConfig()->set($item['uid'], 'system', 'last_publish', $publish_time);
} }
} }

View File

@ -30,16 +30,16 @@ class DelayedPublish
* Publish a post, used for delayed postings * Publish a post, used for delayed postings
* *
* @param array $item * @param array $item
* @param integer $notify * @param int $notify
* @param array $taglist * @param array $taglist
* @param array $attachments * @param array $attachments
* @param bool $unprepared * @param int $preparation_mode
* @param string $uri * @param string $uri
* @return void * @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); $id = Post\Delayed::publish($item, $notify, $taglist, $attachments, $preparation_mode, $uri);
Logger::notice('Post published', ['id' => $id, 'uid' => $item['uid'], 'notify' => $notify, 'unprepared' => $unprepared]); Logger::notice('Post published', ['id' => $id, 'uid' => $item['uid'], 'notify' => $notify, 'unprepared' => $preparation_mode]);
} }
} }