if ($cmd == self::MAIL) {
$target_item = DBA::selectFirst('mail', [], ['id' => $target_id]);
if (!DBA::isResult($target_item)) {
+ self::setFailedQueue($cmd, $target_id);
return;
}
$uid = $target_item['uid'];
} elseif ($cmd == self::SUGGESTION) {
$target_item = DBA::selectFirst('fsuggest', [], ['id' => $target_id]);
if (!DBA::isResult($target_item)) {
+ self::setFailedQueue($cmd, $target_id);
return;
}
$uid = $target_item['uid'];
} else {
$item = Model\Item::selectFirst(['parent'], ['id' => $target_id]);
if (!DBA::isResult($item) || empty($item['parent'])) {
+ self::setFailedQueue($cmd, $target_id);
return;
}
$parent_id = intval($item['parent']);
if (empty($target_item)) {
Logger::log('Item ' . $target_id . "wasn't found. Quitting here.");
+ self::setFailedQueue($cmd, $target_id);
return;
}
if (empty($parent)) {
Logger::log('Parent ' . $parent_id . ' for item ' . $target_id . "wasn't found. Quitting here.");
+ self::setFailedQueue($cmd, $target_id);
return;
}
$uid = $target_item['uid'];
} else {
Logger::log('Only public users for item ' . $target_id, Logger::DEBUG);
+ self::setFailedQueue($cmd, $target_id);
return;
}
+ $condition = ['uri' => $target_item['thr-parent'], 'uid' => $target_item['uid']];
+ $thr_parent = Model\Item::selectFirst(['network'], $condition);
+ if (!DBA::isResult($thr_parent)) {
+ // Shouldn't happen. But when this does, we just take the parent as thread parent.
+ // That's totally okay for what we use this variable here.
+ $thr_parent = $parent;
+ }
+
if (!empty($contact_id) && Model\Contact::isArchived($contact_id)) {
Logger::info('Contact is archived', ['id' => $contact_id, 'cmd' => $cmd, 'item' => $target_item['id']]);
- if (in_array($cmd, [Delivery::POST, Delivery::POKE])) {
- Model\ItemDeliveryData::incrementQueueFailed($target_item['id']);
- }
+ self::setFailedQueue($cmd, $target_id);
return;
}
$owner = Model\User::getOwnerDataById($uid);
if (!DBA::isResult($owner)) {
+ self::setFailedQueue($cmd, $target_id);
return;
}
['id' => $contact_id, 'blocked' => false, 'pending' => false, 'self' => false]
);
if (!DBA::isResult($contact)) {
+ self::setFailedQueue($cmd, $target_id);
return;
}
if (Network::isUrlBlocked($contact['url'])) {
+ self::setFailedQueue($cmd, $target_id);
return;
}
- // Transmit via Diaspora if the thread had started as Diaspora post
+ // Transmit via Diaspora if the thread had started as Diaspora post.
+ // Also transmit via Diaspora if this is a direct answer to a Diaspora comment.
// This is done since the uri wouldn't match (Diaspora doesn't transmit it)
- if (isset($parent) && ($parent['network'] == Protocol::DIASPORA) && ($contact['network'] == Protocol::DFRN)) {
+ if (!empty($parent) && !empty($thr_parent) && in_array(Protocol::DIASPORA, [$parent['network'], $thr_parent['network']])) {
$contact['network'] = Protocol::DIASPORA;
}
- Logger::log("Delivering " . $cmd . " followup=$followup - via network " . $contact['network']);
+ Logger::notice('Delivering', ['cmd' => $cmd, 'target' => $target_id, 'followup' => $followup, 'network' => $contact['network']]);
switch ($contact['network']) {
-
case Protocol::DFRN:
self::deliverDFRN($cmd, $contact, $owner, $items, $target_item, $public_message, $top_level, $followup);
break;
return;
}
+ /**
+ * Increased the "failed" counter in the item delivery data
+ *
+ * @param string $cmd Command
+ * @param integer $id Item id
+ */
+ private static function setFailedQueue(string $cmd, int $id)
+ {
+ if (!in_array($cmd, [Delivery::POST, Delivery::POKE])) {
+ return;
+ }
+
+ Model\ItemDeliveryData::incrementQueueFailed($id);
+ }
+
/**
* @brief Deliver content via DFRN
*
*/
private static function deliverDFRN($cmd, $contact, $owner, $items, $target_item, $public_message, $top_level, $followup)
{
- Logger::log('Deliver ' . defaults($target_item, 'guid', $target_item['id']) . ' via DFRN to ' . (empty($contact['addr']) ? $contact['url'] : $contact['addr']));
+ Logger::info('Deliver ' . (($target_item['guid'] ?? '') ?: $target_item['id']) . ' via DFRN to ' . (($contact['addr'] ?? '') ?: $contact['url']));
if ($cmd == self::MAIL) {
$item = $target_item;
$atom = DFRN::entries($msgitems, $owner);
}
- Logger::log('Notifier entry: ' . $contact["url"] . ' ' . defaults($target_item, 'guid', $target_item['id']) . ' entry: ' . $atom, Logger::DATA);
+ Logger::debug('Notifier entry: ' . $contact["url"] . ' ' . (($target_item['guid'] ?? '') ?: $target_item['id']) . ' entry: ' . $atom);
$basepath = implode('/', array_slice(explode('/', $contact['url']), 0, 3));
// We never spool failed relay deliveries
if ($public_dfrn) {
- Logger::log('Relay delivery to ' . $contact["url"] . ' with guid ' . $target_item["guid"] . ' returns ' . $deliver_status);
+ Logger::info('Relay delivery to ' . $contact["url"] . ' with guid ' . $target_item["guid"] . ' returns ' . $deliver_status);
+
+ if (in_array($cmd, [Delivery::POST, Delivery::POKE])) {
+ if (($deliver_status >= 200) && ($deliver_status <= 299)) {
+ Model\ItemDeliveryData::incrementQueueDone($target_item['id'], $protocol);
+ } else {
+ Model\ItemDeliveryData::incrementQueueFailed($target_item['id']);
+ }
+ }
return;
}
$protocol = Model\ItemDeliveryData::LEGACY_DFRN;
}
- Logger::info('DFRN Delivery', ['cmd' => $cmd, 'url' => $contact['url'], 'guid' => defaults($target_item, 'guid', $target_item['id']), 'return' => $deliver_status]);
+ Logger::info('DFRN Delivery', ['cmd' => $cmd, 'url' => $contact['url'], 'guid' => ($target_item['guid'] ?? '') ?: $target_item['id'], 'return' => $deliver_status]);
if (($deliver_status >= 200) && ($deliver_status <= 299)) {
// We successfully delivered a message, the contact is alive
// The message could not be delivered. We mark the contact as "dead"
Model\Contact::markForArchival($contact);
- Logger::info('Delivery failed: defer message', ['id' => defaults($target_item, 'guid', $target_item['id'])]);
+ Logger::info('Delivery failed: defer message', ['id' => ($target_item['guid'] ?? '') ?: $target_item['id']]);
if (!Worker::defer() && in_array($cmd, [Delivery::POST, Delivery::POKE])) {
Model\ItemDeliveryData::incrementQueueFailed($target_item['id']);
}
$loc = $contact['addr'];
}
- Logger::log('Deliver ' . defaults($target_item, 'guid', $target_item['id']) . ' via Diaspora to ' . $loc);
+ Logger::notice('Deliver via Diaspora', ['target' => $target_item['id'], 'guid' => $target_item['guid'], 'to' => $loc]);
if (Config::get('system', 'dfrn_only') || !Config::get('system', 'diaspora_enabled')) {
return;
// The message could not be delivered. We mark the contact as "dead"
Model\Contact::markForArchival($contact);
+ // When it is delivered to the public endpoint, we do mark the relay contact for archival as well
+ if ($public_message) {
+ Diaspora::markRelayForArchival($contact);
+ }
+
if (empty($contact['contact-type']) || ($contact['contact-type'] != Model\Contact::TYPE_RELAY)) {
- Logger::info('Delivery failed: defer message', ['id' => defaults($target_item, 'guid', $target_item['id'])]);
+ Logger::info('Delivery failed: defer message', ['id' => ($target_item['guid'] ?? '') ?: $target_item['id']]);
// defer message for redelivery
if (!Worker::defer() && in_array($cmd, [Delivery::POST, Delivery::POKE])) {
- Model\ItemDeliveryData::incrementQueueFailed($target_item['id'], Model\ItemDeliveryData::DIASPORA);
+ Model\ItemDeliveryData::incrementQueueFailed($target_item['id']);
}
} elseif (in_array($cmd, [Delivery::POST, Delivery::POKE])) {
- Model\ItemDeliveryData::incrementQueueDone($target_item['id'], Model\ItemDeliveryData::DIASPORA);
+ Model\ItemDeliveryData::incrementQueueFailed($target_item['id']);
}
}
}