use Friendica\Core\Worker;
use Friendica\Model\Conversation;
use Friendica\Model\FContact;
+use Friendica\Model\Item;
use Friendica\Protocol\Relay;
class Delivery
$uid = $target_id;
$target_item = [];
} else {
- $item = Model\Item::selectFirst(['parent'], ['id' => $target_id]);
+ $item = Model\Post::selectFirst(['parent'], ['id' => $target_id]);
if (!DBA::isResult($item) || empty($item['parent'])) {
return;
}
$parent_id = intval($item['parent']);
- $condition = ['id' => [$target_id, $parent_id], 'visible' => true, 'moderated' => false];
+ $condition = ['id' => [$target_id, $parent_id], 'visible' => true];
$params = ['order' => ['id']];
- $itemdata = Model\Item::select([], $condition, $params);
+ $itemdata = Model\Post::select(Item::DELIVER_FIELDLIST, $condition, $params);
- while ($item = Model\Item::fetch($itemdata)) {
+ while ($item = Model\Post::fetch($itemdata)) {
if ($item['verb'] == Activity::ANNOUNCE) {
continue;
}
}
$condition = ['uri' => $target_item['thr-parent'], 'uid' => $target_item['uid']];
- $thr_parent = Model\Item::selectFirst(['network', 'object'], $condition);
+ $thr_parent = Model\Post::selectFirst(['network', 'object'], $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.
return;
}
+ $protocol = Model\GServer::getProtocol($contact['gsid'] ?? 0);
+
// 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)
switch ($contact['network']) {
case Protocol::DFRN:
- self::deliverDFRN($cmd, $contact, $owner, $items, $target_item, $public_message, $top_level, $followup);
+ self::deliverDFRN($cmd, $contact, $owner, $items, $target_item, $public_message, $top_level, $followup, $protocol);
break;
case Protocol::DIASPORA:
/**
* Deliver content via DFRN
*
- * @param string $cmd Command
- * @param array $contact Contact record of the receiver
- * @param array $owner Owner record of the sender
- * @param array $items Item record of the content and the parent
- * @param array $target_item Item record of the content
- * @param boolean $public_message Is the content public?
- * @param boolean $top_level Is it a thread starter?
- * @param boolean $followup Is it an answer to a remote post?
+ * @param string $cmd Command
+ * @param array $contact Contact record of the receiver
+ * @param array $owner Owner record of the sender
+ * @param array $items Item record of the content and the parent
+ * @param array $target_item Item record of the content
+ * @param boolean $public_message Is the content public?
+ * @param boolean $top_level Is it a thread starter?
+ * @param boolean $followup Is it an answer to a remote post?
+ * @param int $server_protocol The protocol of the server
* @throws \Friendica\Network\HTTPException\InternalServerErrorException
* @throws \ImagickException
*/
- private static function deliverDFRN($cmd, $contact, $owner, $items, $target_item, $public_message, $top_level, $followup)
+ private static function deliverDFRN($cmd, $contact, $owner, $items, $target_item, $public_message, $top_level, $followup, $server_protocol)
{
// Transmit Diaspora reshares via Diaspora if the Friendica contact support Diaspora
if (Diaspora::isReshare($target_item['body']) && !empty(FContact::getByURL($contact['addr'], false))) {
if (in_array($cmd, [Delivery::POST, Delivery::POKE])) {
if (($deliver_status >= 200) && ($deliver_status <= 299)) {
Model\Post\DeliveryData::incrementQueueDone($target_item['uri-id'], $protocol);
+
+ Model\GServer::setProtocol($contact['gsid'] ?? 0, $protocol);
} else {
Model\Post\DeliveryData::incrementQueueFailed($target_item['uri-id']);
}
return;
}
- if (($deliver_status < 200) || ($deliver_status > 299)) {
+ if ((($deliver_status < 200) || ($deliver_status > 299)) && (empty($server_protocol) || ($server_protocol == Model\Post\DeliveryData::LEGACY_DFRN))) {
// Transmit via Diaspora if not possible via Friendica
self::deliverDiaspora($cmd, $contact, $owner, $items, $target_item, $public_message, $top_level, $followup);
return;
} elseif ($cmd != self::RELOCATION) {
// DFRN payload over Diaspora transport layer
$deliver_status = DFRN::transmit($owner, $contact, $atom);
- if ($deliver_status < 200) {
+ if (($deliver_status < 200) && (empty($server_protocol) || ($server_protocol == Model\Post\DeliveryData::LEGACY_DFRN))) {
// Legacy DFRN
$deliver_status = DFRN::deliver($owner, $contact, $atom);
$protocol = Model\Post\DeliveryData::LEGACY_DFRN;
// We successfully delivered a message, the contact is alive
Model\Contact::unmarkForArchival($contact);
+ Model\GServer::setProtocol($contact['gsid'] ?? 0, $protocol);
+
if (in_array($cmd, [Delivery::POST, Delivery::POKE])) {
Model\Post\DeliveryData::incrementQueueDone($target_item['uri-id'], $protocol);
}
// We successfully delivered a message, the contact is alive
Model\Contact::unmarkForArchival($contact);
+ Model\GServer::setProtocol($contact['gsid'] ?? 0, Model\Post\DeliveryData::DIASPORA);
+
if (in_array($cmd, [Delivery::POST, Delivery::POKE])) {
Model\Post\DeliveryData::incrementQueueDone($target_item['uri-id'], Model\Post\DeliveryData::DIASPORA);
}
if (empty($target_item['title'])) {
$condition = ['uri' => $target_item['parent-uri'], 'uid' => $owner['uid']];
- $title = Model\Item::selectFirst(['title'], $condition);
+ $title = Model\Post::selectFirst(['title'], $condition);
if (DBA::isResult($title) && ($title['title'] != '')) {
$subject = $title['title'];
} else {
$condition = ['parent-uri' => $target_item['parent-uri'], 'uid' => $owner['uid']];
- $title = Model\Item::selectFirst(['title'], $condition);
+ $title = Model\Post::selectFirst(['title'], $condition);
if (DBA::isResult($title) && ($title['title'] != '')) {
$subject = $title['title'];