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);
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.

View 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]);

View 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']]);

View 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();
}

View 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);
}
}

View 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]);
}
}