Display followers for followers of private forums

This commit is contained in:
Michael 2022-02-08 21:05:15 +00:00
parent ce762b4154
commit f87b80266c
2 changed files with 17 additions and 9 deletions

View file

@ -25,6 +25,7 @@ use Friendica\BaseModule;
use Friendica\Model\Contact; use Friendica\Model\Contact;
use Friendica\Model\User; use Friendica\Model\User;
use Friendica\Protocol\ActivityPub; use Friendica\Protocol\ActivityPub;
use Friendica\Util\HTTPSignature;
/** /**
* ActivityPub Followers * ActivityPub Followers
@ -45,7 +46,7 @@ class Followers extends BaseModule
$page = $_REQUEST['page'] ?? null; $page = $_REQUEST['page'] ?? null;
$followers = ActivityPub\Transmitter::getContacts($owner, [Contact::FOLLOWER, Contact::FRIEND], 'followers', $page); $followers = ActivityPub\Transmitter::getContacts($owner, [Contact::FOLLOWER, Contact::FRIEND], 'followers', $page, (string)HTTPSignature::getSigner('', $_SERVER));
header('Content-Type: application/activity+json'); header('Content-Type: application/activity+json');
echo json_encode($followers); echo json_encode($followers);

View file

@ -36,7 +36,6 @@ use Friendica\Model\GServer;
use Friendica\Model\Item; use Friendica\Model\Item;
use Friendica\Model\Photo; use Friendica\Model\Photo;
use Friendica\Model\Post; use Friendica\Model\Post;
use Friendica\Model\Profile;
use Friendica\Model\Tag; use Friendica\Model\Tag;
use Friendica\Model\User; use Friendica\Model\User;
use Friendica\Network\HTTPException; use Friendica\Network\HTTPException;
@ -49,6 +48,7 @@ use Friendica\Util\JsonLD;
use Friendica\Util\LDSignature; use Friendica\Util\LDSignature;
use Friendica\Util\Map; use Friendica\Util\Map;
use Friendica\Util\Network; use Friendica\Util\Network;
use Friendica\Util\Strings;
use Friendica\Util\XML; use Friendica\Util\XML;
/** /**
@ -146,15 +146,16 @@ class Transmitter
/** /**
* Collects a list of contacts of the given owner * Collects a list of contacts of the given owner
* *
* @param array $owner Owner array * @param array $owner Owner array
* @param int|array $rel The relevant value(s) contact.rel should match * @param int|array $rel The relevant value(s) contact.rel should match
* @param string $module The name of the relevant AP endpoint module (followers|following) * @param string $module The name of the relevant AP endpoint module (followers|following)
* @param integer $page Page number * @param integer $page Page number
* @param string $requester URL of the requester
* *
* @return array of owners * @return array of owners
* @throws \Exception * @throws \Exception
*/ */
public static function getContacts($owner, $rel, $module, $page = null) public static function getContacts($owner, $rel, $module, $page = null, string $requester = null)
{ {
$parameters = [ $parameters = [
'rel' => $rel, 'rel' => $rel,
@ -179,8 +180,14 @@ class Transmitter
$data['totalItems'] = $total; $data['totalItems'] = $total;
// When we hide our friends we will only show the pure number but don't allow more. // When we hide our friends we will only show the pure number but don't allow more.
$profile = Profile::getByUID($owner['uid']); $show_contacts = empty($owner['hide-friends']);
if (!empty($profile['hide-friends'])) {
// Allow fetching the contact list when the requester is part of the list.
if (($owner['page-flags'] == User::PAGE_FLAGS_PRVGROUP) && !empty($requester)) {
$show_contacts = DBA::exists('contact', ['nurl' => Strings::normaliseLink($requester), 'rel' => $rel]);
}
if (!$show_contacts) {
return $data; return $data;
} }