Skip to content

Commit

Permalink
Improve magazine matching in the AddHandler (#1403)
Browse files Browse the repository at this point in the history
  • Loading branch information
BentiGorlich authored Feb 3, 2025
1 parent 7f9fef0 commit d7ed2a8
Showing 1 changed file with 8 additions and 1 deletion.
9 changes: 8 additions & 1 deletion src/MessageHandler/ActivityPub/Inbox/AddHandler.php
Original file line number Diff line number Diff line change
Expand Up @@ -108,6 +108,11 @@ private function handlePinnedAdd(Magazine $targetMag, User $actor, mixed $object
throw new \LogicException("the user '$actor->username' ({$actor->getId()}) is not a moderator of $targetMag->name ({$targetMag->getId()}) and is not from the same instance. They can therefore not add pinned entries");
}

if ('random' === $targetMag->name) {
// do not pin anything in the random magazine
return;
}

$apId = null;
if (\is_string($object)) {
$apId = $object;
Expand All @@ -121,7 +126,9 @@ private function handlePinnedAdd(Magazine $targetMag, User $actor, mixed $object
$pair = $this->apActivityRepository->findLocalByApId($apId);
if (Entry::class === $pair['type']) {
$existingEntry = $this->entryRepository->findOneBy(['id' => $pair['id']]);
if ($existingEntry && !$existingEntry->sticky) {
if ($existingEntry->magazine->getId() !== $targetMag->getId()) {
$this->logger->warning('[AddHandler::handlePinnedAdd] entry {e} is not in the magazine that was targeted {m}. It was in {m2}', ['e' => $existingEntry->title, 'm' => $targetMag->name, 'm2' => $existingEntry->magazine->name]);
} elseif ($existingEntry && !$existingEntry->sticky) {
$this->logger->info('[AddHandler::handlePinnedAdd] Pinning entry {e} to magazine {m}', ['e' => $existingEntry->title, 'm' => $existingEntry->magazine->name]);
$this->entryManager->pin($existingEntry, $actor);
}
Expand Down

0 comments on commit d7ed2a8

Please sign in to comment.