* @return void
* @throws Exception
*/
- static function setProtocol(int $gsid, int $protocol)
+ public static function setProtocol(int $gsid, int $protocol)
{
if (empty($gsid)) {
return;
Logger::info('Protocol for server', ['protocol' => $protocol, 'old' => $old, 'id' => $gsid, 'url' => $gserver['url']]);
DBA::update('gserver', ['protocol' => $protocol], ['id' => $gsid]);
}
+
+ /**
+ * Fetch the protocol of the given server
+ *
+ * @param int $gsid Server id
+ * @return int
+ * @throws Exception
+ */
+ public static function getProtocol(int $gsid)
+ {
+ if (empty($gsid)) {
+ return null;
+ }
+
+ $gserver = DBA::selectFirst('gserver', ['protocol'], ['id' => $gsid]);
+ if (DBA::isResult($gserver)) {
+ return $gserver['protocol'];
+ }
+
+ return null;
+ }
}
return;
}
+ $protocol = Model\GServer::getProtocol($contact['gsid']);
+
// 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))) {
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;