Added processing of incoming block notices

This commit is contained in:
Michael
2022-04-05 19:14:29 +00:00
parent 79526564ca
commit c0b3c527d6
6 changed files with 99 additions and 4 deletions
+44
View File
@@ -311,4 +311,48 @@ class User
return $collapsed;
}
/**
* Set/Release that the user is blocked by the contact
*
* @param int $cid Either public contact id or user's contact id
* @param int $uid User ID
* @param boolean $blocked Is the user blocked or unblocked by the contact?
* @throws \Exception
*/
public static function setIsBlocked($cid, $uid, $blocked)
{
$cdata = Contact::getPublicAndUserContactID($cid, $uid);
if (empty($cdata)) {
return;
}
DBA::update('user-contact', ['is-blocked' => $blocked], ['cid' => $cdata['public'], 'uid' => $uid], true);
}
/**
* Returns if the user is blocked by the contact
*
* @param int $cid Either public contact id or user's contact id
* @param int $uid User ID
*
* @return boolean Is the user blocked or unblocked by the contact?
* @throws \Exception
*/
public static function isIsBlocked($cid, $uid)
{
$cdata = Contact::getPublicAndUserContactID($cid, $uid);
if (empty($cdata)) {
return false;
}
if (!empty($cdata['public'])) {
$public_contact = DBA::selectFirst('user-contact', ['is-blocked'], ['cid' => $cdata['public'], 'uid' => $uid]);
if (DBA::isResult($public_contact)) {
return $public_contact['is-blocked'];
}
}
return false;
}
}
+46
View File
@@ -1206,6 +1206,52 @@ class Processor
Logger::info('Deleted contact', ['object' => $activity['object_id']]);
}
/**
* Blocks the user by the contact
*
* @param array $activity
* @throws \Exception
*/
public static function blockPerson($activity)
{
$cid = Contact::getIdForURL($activity['actor']);
if (empty($cid)) {
return;
}
$uid = User::getIdForURL($activity['object_id']);
if (empty($uid)) {
return;
}
Contact\User::setIsBlocked($cid, $uid, true);
Logger::info('Contact blocked user', ['contact' => $cid, 'user' => $uid]);
}
/**
* Unblocks the user by the contact
*
* @param array $activity
* @throws \Exception
*/
public static function unblockPerson($activity)
{
$cid = Contact::getIdForURL($activity['actor']);
if (empty($cid)) {
return;
}
$uid = User::getIdForURL($activity['object_object']);
if (empty($uid)) {
return;
}
Contact\User::setIsBlocked($cid, $uid, false);
Logger::info('Contact unblocked user', ['contact' => $cid, 'user' => $uid]);
}
/**
* Accept a follow request
*
+4 -2
View File
@@ -670,8 +670,7 @@ class Receiver
case 'as:Block':
if (in_array($object_data['object_type'], self::ACCOUNT_TYPES)) {
// Used by Mastodon to announce that the sender has blocked the account
self::storeUnhandledActivity(false, $type, $object_data, $activity, $body, $uid, $trust_source, $push, $signer);
ActivityPub\Processor::blockPerson($object_data);
} else {
self::storeUnhandledActivity(true, $type, $object_data, $activity, $body, $uid, $trust_source, $push, $signer);
}
@@ -728,6 +727,9 @@ class Receiver
} elseif (($object_data['object_type'] == 'as:Accept') &&
in_array($object_data['object_object_type'], self::ACCOUNT_TYPES)) {
ActivityPub\Processor::rejectFollowUser($object_data);
} elseif (($object_data['object_type'] == 'as:Block') &&
in_array($object_data['object_object_type'], self::ACCOUNT_TYPES)) {
ActivityPub\Processor::unblockPerson($object_data);
} elseif (in_array($object_data['object_type'], array_merge(self::ACTIVITY_TYPES, ['as:Announce'])) &&
in_array($object_data['object_object_type'], array_merge(['as:Tombstone'], self::CONTENT_TYPES))) {
ActivityPub\Processor::undoActivity($object_data);