Avoid empty posts on Diaspora

This commit is contained in:
Michael 2021-04-30 22:35:16 +00:00
parent 3666742e7b
commit c840ee82af
4 changed files with 13 additions and 9 deletions

View File

@ -526,15 +526,19 @@ class Media
* Add media attachments to the body * Add media attachments to the body
* *
* @param int $uriid * @param int $uriid
* @param string $body
* @return string body * @return string body
*/ */
public static function addAttachmentsToBody(int $uriid) public static function addAttachmentsToBody(int $uriid, string $body = '')
{ {
$item = Post::selectFirst(['body'], ['uri-id' => $uriid]); if (empty($body)) {
if (!DBA::isResult($item)) { $item = Post::selectFirst(['body'], ['uri-id' => $uriid]);
return ''; if (!DBA::isResult($item)) {
return '';
}
$body = $item['body'];
} }
$body = preg_replace("/\s*\[attachment .*?\].*?\[\/attachment\]\s*/ism", '', $item['body']); $body = preg_replace("/\s*\[attachment .*?\].*?\[\/attachment\]\s*/ism", '', $body);
foreach (self::getByURIId($uriid, [self::IMAGE, self::AUDIO, self::VIDEO]) as $media) { foreach (self::getByURIId($uriid, [self::IMAGE, self::AUDIO, self::VIDEO]) as $media) {
if (Item::containsLink($body, $media['url'])) { if (Item::containsLink($body, $media['url'])) {

View File

@ -899,7 +899,7 @@ class DFRN
$entry->setAttribute("xmlns:statusnet", ActivityNamespace::STATUSNET); $entry->setAttribute("xmlns:statusnet", ActivityNamespace::STATUSNET);
} }
$body = Post\Media::addAttachmentsToBody($item['uri-id']); $body = Post\Media::addAttachmentsToBody($item['uri-id'], $item['body']);
if ($item['private'] == Item::PRIVATE) { if ($item['private'] == Item::PRIVATE) {
$body = Item::fixPrivatePhotos($body, $owner['uid'], $item, $cid); $body = Item::fixPrivatePhotos($body, $owner['uid'], $item, $cid);

View File

@ -3406,7 +3406,7 @@ class Diaspora
$type = "reshare"; $type = "reshare";
} else { } else {
$title = $item["title"]; $title = $item["title"];
$body = Post\Media::addAttachmentsToBody($item['uri-id']); $body = Post\Media::addAttachmentsToBody($item['uri-id'], $item['body']);
// Fetch the title from an attached link - if there is one // Fetch the title from an attached link - if there is one
if (empty($item["title"]) && DI::pConfig()->get($owner['uid'], 'system', 'attach_link_title')) { if (empty($item["title"]) && DI::pConfig()->get($owner['uid'], 'system', 'attach_link_title')) {
@ -3620,7 +3620,7 @@ class Diaspora
$thread_parent_item = Post::selectFirst(['guid', 'author-id', 'author-link', 'gravity'], ['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 = Post\Media::addAttachmentsToBody($item['uri-id']); $body = Post\Media::addAttachmentsToBody($item['uri-id'], $item['body']);
// The replied to autor mention is prepended for clarity if: // The replied to autor mention is prepended for clarity if:
// - Item replied isn't yours // - Item replied isn't yours

View File

@ -1885,7 +1885,7 @@ class OStatus
XML::addElement($doc, $entry, "id", $item["uri"]); XML::addElement($doc, $entry, "id", $item["uri"]);
XML::addElement($doc, $entry, "title", html_entity_decode($title, ENT_QUOTES, 'UTF-8')); XML::addElement($doc, $entry, "title", html_entity_decode($title, ENT_QUOTES, 'UTF-8'));
$body = Post\Media::addAttachmentsToBody($item['uri-id']); $body = Post\Media::addAttachmentsToBody($item['uri-id'], $item['body']);
$body = self::formatPicturePost($body); $body = self::formatPicturePost($body);
if (!empty($item['title'])) { if (!empty($item['title'])) {