[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
This commit is contained in:
John S Long 2023-08-19 21:37:21 -05:00 committed by GitHub
parent a1237d90f1
commit 79e3f7f204
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 16 additions and 1 deletions

View File

@ -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 {