<?php
/**
- * @copyright Copyright (C) 2020, Friendica
+ * @copyright Copyright (C) 2010-2021, the Friendica project
*
* @license GNU AGPL version 3 or any later version
*
namespace Friendica\Protocol;
use Friendica\Content\Feature;
-use Friendica\Content\PageInfo;
use Friendica\Content\Text\BBCode;
use Friendica\Content\Text\Markdown;
use Friendica\Core\Cache\Duration;
use Friendica\Model\Contact;
use Friendica\Model\Conversation;
use Friendica\Model\FContact;
+use Friendica\Model\GServer;
use Friendica\Model\Item;
use Friendica\Model\ItemURI;
use Friendica\Model\Mail;
* 'key' => The public key of the author
* @throws \Exception
*/
- private static function message($guid, $server, $level = 0)
+ public static function message($guid, $server, $level = 0)
{
if ($level > 5) {
return false;
return false;
}
+ if (!empty($contact['gsid'])) {
+ GServer::setProtocol($contact['gsid'], Post\DeliveryData::DIASPORA);
+ }
+
$message_id = self::messageExists($importer["uid"], $guid);
if ($message_id) {
return true;
// Will be overwritten for sharing accounts in Item::insert
if ($fetched) {
- $datarray["post-type"] = Item::PT_FETCHED;
+ $datarray["post-reason"] = Item::PR_FETCHED;
} elseif ($datarray["uid"] == 0) {
- $datarray["post-type"] = Item::PT_GLOBAL;
+ $datarray["post-reason"] = Item::PR_GLOBAL;
} else {
- $datarray["post-type"] = Item::PT_COMMENT;
+ $datarray["post-reason"] = Item::PR_COMMENT;
}
$datarray["guid"] = $guid;
$datarray['thr-parent'] = $thr_parent ?: $toplevel_parent_item['uri'];
$datarray["object-type"] = Activity\ObjectType::COMMENT;
+ $datarray["post-type"] = Item::PT_NOTE;
$datarray["protocol"] = Conversation::PARCEL_DIASPORA;
$datarray["source"] = $xml;
return false;
}
+ if (!empty($contact['gsid'])) {
+ GServer::setProtocol($contact['gsid'], Post\DeliveryData::DIASPORA);
+ }
+
$conversation = DBA::selectFirst('conv', [], ['uid' => $importer["uid"], 'guid' => $guid]);
if (!DBA::isResult($conversation)) {
$r = q(
return false;
}
+ if (!empty($contact['gsid'])) {
+ GServer::setProtocol($contact['gsid'], Post\DeliveryData::DIASPORA);
+ }
+
$message_id = self::messageExists($importer["uid"], $guid);
if ($message_id) {
return true;
return false;
}
+ if (!empty($contact['gsid'])) {
+ GServer::setProtocol($contact['gsid'], Post\DeliveryData::DIASPORA);
+ }
+
$conversation = null;
$condition = ['uid' => $importer["uid"], 'guid' => $conversation_guid];
return false;
}
+ if (!empty($contact['gsid'])) {
+ GServer::setProtocol($contact['gsid'], Post\DeliveryData::DIASPORA);
+ }
+
if (self::messageExists($importer["uid"], $guid)) {
return true;
}
$item["body"] = self::replacePeopleGuid($item["body"], $item["author-link"]);
- // Add OEmbed and other information to the body
- $item["body"] = PageInfo::searchAndAppendToBody($item["body"], false, true);
-
return $item;
} else {
return $item;
return false;
}
+ if (!empty($contact['gsid'])) {
+ GServer::setProtocol($contact['gsid'], Post\DeliveryData::DIASPORA);
+ }
+
$message_id = self::messageExists($importer["uid"], $guid);
if ($message_id) {
return true;
Tag::storeFromBody($datarray['uri-id'], $datarray["body"]);
- Post\Media::copy($original_item['uri-id'], $datarray['uri-id']);
$datarray["app"] = $original_item["app"];
$datarray["plink"] = self::plink($author, $guid);
}
// Fetch items that are about to be deleted
- $fields = ['uid', 'id', 'parent', 'author-link', 'file'];
+ $fields = ['uid', 'id', 'parent', 'author-link', 'uri-id'];
// When we receive a public retraction, we delete every item that we find.
if ($importer['uid'] == 0) {
}
while ($item = Post::fetch($r)) {
- if (strstr($item['file'], '[')) {
+ if (DBA::exists('post-category', ['uri-id' => $item['uri-id'], 'uid' => $item['uid'], 'type' => Post\Category::FILE])) {
Logger::log("Target guid " . $target_guid . " for user " . $item['uid'] . " is filed. So it won't be deleted.", Logger::DEBUG);
continue;
}
return false;
}
+ if (!empty($contact['gsid'])) {
+ GServer::setProtocol($contact['gsid'], Post\DeliveryData::DIASPORA);
+ }
+
$message_id = self::messageExists($importer["uid"], $guid);
if ($message_id) {
return true;
if ($data->photo) {
foreach ($data->photo as $photo) {
self::storePhotoAsMedia($datarray['uri-id'], $photo);
- $body = "[img]".XML::unescape($photo->remote_photo_path).
- XML::unescape($photo->remote_photo_name)."[/img]\n".$body;
}
$datarray["object-type"] = Activity\ObjectType::IMAGE;
+ $datarray["post-type"] = Item::PT_IMAGE;
} else {
$datarray["object-type"] = Activity\ObjectType::NOTE;
-
- // Add OEmbed and other information to the body
- if (!self::isHubzilla($contact["url"])) {
- $body = PageInfo::searchAndAppendToBody($body, false, true);
- }
+ $datarray["post-type"] = Item::PT_NOTE;
}
/// @todo enable support for polls
$datarray["direction"] = $fetched ? Conversation::PULL : Conversation::PUSH;
if ($fetched) {
- $datarray["post-type"] = Item::PT_FETCHED;
+ $datarray["post-reason"] = Item::PR_FETCHED;
} elseif ($datarray["uid"] == 0) {
- $datarray["post-type"] = Item::PT_GLOBAL;
+ $datarray["post-reason"] = Item::PR_GLOBAL;
}
$datarray["body"] = self::replacePeopleGuid($body, $contact["url"]);
return;
}
- // Fetch some user id to have a valid handle to transmit the participation.
- // In fact it doesn't matter which user sends this - but it is needed by the protocol.
- // If the item belongs to a user, we take this user id.
- if ($item['uid'] == 0) {
- $condition = ['verified' => true, 'blocked' => false, 'account_removed' => false, 'account_expired' => false];
- $first_user = DBA::selectFirst('user', ['uid'], $condition);
- $owner = User::getOwnerDataById($first_user['uid']);
- } else {
- $owner = User::getOwnerDataById($item['uid']);
- }
-
+ $owner = User::getOwnerDataById($item['uid']);
$author = self::myHandle($owner);
$message = ["author" => $author,
return $eventdata;
}
+ /**
+ * Add media attachments to the body
+ *
+ * @param array $item
+ * @return string body
+ */
+ private static function addAttachments(array $item)
+ {
+ $body = $item['body'];
+
+ foreach (Post\Media::getByURIId($item['uri-id'], [Post\Media::IMAGE, Post\Media::AUDIO, Post\Media::VIDEO]) as $media) {
+ if (Item::containsLink($item['body'], $media['url'])) {
+ continue;
+ }
+
+ if ($media['type'] == Post\Media::IMAGE) {
+ if (!empty($media['description'])) {
+ $body .= "\n[img=" . $media['url'] . ']' . $media['description'] .'[/img]';
+ } else {
+ $body .= "\n[img]" . $media['url'] .'[/img]';
+ }
+ } elseif ($media['type'] == Post\Media::AUDIO) {
+ $body .= "\n[audio]" . $media['url'] . "[/audio]\n";
+ } elseif ($media['type'] == Post\Media::VIDEO) {
+ $body .= "\n[video]" . $media['url'] . "[/video]\n";
+ }
+ }
+ return $body;
+ }
+
/**
* Create a post (status message or reshare)
*
$type = "reshare";
} else {
$title = $item["title"];
- $body = $item["body"];
+ $body = self::addAttachments($item);
// Fetch the title from an attached link - if there is one
if (empty($item["title"]) && DI::pConfig()->get($owner['uid'], 'system', 'attach_link_title')) {
return $result;
}
- $toplevel_item = Post::selectFirst(['guid', 'author-id', 'author-link'], ['id' => $item['parent'], 'parent' => $item['parent']]);
+ $toplevel_item = Post::selectFirst(['guid', 'author-id', 'author-link', 'gravity'], ['id' => $item['parent'], 'parent' => $item['parent']]);
if (!DBA::isResult($toplevel_item)) {
Logger::error('Missing parent conversation item', ['parent' => $item['parent']]);
return false;
$thread_parent_item = $toplevel_item;
if ($item['thr-parent'] != $item['parent-uri']) {
- $thread_parent_item = Post::selectFirst(['guid', 'author-id', 'author-link'], ['uri' => $item['thr-parent'], 'uid' => $item['uid']]);
+ $thread_parent_item = Post::selectFirst(['guid', 'author-id', 'author-link', 'gravity'], ['uri' => $item['thr-parent'], 'uid' => $item['uid']]);
}
- $body = $item["body"];
+ $body = self::addAttachments($item);
// The replied to autor mention is prepended for clarity if:
// - Item replied isn't yours
// - Implicit mentions are enabled
if (
$item['author-id'] != $thread_parent_item['author-id']
+ && ($thread_parent_item['gravity'] != GRAVITY_PARENT)
&& (empty($item['uid']) || !Feature::isEnabled($item['uid'], 'explicit_mentions'))
&& !DI::config()->get('system', 'disable_implicit_mentions')
) {