From d86f36e4becbe40766598816f837042aad4ce145 Mon Sep 17 00:00:00 2001 From: winter Date: Sun, 4 May 2025 21:04:18 +0100 Subject: allow following actors with no follow endpoint --- Digitigrade/Job/PeriodicFetchRemoteFeed.php | 37 +++++++++++++++++++++++++++++ Digitigrade/Job/ProcessIncomingPush.php | 14 +++++++---- 2 files changed, 47 insertions(+), 4 deletions(-) create mode 100644 Digitigrade/Job/PeriodicFetchRemoteFeed.php (limited to 'Digitigrade/Job') diff --git a/Digitigrade/Job/PeriodicFetchRemoteFeed.php b/Digitigrade/Job/PeriodicFetchRemoteFeed.php new file mode 100644 index 0000000..e84757f --- /dev/null +++ b/Digitigrade/Job/PeriodicFetchRemoteFeed.php @@ -0,0 +1,37 @@ +actorId = $targetActor->id; + $this->remainingTries = 8; + } + + public function run() { + $actor = Actor::find($this->actorId); + $logger = Logger::getInstance(); + // only bother if someone local still follows the actor + if (count(array_filter($actor->findFollowers(), fn(Actor $a) => $a->isLocal)) > 0) { + $logger->info('Fetching feed for simple remote actor ' . $actor->getFullHandle()); + $actor->backfill(GlobalSettings::getInstance()->get('instance.feedUpdateLimit') ?? 50); + $this->submit(); + } else { + $logger->info('No longer fetching feed for ' . $actor->getFullHandle() . ' as nobody follows them anymore'); + } + } + + public function submit() { + JobQueue::getInstance()->submitDelayedUntil( + $this, + (new \DateTimeImmutable)->add(new \DateInterval(GlobalSettings::getInstance()->get('instance.feedUpdateInterval') ?? 'PT1H')) + ); + } +} \ No newline at end of file diff --git a/Digitigrade/Job/ProcessIncomingPush.php b/Digitigrade/Job/ProcessIncomingPush.php index 600972c..16dd1ce 100644 --- a/Digitigrade/Job/ProcessIncomingPush.php +++ b/Digitigrade/Job/ProcessIncomingPush.php @@ -34,15 +34,21 @@ class ProcessIncomingPush extends Job { break; case 'note': $log->info('importing note with uri ' . $this->object->self); + $alreadyExisted = Note::countWhere('uri = ?', [$this->object->self]) > 0; $note = Note::importFromReceivedObject($this->object); - $note?->processTimelineAdditions(); - $note?->processNotifications(); + if (!$alreadyExisted) { + $note?->processTimelineAdditions(); + $note?->processNotifications(); + } break; case 'interaction': $log->info('importing interaction with uri ' . $this->object->self); + $alreadyExisted = Interaction::countWhere('uri = ?', [$this->object->self]) > 0; $interaction = Interaction::importFromReceivedObject($this->object); - $interaction?->processTimelineAdditions(); - $interaction?->processNotifications(); + if (!$alreadyExisted) { + $interaction?->processTimelineAdditions(); + $interaction?->processNotifications(); + } break; case 'extension': throw new \RuntimeException('object type ' . $this->object->type . ' not yet implemented :('); -- cgit v1.3