From dfcf1b1e6f6c89f412ffe8ee6bd6404408879d6e Mon Sep 17 00:00:00 2001 From: Michael Date: Sat, 16 Mar 2019 08:46:33 +0000 Subject: [PATCH 1/3] We now send a summary via AP. This partially fixes the problem with Mastodon and Articles --- src/Protocol/ActivityPub/Transmitter.php | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/src/Protocol/ActivityPub/Transmitter.php b/src/Protocol/ActivityPub/Transmitter.php index d85f67a7c..79263f8ac 100644 --- a/src/Protocol/ActivityPub/Transmitter.php +++ b/src/Protocol/ActivityPub/Transmitter.php @@ -20,6 +20,7 @@ use Friendica\Model\Term; use Friendica\Model\User; use Friendica\Util\DateTimeFormat; use Friendica\Content\Text\BBCode; +use Friendica\Content\Text\Plaintext; use Friendica\Util\JsonLD; use Friendica\Util\LDSignature; use Friendica\Model\Profile; @@ -1020,7 +1021,7 @@ class Transmitter return $data; } - $data['summary'] = null; // Ignore by now + $data['summary'] = BBCode::getAbstract($item['body'], Protocol::ACTIVITYPUB); if ($item['uri'] != $item['thr-parent']) { $data['inReplyTo'] = $item['thr-parent']; @@ -1054,6 +1055,8 @@ class Transmitter if ($type == 'Note') { $body = self::removePictures($body); + } elseif (($type == 'Article') && empty($data['summary'])) { + $data['summary'] = Plaintext::shorten(self::removePictures($body), 1000); } if ($type == 'Event') { From 14b56ce0cc76186df34ebcadaaae3c9de42d19ca Mon Sep 17 00:00:00 2001 From: Michael Date: Sat, 16 Mar 2019 10:59:11 +0000 Subject: [PATCH 2/3] Adding the "abstract" element to the imported feed --- src/Protocol/Feed.php | 19 ++++++++++++++++--- 1 file changed, 16 insertions(+), 3 deletions(-) diff --git a/src/Protocol/Feed.php b/src/Protocol/Feed.php index 3981a8860..2a2ea0363 100644 --- a/src/Protocol/Feed.php +++ b/src/Protocol/Feed.php @@ -356,11 +356,20 @@ class Feed { if (empty($body)) { $body = trim(XML::getFirstNodeValue($xpath, 'content:encoded/text()', $entry)); } - if (empty($body)) { - $body = trim(XML::getFirstNodeValue($xpath, 'description/text()', $entry)); + + $summary = trim(XML::getFirstNodeValue($xpath, 'atom:summary/text()', $entry)); + + if (empty($summary)) { + $summary = trim(XML::getFirstNodeValue($xpath, 'description/text()', $entry)); } + if (empty($body)) { - $body = trim(XML::getFirstNodeValue($xpath, 'atom:summary/text()', $entry)); + $body = $summary; + $summary = ''; + } + + if ($body == $summary) { + $summary = ''; } // remove the content of the title if it is identically to the body @@ -411,6 +420,10 @@ class Feed { $item["object-type"] = ACTIVITY_OBJ_BOOKMARK; unset($item["attach"]); } else { + if (!empty($summary)) { + $item["body"] = '[abstract]' . HTML::toBBCode($summary, $basepath) . '[/abstract]' . $item["body"]; + } + if ($contact["fetch_further_information"] == 3) { if (!empty($tags)) { $item["tag"] = $tags; From ce2e98ea68f3db7eae13c5f6af1b2886e826c3d2 Mon Sep 17 00:00:00 2001 From: Michael Date: Sat, 16 Mar 2019 11:18:36 +0000 Subject: [PATCH 3/3] Adding a line feed looks nicer --- src/Protocol/Feed.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Protocol/Feed.php b/src/Protocol/Feed.php index 2a2ea0363..0cf1db7cb 100644 --- a/src/Protocol/Feed.php +++ b/src/Protocol/Feed.php @@ -421,7 +421,7 @@ class Feed { unset($item["attach"]); } else { if (!empty($summary)) { - $item["body"] = '[abstract]' . HTML::toBBCode($summary, $basepath) . '[/abstract]' . $item["body"]; + $item["body"] = '[abstract]' . HTML::toBBCode($summary, $basepath) . "[/abstract]\n" . $item["body"]; } if ($contact["fetch_further_information"] == 3) {