From 79e3f7f20474c2fda99640ffa69f94fd05d6d991 Mon Sep 17 00:00:00 2001 From: John S Long Date: Sat, 19 Aug 2023 21:37:21 -0500 Subject: [PATCH] [MastodonBridge] Add support for excluding regular statuses (non-boosts/replies) (#3624) * [MastodonBridge]: add support for excluding posts (non-boosts/replies) * Update name of input * Fix lint failures --- bridges/MastodonBridge.php | 17 ++++++++++++++++- 1 file changed, 16 insertions(+), 1 deletion(-) diff --git a/bridges/MastodonBridge.php b/bridges/MastodonBridge.php index 372838ca..855aae08 100644 --- a/bridges/MastodonBridge.php +++ b/bridges/MastodonBridge.php @@ -35,6 +35,11 @@ class MastodonBridge extends BridgeAbstract 'exampleValue' => '@sebsauvage@framapiaf.org', 'required' => true, ], + 'noregular' => [ + 'name' => 'Without regular statuses', + 'type' => 'checkbox', + 'title' => 'Hide regular statuses (i.e. non-boosts, replies, etc.)', + ], 'norep' => [ 'name' => 'Without replies', 'type' => 'checkbox', @@ -61,6 +66,10 @@ class MastodonBridge extends BridgeAbstract public function collectData() { + if ($this->getInput('norep') && $this->getInput('noboost') && $this->getInput('noregular')) { + throw new \Exception('replies, boosts, or regular statuses must be allowed'); + } + $user = $this->fetchAP($this->getURI()); if (!isset($user['outbox'])) { throw new \Exception('Unable to find the outbox'); @@ -115,6 +124,9 @@ class MastodonBridge extends BridgeAbstract if ($this->getInput('norep') && isset($content['inReplyTo'])) { return null; } + if ($this->getInput('noregular') && !isset($content['inReplyTo'])) { + return null; + } $item['title'] = ''; $item['author'] = $this->getInput('canusername'); $item = $this->parseObject($content, $item); @@ -123,6 +135,9 @@ class MastodonBridge extends BridgeAbstract if ($this->getInput('norep') && isset($content['object']['inReplyTo'])) { return null; } + if ($this->getInput('noregular') && !isset($content['object']['inReplyTo'])) { + return null; + } $item['title'] = ''; $item['author'] = $this->getInput('canusername'); $item = $this->parseObject($content['object'], $item); @@ -147,7 +162,7 @@ class MastodonBridge extends BridgeAbstract if (isset($object['name'])) { $item['title'] = $object['name']; - } else if (mb_strlen($strippedContent) > 75) { + } elseif (mb_strlen($strippedContent) > 75) { $contentSubstring = mb_substr($strippedContent, 0, mb_strpos(wordwrap($strippedContent, 75), "\n")); $item['title'] .= $contentSubstring . '...'; } else {