]> git.mxchange.org Git - friendica.git/commitdiff
Implement relationship termination for Mastodon block
authorHypolite Petovan <hypolite@mrpetovan.com>
Sat, 2 Oct 2021 20:02:58 +0000 (16:02 -0400)
committerHypolite Petovan <hypolite@mrpetovan.com>
Sat, 2 Oct 2021 21:30:07 +0000 (17:30 -0400)
- This is the expected Mastodon behavior on block

src/Module/Api/Mastodon/Accounts/Block.php

index 21114804962771c848592845861de2b7645c94d7..463383df71c4608032b7c0da5f8db785935b7359 100644 (file)
@@ -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());
        }