*/
class Feed
{
- /**
- * consume - process atom feed and update anything/everything we might need to update
- *
- * $xml = the (atom) feed to consume - RSS isn't as fully supported but may work for simple feeds.
- *
- * $importer = the contact_record (joined to user_record) of the local user who owns this relationship.
- * It is this person's stuff that is going to be updated.
- * $contact = the person who is sending us stuff. If not set, we MAY be processing a "follow" activity
- * from an external network and MAY create an appropriate contact record. Otherwise, we MUST
- * have a contact record.
- * $hub = should we find a hub declation in the feed, pass it back to our calling process, who might (or
- * might not) try and subscribe to it.
- * $datedir sorts in reverse order
- * $pass - by default ($pass = 0) we cannot guarantee that a parent item has been
- * imported prior to its children being seen in the stream unless we are certain
- * of how the feed is arranged/ordered.
- * With $pass = 1, we only pull parent items out of the stream.
- * With $pass = 2, we only pull children (comments/likes).
- *
- * So running this twice, first with pass 1 and then with pass 2 will do the right
- * thing regardless of feed ordering. This won't be adequate in a fully-threaded
- * model where comments can have sub-threads. That would require some massive sorting
- * to get all the feed items into a mostly linear ordering, and might still require
- * recursion.
- *
- * @param $xml
- * @param array $importer
- * @param array $contact
- * @param $hub
- * @throws ImagickException
- * @throws \Friendica\Network\HTTPException\InternalServerErrorException
- */
- public static function consume($xml, array $importer, array $contact, &$hub)
- {
- if ($contact['network'] === Protocol::OSTATUS) {
- Logger::info('Consume OStatus messages');
- OStatus::import($xml, $importer, $contact, $hub);
-
- return;
- }
-
- if ($contact['network'] === Protocol::FEED) {
- Logger::info('Consume feeds');
- self::import($xml, $importer, $contact);
-
- return;
- }
-
- if ($contact['network'] === Protocol::DFRN) {
- Logger::info('Consume DFRN messages');
- $dfrn_importer = DFRN::getImporter($contact['id'], $importer['uid']);
- if (!empty($dfrn_importer)) {
- Logger::info('Now import the DFRN feed');
- DFRN::import($xml, $dfrn_importer, true, Conversation::PARCEL_LEGACY_DFRN);
- return;
- }
- }
- }
-
/**
* Read a RSS/RDF/Atom feed and create an item entry for it
*
$condition = ['uid' => $item['uid'], 'uri' => $item['uri']];
if (!Item::exists($condition) && !Post\Delayed::exists($item["uri"], $item['uid'])) {
- $postings[] = ['item' => $item, 'notify' => $notify,
- 'taglist' => $taglist, 'attachments' => $attachments];
+ if (!$notify) {
+ Post\Delayed::publish($item, $notify, $taglist, $attachments);
+ } else {
+ $postings[] = ['item' => $item, 'notify' => $notify,
+ 'taglist' => $taglist, 'attachments' => $attachments];
+ }
} else {
- Logger::info('Post already exists in the delayed posts queue', ['uri' => $item["uri"]]);
+ Logger::info('Post already created or exists in the delayed posts queue', ['uid' => $item['uid'], 'uri' => $item["uri"]]);
}
}
// Posts shouldn't be delayed more than a day
$interval = min(1440, self::getPollInterval($contact));
$delay = max(round(($interval * 60) / $total), 60 * $min_posting);
- Logger::notice('Got posting delay', ['delay' => $delay, 'interval' => $interval, 'items' => $total, 'cid' => $contact['id'], 'url' => $contact['url']]);
+ Logger::info('Got posting delay', ['delay' => $delay, 'interval' => $interval, 'items' => $total, 'cid' => $contact['id'], 'url' => $contact['url']]);
} else {
$delay = 0;
}
foreach ($postings as $posting) {
if ($delay > 0) {
$publish_time = time() + $post_delay;
- Logger::notice('Got publishing date', ['delay' => $delay, 'cid' => $contact['id'], 'url' => $contact['url']]);
$post_delay += $delay;
} else {
$publish_time = time();
$last_publish = DI::pConfig()->get($posting['item']['uid'], 'system', 'last_publish', 0, true);
$next_publish = max($last_publish + (60 * $min_posting), time());
if ($publish_time < $next_publish) {
- Logger::notice('Adapting publish time',
- ['last' => date(DateTimeFormat::MYSQL, $last_publish),
- 'next' => date(DateTimeFormat::MYSQL, $next_publish),
- 'publish' => date(DateTimeFormat::MYSQL, $publish_time)]);
$publish_time = $next_publish;
}
$publish_at = date(DateTimeFormat::MYSQL, $publish_time);
- Post\Delayed::add($publish_at, $posting['item'], $posting['notify'], $posting['taglist'], $posting['attachments']);
- DI::pConfig()->set($item['uid'], 'system', 'last_publish', $next_publish);
+ Post\Delayed::add($posting['item']['uri'], $posting['item'], $posting['notify'], false, $publish_at, $posting['taglist'], $posting['attachments']);
}
}