Store the protocol of the received message

This commit is contained in:
Michael 2020-11-29 09:01:51 +00:00
parent dd4a656dec
commit 7ab63d2106
9 changed files with 38 additions and 37 deletions

View File

@ -28,6 +28,7 @@ use Friendica\Core\System;
use Friendica\Database\DBA; use Friendica\Database\DBA;
use Friendica\DI; use Friendica\DI;
use Friendica\Model\Contact; use Friendica\Model\Contact;
use Friendica\Model\Conversation;
use Friendica\Model\User; use Friendica\Model\User;
use Friendica\Protocol\DFRN; use Friendica\Protocol\DFRN;
use Friendica\Protocol\Diaspora; use Friendica\Protocol\Diaspora;
@ -192,7 +193,7 @@ function dfrn_notify_post(App $a) {
Logger::log('Importing post from ' . $importer['addr'] . ' to ' . $importer['nickname'] . ' with the RINO ' . $rino_remote . ' encryption.', Logger::DEBUG); Logger::log('Importing post from ' . $importer['addr'] . ' to ' . $importer['nickname'] . ' with the RINO ' . $rino_remote . ' encryption.', Logger::DEBUG);
$ret = DFRN::import($data, $importer); $ret = DFRN::import($data, $importer, false, Conversation::PARCEL_LEGACY_DFRN);
System::xmlExit($ret, 'Processed'); System::xmlExit($ret, 'Processed');
// NOTREACHED // NOTREACHED
@ -224,7 +225,7 @@ function dfrn_dispatch_public($postdata)
Logger::log('Importing post from ' . $msg['author'] . ' with the public envelope.', Logger::DEBUG); Logger::log('Importing post from ' . $msg['author'] . ' with the public envelope.', Logger::DEBUG);
// Now we should be able to import it // Now we should be able to import it
$ret = DFRN::import($msg['message'], $importer); $ret = DFRN::import($msg['message'], $importer, false, Conversation::PARCEL_DIASPORA_DFRN);
System::xmlExit($ret, 'Done'); System::xmlExit($ret, 'Done');
} }
@ -257,7 +258,7 @@ function dfrn_dispatch_private($user, $postdata)
Logger::log('Importing post from ' . $msg['author'] . ' to ' . $user['nickname'] . ' with the private envelope.', Logger::DEBUG); Logger::log('Importing post from ' . $msg['author'] . ' to ' . $user['nickname'] . ' with the private envelope.', Logger::DEBUG);
// Now we should be able to import it // Now we should be able to import it
$ret = DFRN::import($msg['message'], $importer); $ret = DFRN::import($msg['message'], $importer, false, Conversation::PARCEL_DIASPORA_DFRN);
System::xmlExit($ret, 'Done'); System::xmlExit($ret, 'Done');
} }

View File

@ -81,8 +81,6 @@ function item_post(App $a) {
$api_source = $_REQUEST['api_source'] ?? false; $api_source = $_REQUEST['api_source'] ?? false;
$message_id = ((!empty($_REQUEST['message_id']) && $api_source) ? strip_tags($_REQUEST['message_id']) : '');
$return_path = $_REQUEST['return'] ?? ''; $return_path = $_REQUEST['return'] ?? '';
$preview = intval($_REQUEST['preview'] ?? 0); $preview = intval($_REQUEST['preview'] ?? 0);
@ -176,14 +174,6 @@ function item_post(App $a) {
$profile_uid = $toplevel_user_id; $profile_uid = $toplevel_user_id;
} }
// Check for multiple posts with the same message id (when the post was created via API)
if (($message_id != '') && ($profile_uid != 0)) {
if (Item::exists(['uri' => $message_id, 'uid' => $profile_uid])) {
Logger::info('Message already exists for user', ['uri' => $message_id, 'uid' => $profile_uid]);
return 0;
}
}
// Allow commenting if it is an answer to a public post // Allow commenting if it is an answer to a public post
$allow_comment = local_user() && ($profile_uid == 0) && $toplevel_item_id && in_array($toplevel_item['network'], Protocol::FEDERATED); $allow_comment = local_user() && ($profile_uid == 0) && $toplevel_item_id && in_array($toplevel_item['network'], Protocol::FEDERATED);
@ -562,7 +552,7 @@ function item_post(App $a) {
$origin = $_REQUEST['origin']; $origin = $_REQUEST['origin'];
} }
$uri = ($message_id ? $message_id : Item::newURI($api_source ? $profile_uid : $uid, $guid)); $uri = Item::newURI($api_source ? $profile_uid : $uid, $guid);
// Fallback so that we alway have a parent uri // Fallback so that we alway have a parent uri
if (!$thr_parent_uri || !$toplevel_item_id) { if (!$thr_parent_uri || !$toplevel_item_id) {
@ -628,7 +618,7 @@ function item_post(App $a) {
$datarray['api_source'] = $api_source; $datarray['api_source'] = $api_source;
// This field is for storing the raw conversation data // This field is for storing the raw conversation data
$datarray['protocol'] = Conversation::PARCEL_DFRN; $datarray['protocol'] = Conversation::PARCEL_DIRECT;
$conversation = DBA::selectFirst('conversation', ['conversation-uri', 'conversation-href'], ['item-uri' => $datarray['thr-parent']]); $conversation = DBA::selectFirst('conversation', ['conversation-uri', 'conversation-href'], ['item-uri' => $datarray['thr-parent']]);
if (DBA::isResult($conversation)) { if (DBA::isResult($conversation)) {

View File

@ -34,11 +34,15 @@ class Conversation
* It currently is stored in the "protocol" field for legacy reasons. * It currently is stored in the "protocol" field for legacy reasons.
*/ */
const PARCEL_ACTIVITYPUB = 0; const PARCEL_ACTIVITYPUB = 0;
const PARCEL_DFRN = 1; const PARCEL_DFRN = 1; // Deprecated
const PARCEL_DIASPORA = 2; const PARCEL_DIASPORA = 2;
const PARCEL_SALMON = 3; const PARCEL_SALMON = 3;
const PARCEL_FEED = 4; // Deprecated const PARCEL_FEED = 4; // Deprecated
const PARCEL_SPLIT_CONVERSATION = 6; const PARCEL_SPLIT_CONVERSATION = 6;
const PARCEL_LEGACY_DFRN = 7;
const PARCEL_DIASPORA_DFRN = 8;
const PARCEL_LOCAL_DFRN = 9;
const PARCEL_DIRECT = 10;
const PARCEL_TWITTER = 67; const PARCEL_TWITTER = 67;
const PARCEL_UNKNOWN = 255; const PARCEL_UNKNOWN = 255;
@ -134,9 +138,7 @@ class Conversation
unset($arr['conversation-uri']); unset($arr['conversation-uri']);
unset($arr['conversation-href']); unset($arr['conversation-href']);
unset($arr['protocol']);
unset($arr['source']); unset($arr['source']);
unset($arr['direction']);
return $arr; return $arr;
} }

View File

@ -1553,7 +1553,7 @@ class Item
$item['wall'] = 1; $item['wall'] = 1;
$item['origin'] = 1; $item['origin'] = 1;
$item['network'] = Protocol::DFRN; $item['network'] = Protocol::DFRN;
$item['protocol'] = Conversation::PARCEL_DFRN; $item['protocol'] = Conversation::PARCEL_DIRECT;
if (is_int($notify)) { if (is_int($notify)) {
$priority = $notify; $priority = $notify;
@ -1879,6 +1879,7 @@ class Item
Tag::storeFromBody($item['uri-id'], $body); Tag::storeFromBody($item['uri-id'], $body);
} }
if (Post\User::insert($item['uri-id'], $item['uid'], $item)) {
// Remove all fields that aren't part of the item table // Remove all fields that aren't part of the item table
foreach ($item as $field => $value) { foreach ($item as $field => $value) {
if (!in_array($field, $structure['item'])) { if (!in_array($field, $structure['item'])) {
@ -1886,7 +1887,6 @@ class Item
} }
} }
if (Post\User::insert($item['uri-id'], $item['uid'], $item)) {
$condition = ['uri-id' => $item['uri-id'], 'uid' => $item['uid'], 'network' => $item['network']]; $condition = ['uri-id' => $item['uri-id'], 'uid' => $item['uid'], 'network' => $item['network']];
if (DBA::exists('item', $condition)) { if (DBA::exists('item', $condition)) {
Logger::notice('Item is already inserted - aborting', $condition); Logger::notice('Item is already inserted - aborting', $condition);

View File

@ -2199,13 +2199,13 @@ class DFRN
* @throws \ImagickException * @throws \ImagickException
* @todo Add type-hints * @todo Add type-hints
*/ */
private static function processEntry($header, $xpath, $entry, $importer, $xml) private static function processEntry($header, $xpath, $entry, $importer, $xml, $protocol)
{ {
Logger::log("Processing entries"); Logger::log("Processing entries");
$item = $header; $item = $header;
$item["protocol"] = Conversation::PARCEL_DFRN; $item["protocol"] = $protocol;
$item["source"] = $xml; $item["source"] = $xml;
@ -2601,7 +2601,7 @@ class DFRN
* @throws \ImagickException * @throws \ImagickException
* @todo set proper type-hints * @todo set proper type-hints
*/ */
public static function import($xml, $importer, $sort_by_date = false) public static function import($xml, $importer, $sort_by_date = false, $protocol = Conversation::PARCEL_DFRN)
{ {
if ($xml == "") { if ($xml == "") {
return 400; return 400;
@ -2712,7 +2712,7 @@ class DFRN
if (!$sort_by_date) { if (!$sort_by_date) {
$entries = $xpath->query("/atom:feed/atom:entry"); $entries = $xpath->query("/atom:feed/atom:entry");
foreach ($entries as $entry) { foreach ($entries as $entry) {
self::processEntry($header, $xpath, $entry, $importer, $xml); self::processEntry($header, $xpath, $entry, $importer, $xml, $protocol);
} }
} else { } else {
$newentries = []; $newentries = [];
@ -2726,7 +2726,7 @@ class DFRN
ksort($newentries); ksort($newentries);
foreach ($newentries as $entry) { foreach ($newentries as $entry) {
self::processEntry($header, $xpath, $entry, $importer, $xml); self::processEntry($header, $xpath, $entry, $importer, $xml, $protocol);
} }
} }
Logger::log("Import done for user " . $importer["importer_uid"] . " from contact " . $importer["id"], Logger::DEBUG); Logger::log("Import done for user " . $importer["importer_uid"] . " from contact " . $importer["id"], Logger::DEBUG);

View File

@ -32,6 +32,7 @@ use Friendica\Core\Protocol;
use Friendica\Database\DBA; use Friendica\Database\DBA;
use Friendica\DI; use Friendica\DI;
use Friendica\Model\Contact; use Friendica\Model\Contact;
use Friendica\Model\Conversation;
use Friendica\Model\Item; use Friendica\Model\Item;
use Friendica\Model\Post; use Friendica\Model\Post;
use Friendica\Model\Tag; use Friendica\Model\Tag;
@ -100,7 +101,7 @@ class Feed
$dfrn_importer = DFRN::getImporter($contact['id'], $importer['uid']); $dfrn_importer = DFRN::getImporter($contact['id'], $importer['uid']);
if (!empty($dfrn_importer)) { if (!empty($dfrn_importer)) {
Logger::info('Now import the DFRN feed'); Logger::info('Now import the DFRN feed');
DFRN::import($xml, $dfrn_importer, true); DFRN::import($xml, $dfrn_importer, true, Conversation::PARCEL_LEGACY_DFRN);
return; return;
} }
} }

View File

@ -875,7 +875,9 @@ class OStatus
*/ */
private static function fetchSelf($self, array &$item) private static function fetchSelf($self, array &$item)
{ {
$condition = ['`item-uri` = ? AND `protocol` IN (?, ?)', $self, Conversation::PARCEL_DFRN, Conversation::PARCEL_SALMON]; $condition = ['item-uri' => $self, 'protocol' => [Conversation::PARCEL_DFRN,
Conversation::PARCEL_DIASPORA_DFRN, Conversation::PARCEL_LEGACY_DFRN,
Conversation::PARCEL_LOCAL_DFRN, Conversation::PARCEL_DIRECT, Conversation::PARCEL_SALMON]];
if (DBA::exists('conversation', $condition)) { if (DBA::exists('conversation', $condition)) {
Logger::log('Conversation '.$item['uri'].' is already stored.', Logger::DEBUG); Logger::log('Conversation '.$item['uri'].' is already stored.', Logger::DEBUG);
return; return;
@ -912,7 +914,10 @@ class OStatus
*/ */
private static function fetchRelated($related, $related_uri, $importer) private static function fetchRelated($related, $related_uri, $importer)
{ {
$condition = ['`item-uri` = ? AND `protocol` IN (?, ?)', $related_uri, Conversation::PARCEL_DFRN, Conversation::PARCEL_SALMON]; $condition = ['item-uri' => $related_uri, 'protocol' => [Conversation::PARCEL_DFRN,
Conversation::PARCEL_DIASPORA_DFRN, Conversation::PARCEL_LEGACY_DFRN,
Conversation::PARCEL_LOCAL_DFRN, Conversation::PARCEL_DIRECT, Conversation::PARCEL_SALMON]];
if (DBA::exists('conversation', $condition)) {
$conversation = DBA::selectFirst('conversation', ['source', 'protocol'], $condition); $conversation = DBA::selectFirst('conversation', ['source', 'protocol'], $condition);
if (DBA::isResult($conversation)) { if (DBA::isResult($conversation)) {
$stored = true; $stored = true;

View File

@ -33,6 +33,7 @@ use Friendica\Protocol\Activity;
use Friendica\Util\Strings; use Friendica\Util\Strings;
use Friendica\Util\Network; use Friendica\Util\Network;
use Friendica\Core\Worker; use Friendica\Core\Worker;
use Friendica\Model\Conversation;
use Friendica\Model\FContact; use Friendica\Model\FContact;
use Friendica\Protocol\Relay; use Friendica\Protocol\Relay;
@ -334,7 +335,7 @@ class Delivery
return; return;
} }
DFRN::import($atom, $target_importer); DFRN::import($atom, $target_importer, false, Conversation::PARCEL_LOCAL_DFRN);
if (in_array($cmd, [Delivery::POST, Delivery::POKE])) { if (in_array($cmd, [Delivery::POST, Delivery::POKE])) {
Model\Post\DeliveryData::incrementQueueDone($target_item['uri-id'], Model\Post\DeliveryData::DFRN); Model\Post\DeliveryData::incrementQueueDone($target_item['uri-id'], Model\Post\DeliveryData::DFRN);

View File

@ -55,7 +55,7 @@
use Friendica\Database\DBA; use Friendica\Database\DBA;
if (!defined('DB_UPDATE_VERSION')) { if (!defined('DB_UPDATE_VERSION')) {
define('DB_UPDATE_VERSION', 1380); define('DB_UPDATE_VERSION', 1381);
} }
return [ return [
@ -1191,6 +1191,7 @@ return [
"fields" => [ "fields" => [
"uri-id" => ["type" => "int unsigned", "not null" => "1", "primary" => "1", "foreign" => ["item-uri" => "id"], "comment" => "Id of the item-uri table entry that contains the item uri"], "uri-id" => ["type" => "int unsigned", "not null" => "1", "primary" => "1", "foreign" => ["item-uri" => "id"], "comment" => "Id of the item-uri table entry that contains the item uri"],
"uid" => ["type" => "mediumint unsigned", "not null" => "1", "primary" => "1", "foreign" => ["user" => "uid"], "comment" => "Owner id which owns this copy of the item"], "uid" => ["type" => "mediumint unsigned", "not null" => "1", "primary" => "1", "foreign" => ["user" => "uid"], "comment" => "Owner id which owns this copy of the item"],
"protocol" => ["type" => "tinyint unsigned", "comment" => "The used transport protocol - can be different per user"],
"contact-id" => ["type" => "int unsigned", "not null" => "1", "default" => "0", "foreign" => ["contact" => "id"], "comment" => "contact.id"], "contact-id" => ["type" => "int unsigned", "not null" => "1", "default" => "0", "foreign" => ["contact" => "id"], "comment" => "contact.id"],
"unseen" => ["type" => "boolean", "not null" => "1", "default" => "1", "comment" => "post has not been seen"], "unseen" => ["type" => "boolean", "not null" => "1", "default" => "1", "comment" => "post has not been seen"],
"hidden" => ["type" => "boolean", "not null" => "1", "default" => "0", "comment" => "Marker to hide the post from the user"], "hidden" => ["type" => "boolean", "not null" => "1", "default" => "0", "comment" => "Marker to hide the post from the user"],