Delay unprepared posts
This commit is contained in:
parent
c787281eff
commit
0eb4a600b0
|
@ -67,7 +67,6 @@ use Friendica\Util\Proxy as ProxyUtils;
|
||||||
use Friendica\Util\Strings;
|
use Friendica\Util\Strings;
|
||||||
use Friendica\Util\XML;
|
use Friendica\Util\XML;
|
||||||
|
|
||||||
require_once __DIR__ . '/../mod/share.php';
|
|
||||||
require_once __DIR__ . '/../mod/item.php';
|
require_once __DIR__ . '/../mod/item.php';
|
||||||
require_once __DIR__ . '/../mod/wall_upload.php';
|
require_once __DIR__ . '/../mod/wall_upload.php';
|
||||||
|
|
||||||
|
|
|
@ -2910,8 +2910,8 @@ class Item
|
||||||
$datarray['api_source'] = true;
|
$datarray['api_source'] = true;
|
||||||
|
|
||||||
// We have to tell the hooks who we are - this really should be improved
|
// We have to tell the hooks who we are - this really should be improved
|
||||||
$_SESSION["authenticated"] = true;
|
$_SESSION['authenticated'] = true;
|
||||||
$_SESSION["uid"] = $contact['uid'];
|
$_SESSION['uid'] = $contact['uid'];
|
||||||
|
|
||||||
return (bool)$result;
|
return (bool)$result;
|
||||||
}
|
}
|
||||||
|
|
|
@ -25,37 +25,57 @@ use Friendica\Core\Logger;
|
||||||
use Friendica\Database\DBA;
|
use Friendica\Database\DBA;
|
||||||
use Friendica\Core\Worker;
|
use Friendica\Core\Worker;
|
||||||
use Friendica\Database\Database;
|
use Friendica\Database\Database;
|
||||||
|
use Friendica\DI;
|
||||||
use Friendica\Model\Item;
|
use Friendica\Model\Item;
|
||||||
use Friendica\Model\Tag;
|
use Friendica\Model\Tag;
|
||||||
|
use Friendica\Util\DateTimeFormat;
|
||||||
|
|
||||||
class Delayed
|
class Delayed
|
||||||
{
|
{
|
||||||
/**
|
/**
|
||||||
* Insert a new delayed post
|
* Insert a new delayed post
|
||||||
*
|
*
|
||||||
* @param string $delayed
|
* @param string $uri
|
||||||
* @param array $item
|
* @param array $item
|
||||||
* @param integer $notify
|
* @param integer $notify
|
||||||
* @param array $taglist
|
* @param bool $unprepared
|
||||||
* @param array $attachments
|
* @param string $delayed
|
||||||
|
* @param array $taglist
|
||||||
|
* @param array $attachments
|
||||||
* @return bool insert success
|
* @return bool insert success
|
||||||
*/
|
*/
|
||||||
public static function add(string $delayed, array $item, int $notify = 0, array $taglist = [], array $attachments = [])
|
public static function add(string $uri, array $item, int $notify = 0, bool $unprepared = false, string $delayed = '', array $taglist = [], array $attachments = [])
|
||||||
{
|
{
|
||||||
if (empty($item['uri']) || empty($item['uid']) || self::exists($item['uri'], $item['uid'])) {
|
if (empty($item['uid']) || self::exists($uri, $item['uid'])) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
Logger::notice('Adding post for delayed publishing', ['uid' => $item['uid'], 'delayed' => $delayed, 'uri' => $item['uri']]);
|
if (empty($delayed)) {
|
||||||
|
$min_posting = DI::config()->get('system', 'minimum_posting_interval', 0);
|
||||||
|
|
||||||
Worker::add(['priority' => PRIORITY_HIGH, 'delayed' => $delayed], 'DelayedPublish', $item, $notify, $taglist, $attachments);
|
$last_publish = DI::pConfig()->get($item['uid'], 'system', 'last_publish', 0, true);
|
||||||
return DBA::insert('delayed-post', ['uri' => $item['uri'], 'uid' => $item['uid'], 'delayed' => $delayed], Database::INSERT_IGNORE);
|
$next_publish = max($last_publish + (60 * $min_posting), time());
|
||||||
|
$delayed = date(DateTimeFormat::MYSQL, $next_publish);
|
||||||
|
} else {
|
||||||
|
$next_publish = strtotime($delayed);
|
||||||
|
}
|
||||||
|
|
||||||
|
Logger::notice('Adding post for delayed publishing', ['uid' => $item['uid'], 'delayed' => $delayed, 'uri' => $uri]);
|
||||||
|
|
||||||
|
if (!Worker::add(['priority' => PRIORITY_HIGH, 'delayed' => $delayed], 'DelayedPublish', $item, $notify, $taglist, $attachments, $unprepared)) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
DI::pConfig()->set($item['uid'], 'system', 'last_publish', $next_publish);
|
||||||
|
|
||||||
|
return DBA::insert('delayed-post', ['uri' => $uri, 'uid' => $item['uid'], 'delayed' => $delayed], Database::INSERT_IGNORE);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Delete a delayed post
|
* Delete a delayed post
|
||||||
*
|
*
|
||||||
* @param string $uri
|
* @param string $uri
|
||||||
|
* @param int $uid
|
||||||
*
|
*
|
||||||
* @return bool delete success
|
* @return bool delete success
|
||||||
*/
|
*/
|
||||||
|
@ -68,6 +88,7 @@ class Delayed
|
||||||
* Check if an entry exists
|
* Check if an entry exists
|
||||||
*
|
*
|
||||||
* @param string $uri
|
* @param string $uri
|
||||||
|
* @param int $uid
|
||||||
*
|
*
|
||||||
* @return bool "true" if an entry with that URI exists
|
* @return bool "true" if an entry with that URI exists
|
||||||
*/
|
*/
|
||||||
|
@ -83,10 +104,30 @@ class Delayed
|
||||||
* @param integer $notify
|
* @param integer $notify
|
||||||
* @param array $taglist
|
* @param array $taglist
|
||||||
* @param array $attachments
|
* @param array $attachments
|
||||||
|
* @param bool $unprepared
|
||||||
* @return bool
|
* @return bool
|
||||||
*/
|
*/
|
||||||
public static function publish(array $item, int $notify = 0, array $taglist = [], array $attachments = [])
|
public static function publish(array $item, int $notify = 0, array $taglist = [], array $attachments = [], bool $unprepared = false)
|
||||||
{
|
{
|
||||||
|
if ($unprepared) {
|
||||||
|
$_SESSION['authenticated'] = true;
|
||||||
|
$_SESSION['uid'] = $item['uid'];
|
||||||
|
|
||||||
|
$_REQUEST = $item;
|
||||||
|
$_REQUEST['api_source'] = true;
|
||||||
|
$_REQUEST['profile_uid'] = $item['uid'];
|
||||||
|
$_REQUEST['title'] = $item['title'] ?? '';
|
||||||
|
|
||||||
|
if (!empty($item['app'])) {
|
||||||
|
$_REQUEST['source'] = $item['app'];
|
||||||
|
}
|
||||||
|
|
||||||
|
require_once 'mod/item.php';
|
||||||
|
$id = item_post(DI::app());
|
||||||
|
|
||||||
|
Logger::notice('Unprepared post stored', ['id' => $id, 'uid' => $item['uid'], 'extid' => $item['extid']]);
|
||||||
|
return;
|
||||||
|
}
|
||||||
$id = Item::insert($item, $notify);
|
$id = Item::insert($item, $notify);
|
||||||
|
|
||||||
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']]);
|
||||||
|
|
|
@ -51,9 +51,6 @@ use Friendica\Util\Map;
|
||||||
use Friendica\Util\Network;
|
use Friendica\Util\Network;
|
||||||
use Friendica\Util\XML;
|
use Friendica\Util\XML;
|
||||||
|
|
||||||
require_once 'include/api.php';
|
|
||||||
require_once 'mod/share.php';
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* ActivityPub Transmitter Protocol class
|
* ActivityPub Transmitter Protocol class
|
||||||
*
|
*
|
||||||
|
|
|
@ -3382,7 +3382,6 @@ class Diaspora
|
||||||
}
|
}
|
||||||
|
|
||||||
if ($item['author-link'] != $item['owner-link']) {
|
if ($item['author-link'] != $item['owner-link']) {
|
||||||
require_once 'mod/share.php';
|
|
||||||
$body = BBCode::getShareOpeningTag($item['author-name'], $item['author-link'], $item['author-avatar'],
|
$body = BBCode::getShareOpeningTag($item['author-name'], $item['author-link'], $item['author-avatar'],
|
||||||
$item['plink'], $item['created']) . $body . '[/share]';
|
$item['plink'], $item['created']) . $body . '[/share]';
|
||||||
}
|
}
|
||||||
|
|
|
@ -656,8 +656,7 @@ class Feed
|
||||||
}
|
}
|
||||||
$publish_at = date(DateTimeFormat::MYSQL, $publish_time);
|
$publish_at = date(DateTimeFormat::MYSQL, $publish_time);
|
||||||
|
|
||||||
Post\Delayed::add($publish_at, $posting['item'], $posting['notify'], $posting['taglist'], $posting['attachments']);
|
Post\Delayed::add($posting['item']['uri'], $posting['item'], $posting['notify'], false, $publish_at, $posting['taglist'], $posting['attachments']);
|
||||||
DI::pConfig()->set($item['uid'], 'system', 'last_publish', $next_publish);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -46,9 +46,6 @@ use Friendica\Util\Proxy as ProxyUtils;
|
||||||
use Friendica\Util\Strings;
|
use Friendica\Util\Strings;
|
||||||
use Friendica\Util\XML;
|
use Friendica\Util\XML;
|
||||||
|
|
||||||
require_once 'mod/share.php';
|
|
||||||
require_once 'include/api.php';
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* This class contain functions for the OStatus protocol
|
* This class contain functions for the OStatus protocol
|
||||||
*/
|
*/
|
||||||
|
|
|
@ -33,11 +33,12 @@ class DelayedPublish
|
||||||
* @param integer $notify
|
* @param integer $notify
|
||||||
* @param array $taglist
|
* @param array $taglist
|
||||||
* @param array $attachments
|
* @param array $attachments
|
||||||
|
* @param bool $unprepared
|
||||||
* @return void
|
* @return void
|
||||||
*/
|
*/
|
||||||
public static function execute(array $item, int $notify = 0, array $taglist = [], array $attachments = [])
|
public static function execute(array $item, int $notify = 0, array $taglist = [], array $attachments = [], bool $unprepared = false)
|
||||||
{
|
{
|
||||||
$id = Post\Delayed::publish($item, $notify, $taglist, $attachments);
|
$id = Post\Delayed::publish($item, $notify, $taglist, $attachments, $unprepared);
|
||||||
Logger::notice('Post published', ['id' => $id, 'uid' => $item['uid'], 'cid' => $item['contact-id'], 'notify' => $notify]);
|
Logger::notice('Post published', ['id' => $id, 'uid' => $item['uid'], 'cid' => $item['contact-id'], 'notify' => $notify, 'unprepared' => $unprepared]);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue
Block a user