1
0
Fork 0

Fix Diaspora outgoing implicit mention

- Use name instead of nick for implicit mention
- Rename $parent to $toplevel_item in Diaspora::constructComment
- Use thread parent to retrieve the expected mention instead of the top level item
This commit is contained in:
Hypolite Petovan 2019-02-22 23:38:59 -05:00
parent e51f2cea0d
commit fc47a07801

View file

@ -3675,7 +3675,7 @@ class Diaspora
&& !strstr($body, $profile['addr']) && !strstr($body, $profile['addr'])
&& !strstr($body, $profile_url) && !strstr($body, $profile_url)
) { ) {
$body = '@[url=' . $profile_url . ']' . $profile['nick'] . '[/url] ' . $body; $body = '@[url=' . $profile_url . ']' . $profile['name'] . '[/url] ' . $body;
} }
return $body; return $body;
@ -3776,7 +3776,7 @@ class Diaspora
* @param array $item The item that will be exported * @param array $item The item that will be exported
* @param array $owner the array of the item owner * @param array $owner the array of the item owner
* *
* @return array The data for a comment * @return array|false The data for a comment
* @throws \Friendica\Network\HTTPException\InternalServerErrorException * @throws \Friendica\Network\HTTPException\InternalServerErrorException
*/ */
private static function constructComment(array $item, array $owner) private static function constructComment(array $item, array $owner)
@ -3788,30 +3788,40 @@ class Diaspora
return $result; return $result;
} }
$parent = Item::selectFirst(['guid', 'author-link'], ['id' => $item["parent"], 'parent' => $item["parent"]]); $toplevel_item = Item::selectFirst(['guid', 'author-link'], ['id' => $item["parent"], 'parent' => $item["parent"]]);
if (!DBA::isResult($parent)) { if (!DBA::isResult($toplevel_item)) {
Logger::error('Missing parent conversation item', ['parent' => $item["parent"]]);
return false; return false;
} }
$thread_parent_item = $toplevel_item;
if ($item['thr-parent'] != $item['parent-uri']) {
$thread_parent_item = Item::selectFirst(['guid', 'author-link'], ['uri' => $item['thr-parent'], 'uid' => $item['uid']]);
}
$body = $item["body"]; $body = $item["body"];
if (empty($item['uid']) || !Feature::isEnabled($item['uid'], 'explicit_mentions')) { if ((empty($item['uid']) || !Feature::isEnabled($item['uid'], 'explicit_mentions'))
$body = self::prependParentAuthorMention($body, $parent['author-link']); && !Config::get('system', 'disable_implicit_mentions')
) {
$body = self::prependParentAuthorMention($body, $thread_parent_item['author-link']);
} }
$text = html_entity_decode(BBCode::toMarkdown($body)); $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 = [
"guid" => $item["guid"], "author" => self::myHandle($owner),
"created_at" => $created, "guid" => $item["guid"],
"parent_guid" => $parent["guid"], "created_at" => $created,
"text" => $text, "parent_guid" => $toplevel_item["guid"],
"author_signature" => ""]; "text" => $text,
"author_signature" => ""
];
// Send the thread parent guid only if it is a threaded comment // Send the thread parent guid only if it is a threaded comment
if ($item['thr-parent'] != $item['parent-uri']) { if ($item['thr-parent'] != $item['parent-uri']) {
$comment['thread_parent_guid'] = self::getGuidFromUri($item['thr-parent'], $item['uid']); $comment['thread_parent_guid'] = $thread_parent_item['guid'];
} }
Cache::set($cachekey, $comment, Cache::QUARTER_HOUR); Cache::set($cachekey, $comment, Cache::QUARTER_HOUR);