Skip to content

Commit

Permalink
Include content of audience tag in the receivers (#834)
Browse files Browse the repository at this point in the history
  • Loading branch information
BentiGorlich authored Jun 18, 2024
1 parent 88800b1 commit 476314c
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 4 deletions.
2 changes: 1 addition & 1 deletion src/Service/ActivityPub/Note.php
Original file line number Diff line number Diff line change
Expand Up @@ -187,7 +187,7 @@ private function handleSensitiveMedia(PostDto|PostCommentDto|EntryCommentDto|Ent
private function createPost(array $object): Post
{
$dto = new PostDto();
$dto->magazine = $this->activityPubManager->findOrCreateMagazineByToAndCC($object);
$dto->magazine = $this->activityPubManager->findOrCreateMagazineByToCCAndAudience($object);
$dto->apId = $object['id'];

$actor = $this->activityPubManager->findActorOrCreate($object['attributedTo']);
Expand Down
2 changes: 1 addition & 1 deletion src/Service/ActivityPub/Page.php
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ public function create(array $object): Entry
$object['cc'] = [$object['cc']];
}

$magazine = $this->activityPubManager->findOrCreateMagazineByToAndCC($object);
$magazine = $this->activityPubManager->findOrCreateMagazineByToCCAndAudience($object);
$dto = new EntryDto();
$dto->magazine = $magazine;
$dto->title = $object['name'];
Expand Down
16 changes: 14 additions & 2 deletions src/Service/ActivityPubManager.php
Original file line number Diff line number Diff line change
Expand Up @@ -683,7 +683,7 @@ public function updateActor(string $actorUrl): null|Magazine|User
return null;
}

public function findOrCreateMagazineByToAndCC(array $object): Magazine|null
public function findOrCreateMagazineByToCCAndAudience(array $object): Magazine|null
{
$potentialGroups = self::getReceivers($object);
$magazine = $this->magazineRepository->findByApGroupProfileId($potentialGroups);
Expand Down Expand Up @@ -711,8 +711,14 @@ public function findOrCreateMagazineByToAndCC(array $object): Magazine|null
public static function getReceivers(array $object): array
{
$res = [];
if (isset($object['audience']) and \is_array($object['audience'])) {
$res = array_merge($res, $object['audience']);
} elseif (isset($object['audience']) and \is_string($object['audience'])) {
$res[] = $object['audience'];
}

if (isset($object['to']) and \is_array($object['to'])) {
$res = $object['to'];
$res = array_merge($res, $object['to']);
} elseif (isset($object['to']) and \is_string($object['to'])) {
$res[] = $object['to'];
}
Expand All @@ -724,6 +730,12 @@ public static function getReceivers(array $object): array
}

if (isset($object['object']) and \is_array($object['object'])) {
if (isset($object['object']['audience']) and \is_array($object['object']['audience'])) {
$res = array_merge($res, $object['object']['audience']);
} elseif (isset($object['object']['audience']) and \is_string($object['object']['audience'])) {
$res[] = $object['object']['audience'];
}

if (isset($object['object']['to']) and \is_array($object['object']['to'])) {
$res = array_merge($res, $object['object']['to']);
} elseif (isset($object['object']['to']) and \is_string($object['object']['to'])) {
Expand Down

0 comments on commit 476314c

Please sign in to comment.