From bd42f5757f3c284cf463b2cdb2eadf87fead5056 Mon Sep 17 00:00:00 2001 From: Hypolite Petovan Date: Sat, 2 Oct 2021 16:02:58 -0400 Subject: [PATCH] Implement relationship termination for Mastodon block - This is the expected Mastodon behavior on block --- src/Module/Api/Mastodon/Accounts/Block.php | 22 +++++++++++++++++++++- 1 file changed, 21 insertions(+), 1 deletion(-) diff --git a/src/Module/Api/Mastodon/Accounts/Block.php b/src/Module/Api/Mastodon/Accounts/Block.php index 211148049..463383df7 100644 --- a/src/Module/Api/Mastodon/Accounts/Block.php +++ b/src/Module/Api/Mastodon/Accounts/Block.php @@ -24,6 +24,7 @@ namespace Friendica\Module\Api\Mastodon\Accounts; use Friendica\Core\System; use Friendica\DI; use Friendica\Model\Contact; +use Friendica\Model\User; use Friendica\Module\BaseApi; /** @@ -40,7 +41,26 @@ class Block extends BaseApi DI::mstdnError()->UnprocessableEntity(); } - Contact\User::setBlocked($parameters['id'], $uid, true); + $owner = User::getOwnerDataById($uid); + if (empty($owner)) { + DI::mstdnError()->Forbidden(); + } + + $cdata = Contact::getPublicAndUserContactID($parameters['id'], $uid); + if (empty($cdata['user'])) { + DI::mstdnError()->RecordNotFound(); + } + + $contact = Contact::getById($cdata['user']); + if (empty($contact)) { + DI::mstdnError()->RecordNotFound(); + } + + Contact\User::setBlocked($cdata['user'], $uid, true); + + // Mastodon-expected behavior: relationship is severed on block + Contact::terminateFriendship($owner, $contact); + Contact::revokeFollow($contact); System::jsonExit(DI::mstdnRelationship()->createFromContactId($parameters['id'], $uid)->toArray()); }