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/Model/Actor.php | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) (limited to 'Digitigrade/Model/Actor.php') diff --git a/Digitigrade/Model/Actor.php b/Digitigrade/Model/Actor.php index ffaf4e8..3fb7e4e 100644 --- a/Digitigrade/Model/Actor.php +++ b/Digitigrade/Model/Actor.php @@ -2,6 +2,7 @@ namespace Digitigrade\Model; use Digitigrade\Db; +use Digitigrade\Job\PeriodicFetchRemoteFeed; use Digitigrade\Job\ProcessIncomingPush; use Digitigrade\Job\ProcessIncomingSimplePush; use Digitigrade\Notification\PendingFollowActionedNotif; @@ -254,10 +255,26 @@ class Actor extends PushableModel implements RpcReceiver { * @return FollowRelationStatus PENDING if a request was sent or ACTIVE if the follow went through immediately */ public function follow(self $target): FollowRelationStatus { + // handle actors with no follow endpoint + if (!$target->isLocal && !isset($target->endpoints->follow, $target->endpoints->unfollow)) { + // if this is the first time someone local followed this actor, put a job in to update them + if (count(array_filter($target->findFollowers(), fn(Actor $a) => $a->isLocal)) == 0) { + (new PeriodicFetchRemoteFeed($target))->submit(); + } + FollowRelation::create($this, $target, FollowRelationStatus::ACTIVE); + // no need to processNotifications because it's always going to be a remote user & not pending + return FollowRelationStatus::ACTIVE; + } + return $target->rpcCall('follow', [$this]); } public function unfollow(self $target) { + // handle actors with no follow endpoint + if (!$target->isLocal && !isset($target->endpoints->follow, $target->endpoints->unfollow)) { + FollowRelation::findByActors($this, $target)?->remove(); + return; + } $target->rpcCall('unfollow', [$this]); } -- cgit v1.3