]> git.mxchange.org Git - friendica.git/blobdiff - src/Protocol/Feed.php
Standards
[friendica.git] / src / Protocol / Feed.php
index 6390fab6584cd023486b02c9f3e9bcce881a5312..a2e9daaa036ab31826aa4ac82991ec72e5cd173b 100644 (file)
@@ -606,7 +606,7 @@ class Feed
                        // Additionally we have to avoid conflicts with identical URI between imported feeds and these items.
                        if ($notify) {
                                $item['guid'] = Item::guidFromUri($orig_plink, DI::baseUrl()->getHostname());
-                               unset($item['uri']);
+                               $item['uri'] = Item::newURI($item['uid'], $item['guid']);
                                unset($item['thr-parent']);
                                unset($item['parent-uri']);
 
@@ -614,17 +614,27 @@ class Feed
                                $notify = PRIORITY_MEDIUM;
                        }
 
-                       $postings[] = ['item' => $item, 'notify' => $notify,
-                               'taglist' => $taglist, 'attachments' => $attachments];
+                       $condition = ['uid' => $item['uid'], 'uri' => $item['uri']];
+                       if (!Item::exists($condition) && !Post\Delayed::exists($item["uri"], $item['uid'])) {
+                               if (!$notify) {
+                                       Post\Delayed::publish($item, $notify, $taglist, $attachments);
+                               } else {
+                                       $postings[] = ['item' => $item, 'notify' => $notify,
+                                               'taglist' => $taglist, 'attachments' => $attachments];
+                               }
+                       } else {
+                               Logger::info('Post already created or exists in the delayed posts queue', ['uid' => $item['uid'], 'uri' => $item["uri"]]);
+                       }
                }
 
                if (!empty($postings)) {
+                       $min_posting = DI::config()->get('system', 'minimum_posting_interval', 0);
                        $total = count($postings);
                        if ($total > 1) {
                                // Posts shouldn't be delayed more than a day
                                $interval = min(1440, self::getPollInterval($contact));
-                               $delay = round(($interval * 60) / $total);
-                               Logger::notice('Got posting delay', ['delay' => $delay, 'interval' => $interval, 'items' => $total, 'cid' => $contact['id'], 'url' => $contact['url']]);
+                               $delay = max(round(($interval * 60) / $total), 60 * $min_posting);
+                               Logger::info('Got posting delay', ['delay' => $delay, 'interval' => $interval, 'items' => $total, 'cid' => $contact['id'], 'url' => $contact['url']]);
                        } else {
                                $delay = 0;
                        }
@@ -633,15 +643,21 @@ class Feed
 
                        foreach ($postings as $posting) {
                                if ($delay > 0) {
-                                       $publish_at = DateTimeFormat::utc('now + ' . $post_delay . ' second');
-                                       Logger::notice('Got publishing date', ['delay' => $delay, 'publish_at' => $publish_at, 'cid' => $contact['id'], 'url' => $contact['url']]);
+                                       $publish_time = time() + $post_delay;
                                        $post_delay += $delay;
                                } else {
-                                       $publish_at = DBA::NULL_DATETIME;
+                                       $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) {
+                                       $publish_time = $next_publish;
                                }
+                               $publish_at = date(DateTimeFormat::MYSQL, $publish_time);
 
-                               Worker::add(['priority' => PRIORITY_HIGH, 'delayed' => $publish_at],
-                                       'DelayedPublish', $posting['item'], $posting['notify'], $posting['taglist'], $posting['attachments']);
+                               Post\Delayed::add($publish_at, $posting['item'], $posting['notify'], $posting['taglist'], $posting['attachments']);
+                               DI::pConfig()->set($item['uid'], 'system', 'last_publish', $next_publish);
                        }
                }