Prepend implicit author mentions in outgoing Diaspora comments

- Add Diaspora::prependParentAuthorMention method
This commit is contained in:
Hypolite Petovan 2019-02-08 23:10:36 -05:00
parent e514ecb6fa
commit 199fac3397

View file

@ -10,6 +10,7 @@
namespace Friendica\Protocol; namespace Friendica\Protocol;
use Friendica\Content\Feature;
use Friendica\Content\Text\BBCode; use Friendica\Content\Text\BBCode;
use Friendica\Content\Text\Markdown; use Friendica\Content\Text\Markdown;
use Friendica\Core\Cache; use Friendica\Core\Cache;
@ -3666,6 +3667,20 @@ class Diaspora
return $msg; return $msg;
} }
private static function prependParentAuthorMention($body, $profile_url)
{
$profile = Contact::getDetailsByURL($profile_url);
if (!empty($profile['addr'])
&& $profile['contact-type'] != Contact::TYPE_COMMUNITY
&& !strstr($body, $profile['addr'])
&& !strstr($body, $profile_url)
) {
$body = '@[url=' . $profile_url . ']' . $profile['nick'] . '[/url] ' . $body;
}
return $body;
}
/** /**
* @brief Sends a post * @brief Sends a post
* *
@ -3773,12 +3788,18 @@ class Diaspora
return $result; return $result;
} }
$parent = Item::selectFirst(['guid'], ['id' => $item["parent"], 'parent' => $item["parent"]]); $parent = Item::selectFirst(['guid', 'author-link'], ['id' => $item["parent"], 'parent' => $item["parent"]]);
if (!DBA::isResult($parent)) { if (!DBA::isResult($parent)) {
return false; return false;
} }
$text = html_entity_decode(BBCode::toMarkdown($item["body"])); $body = $item["body"];
if (empty($item['uid']) || !Feature::isEnabled($item['uid'], 'explicit_mentions')) {
$body = self::prependParentAuthorMention($body, $parent['author-link']);
}
$text = html_entity_decode(BBCode::toMarkdown($body));
$created = DateTimeFormat::utc($item["created"], DateTimeFormat::ATOM); $created = DateTimeFormat::utc($item["created"], DateTimeFormat::ATOM);
$comment = ["author" => self::myHandle($owner), $comment = ["author" => self::myHandle($owner),