+ if (($deliver_status >= 200) && ($deliver_status <= 299)) {
+ // We successfully delivered a message, the contact is alive
+ Model\Contact::unmarkForArchival($contact);
+
+ if (in_array($cmd, [Delivery::POST, Delivery::POKE])) {
+ Model\ItemDeliveryData::incrementQueueDone($target_item['id'], Model\ItemDeliveryData::DIASPORA);
+ }
+ } else {
+ // 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' => ($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']);
+ }
+ } elseif (in_array($cmd, [Delivery::POST, Delivery::POKE])) {
+ Model\ItemDeliveryData::incrementQueueFailed($target_item['id']);
+ }
+ }