-- ------------------------------------------
--- Friendica 2020.12-rc (Red Hot Poker)
--- DB_UPDATE_VERSION 1384
+-- Friendica 2021.03-dev (Red Hot Poker)
+-- DB_UPDATE_VERSION 1385
-- ------------------------------------------
`poco` varchar(255) NOT NULL DEFAULT '' COMMENT '',
`noscrape` varchar(255) NOT NULL DEFAULT '' COMMENT '',
`network` char(4) NOT NULL DEFAULT '' COMMENT '',
+ `protocol` tinyint unsigned COMMENT 'The protocol of the server',
`platform` varchar(255) NOT NULL DEFAULT '' COMMENT '',
`relay-subscribe` boolean NOT NULL DEFAULT '0' COMMENT 'Has the server subscribed to the relay system',
`relay-scope` varchar(10) NOT NULL DEFAULT '' COMMENT 'The scope of messages that the server wants to get',
use DOMDocument;
use DOMXPath;
+use Exception;
use Friendica\Core\Logger;
use Friendica\Core\Protocol;
use Friendica\Core\System;
DI::config()->set('poco', 'last_federation_discovery', time());
}
+
+ /**
+ * Set the protocol for the given server
+ *
+ * @param int $gsid Server id
+ * @param int $protocol Protocol id
+ * @return void
+ * @throws Exception
+ */
+ static function setProtocol(int $gsid, int $protocol)
+ {
+ if (empty($gsid)) {
+ return;
+ }
+
+ $gserver = DBA::selectFirst('gserver', ['protocol', 'url'], ['id' => $gsid]);
+ if (!DBA::isResult($gserver)) {
+ return;
+ }
+
+ $old = $gserver['protocol'];
+
+ if (!is_null($old)) {
+ /*
+ The priority for the protocols is:
+ 1. ActivityPub
+ 2. DFRN via Diaspora
+ 3. Legacy DFRN
+ 4. Diaspora
+ 5. OStatus
+ */
+
+ // We don't need to change it when nothing is to be changed
+ if ($old == $protocol) {
+ return;
+ }
+
+ // We don't want to mark a server as OStatus when it had been marked with any other protocol before
+ if ($protocol == Post\DeliveryData::OSTATUS) {
+ return;
+ }
+
+ // If the server is marked as ActivityPub then we won't change it to anything different
+ if ($old == Post\DeliveryData::ACTIVITYPUB) {
+ return;
+ }
+
+ // Don't change it to anything lower than DFRN if the new one wasn't ActivityPub
+ if (($old == Post\DeliveryData::DFRN) && ($protocol != Post\DeliveryData::ACTIVITYPUB)) {
+ return;
+ }
+
+ // Don't change it to Diaspora when it is a legacy DFRN server
+ if (($old == Post\DeliveryData::LEGACY_DFRN) && ($protocol == Post\DeliveryData::DIASPORA)) {
+ return;
+ }
+ }
+
+ Logger::info('Protocol for server', ['protocol' => $protocol, 'old' => $old, 'id' => $gsid, 'url' => $gserver['url']]);
+ DBA::update('gserver', ['protocol' => $protocol], ['id' => $gsid]);
+ }
}
use Friendica\Core\Worker;
use Friendica\Database\DBA;
use Friendica\Util\DateTimeFormat;
+use Friendica\Util\Network;
class PushSubscriber
{
$fields = ['push' => 0, 'next_try' => DBA::NULL_DATETIME, 'last_update' => $last_update];
DBA::update('push_subscriber', $fields, ['id' => $id]);
Logger::log('Subscriber ' . $subscriber['callback_url'] . ' for ' . $subscriber['nickname'] . ' is marked as vital', Logger::DEBUG);
+
+ $parts = parse_url($subscriber['callback_url']);
+ unset($parts['path']);
+ $server_url = Network::unparseURL($parts);
+ $gsid = GServer::getID($server_url, true);
+ if (!empty($gsid)) {
+ GServer::setProtocol($gsid, Post\DeliveryData::OSTATUS);
+ }
}
}
use Friendica\Core\Logger;
use Friendica\Core\Worker;
use Friendica\Model\Contact;
+use Friendica\Model\GServer;
use Friendica\Model\Item;
use Friendica\Model\Post;
use Friendica\Protocol\ActivityPub;
// This should never fail and is temporariy (until the move to the "post" structure)
$item = Item::selectFirst(['uri-id'], ['id' => $item_id]);
$uriid = $item['uri-id'] ?? 0;
+ $gsid = null;
foreach ($receivers as $receiver) {
$contact = Contact::getById($receiver);
continue;
}
+ $gsid = $gsid ?: $contact['gsid'];
+
if ($success) {
Contact::unmarkForArchival($contact);
} else {
}
}
+ if (!empty($gsid)) {
+ GServer::setProtocol($gsid, Post\DeliveryData::ACTIVITYPUB);
+ }
+
if (!$success && !Worker::defer() && in_array($cmd, [Delivery::POST])) {
Post\DeliveryData::incrementQueueFailed($uriid);
} elseif ($success && in_array($cmd, [Delivery::POST])) {
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'], $protocol);
} else {
Model\Post\DeliveryData::incrementQueueFailed($target_item['uri-id']);
}
// We successfully delivered a message, the contact is alive
Model\Contact::unmarkForArchival($contact);
+ Model\GServer::setProtocol($contact['gsid'], $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'], Model\Post\DeliveryData::DIASPORA);
+
if (in_array($cmd, [Delivery::POST, Delivery::POKE])) {
Model\Post\DeliveryData::incrementQueueDone($target_item['uri-id'], Model\Post\DeliveryData::DIASPORA);
}
use Friendica\Database\DBA;
if (!defined('DB_UPDATE_VERSION')) {
- define('DB_UPDATE_VERSION', 1384);
+ define('DB_UPDATE_VERSION', 1385);
}
return [
"poco" => ["type" => "varchar(255)", "not null" => "1", "default" => "", "comment" => ""],
"noscrape" => ["type" => "varchar(255)", "not null" => "1", "default" => "", "comment" => ""],
"network" => ["type" => "char(4)", "not null" => "1", "default" => "", "comment" => ""],
+ "protocol" => ["type" => "tinyint unsigned", "comment" => "The protocol of the server"],
"platform" => ["type" => "varchar(255)", "not null" => "1", "default" => "", "comment" => ""],
"relay-subscribe" => ["type" => "boolean", "not null" => "1", "default" => "0", "comment" => "Has the server subscribed to the relay system"],
"relay-scope" => ["type" => "varchar(10)", "not null" => "1", "default" => "", "comment" => "The scope of messages that the server wants to get"],