use Friendica\Database\DBA;
use Friendica\DI;
use Friendica\Model\Contact;
+use Friendica\Model\Conversation;
use Friendica\Model\User;
use Friendica\Protocol\DFRN;
use Friendica\Protocol\Diaspora;
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');
// NOTREACHED
Logger::log('Importing post from ' . $msg['author'] . ' with the public envelope.', Logger::DEBUG);
// 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');
}
Logger::log('Importing post from ' . $msg['author'] . ' to ' . $user['nickname'] . ' with the private envelope.', Logger::DEBUG);
// 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');
}
$api_source = $_REQUEST['api_source'] ?? false;
- $message_id = ((!empty($_REQUEST['message_id']) && $api_source) ? strip_tags($_REQUEST['message_id']) : '');
-
$return_path = $_REQUEST['return'] ?? '';
$preview = intval($_REQUEST['preview'] ?? 0);
$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_comment = local_user() && ($profile_uid == 0) && $toplevel_item_id && in_array($toplevel_item['network'], Protocol::FEDERATED);
$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
if (!$thr_parent_uri || !$toplevel_item_id) {
$datarray['api_source'] = $api_source;
// 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']]);
if (DBA::isResult($conversation)) {
* It currently is stored in the "protocol" field for legacy reasons.
*/
const PARCEL_ACTIVITYPUB = 0;
- const PARCEL_DFRN = 1;
+ const PARCEL_DFRN = 1; // Deprecated
const PARCEL_DIASPORA = 2;
const PARCEL_SALMON = 3;
const PARCEL_FEED = 4; // Deprecated
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_UNKNOWN = 255;
unset($arr['conversation-uri']);
unset($arr['conversation-href']);
- unset($arr['protocol']);
unset($arr['source']);
- unset($arr['direction']);
return $arr;
}
$item['wall'] = 1;
$item['origin'] = 1;
$item['network'] = Protocol::DFRN;
- $item['protocol'] = Conversation::PARCEL_DFRN;
+ $item['protocol'] = Conversation::PARCEL_DIRECT;
if (is_int($notify)) {
$priority = $notify;
Tag::storeFromBody($item['uri-id'], $body);
}
- // Remove all fields that aren't part of the item table
- foreach ($item as $field => $value) {
- if (!in_array($field, $structure['item'])) {
- unset($item[$field]);
+ if (Post\User::insert($item['uri-id'], $item['uid'], $item)) {
+ // Remove all fields that aren't part of the item table
+ foreach ($item as $field => $value) {
+ if (!in_array($field, $structure['item'])) {
+ unset($item[$field]);
+ }
}
- }
- if (Post\User::insert($item['uri-id'], $item['uid'], $item)) {
$condition = ['uri-id' => $item['uri-id'], 'uid' => $item['uid'], 'network' => $item['network']];
if (DBA::exists('item', $condition)) {
Logger::notice('Item is already inserted - aborting', $condition);
* @throws \ImagickException
* @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");
$item = $header;
- $item["protocol"] = Conversation::PARCEL_DFRN;
+ $item["protocol"] = $protocol;
$item["source"] = $xml;
* @throws \ImagickException
* @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 == "") {
return 400;
if (!$sort_by_date) {
$entries = $xpath->query("/atom:feed/atom:entry");
foreach ($entries as $entry) {
- self::processEntry($header, $xpath, $entry, $importer, $xml);
+ self::processEntry($header, $xpath, $entry, $importer, $xml, $protocol);
}
} else {
$newentries = [];
ksort($newentries);
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);
use Friendica\Database\DBA;
use Friendica\DI;
use Friendica\Model\Contact;
+use Friendica\Model\Conversation;
use Friendica\Model\Item;
use Friendica\Model\Post;
use Friendica\Model\Tag;
$dfrn_importer = DFRN::getImporter($contact['id'], $importer['uid']);
if (!empty($dfrn_importer)) {
Logger::info('Now import the DFRN feed');
- DFRN::import($xml, $dfrn_importer, true);
+ DFRN::import($xml, $dfrn_importer, true, Conversation::PARCEL_LEGACY_DFRN);
return;
}
}
*/
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)) {
Logger::log('Conversation '.$item['uri'].' is already stored.', Logger::DEBUG);
return;
*/
private static function fetchRelated($related, $related_uri, $importer)
{
- $condition = ['`item-uri` = ? AND `protocol` IN (?, ?)', $related_uri, Conversation::PARCEL_DFRN, Conversation::PARCEL_SALMON];
- $conversation = DBA::selectFirst('conversation', ['source', 'protocol'], $condition);
+ $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);
if (DBA::isResult($conversation)) {
$stored = true;
$xml = $conversation['source'];
use Friendica\Util\Strings;
use Friendica\Util\Network;
use Friendica\Core\Worker;
+use Friendica\Model\Conversation;
use Friendica\Model\FContact;
use Friendica\Protocol\Relay;
return;
}
- DFRN::import($atom, $target_importer);
+ DFRN::import($atom, $target_importer, false, Conversation::PARCEL_LOCAL_DFRN);
if (in_array($cmd, [Delivery::POST, Delivery::POKE])) {
Model\Post\DeliveryData::incrementQueueDone($target_item['uri-id'], Model\Post\DeliveryData::DFRN);
use Friendica\Database\DBA;
if (!defined('DB_UPDATE_VERSION')) {
- define('DB_UPDATE_VERSION', 1380);
+ define('DB_UPDATE_VERSION', 1381);
}
return [
"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"],
"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"],
"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"],