Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Improve magazine matching in the AddHandler #1403

Merged
merged 4 commits into from
Feb 3, 2025
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading