From e2d3f6d23d4e73fa4dbaad82ecebba507875fcfc Mon Sep 17 00:00:00 2001 From: freamon Date: Tue, 29 Oct 2024 10:33:59 +0000 Subject: [PATCH] Exclude blocked instances from linked instances in federated_instances response --- app/activitypub/routes.py | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) diff --git a/app/activitypub/routes.py b/app/activitypub/routes.py index fa5f9db2..6c36afde 100644 --- a/app/activitypub/routes.py +++ b/app/activitypub/routes.py @@ -206,17 +206,18 @@ def lemmy_federated_instances(): linked = [] allowed = [] blocked = [] + for instance in AllowedInstances.query.all(): + allowed.append({"id": instance.id, "domain": instance.domain, "published": utcnow(), "updated": utcnow()}) + for instance in BannedInstances.query.all(): + blocked.append({"id": instance.id, "domain": instance.domain, "published": utcnow(), "updated": utcnow()}) for instance in instances: instance_data = {"id": instance.id, "domain": instance.domain, "published": instance.created_at.isoformat(), "updated": instance.updated_at.isoformat()} if instance.software: instance_data['software'] = instance.software if instance.version: instance_data['version'] = instance.version - linked.append(instance_data) - for instance in AllowedInstances.query.all(): - allowed.append({"id": instance.id, "domain": instance.domain, "published": utcnow(), "updated": utcnow()}) - for instance in BannedInstances.query.all(): - blocked.append({"id": instance.id, "domain": instance.domain, "published": utcnow(), "updated": utcnow()}) + if not any(blocked_instance.get('domain') == instance.domain for blocked_instance in blocked): + linked.append(instance_data) return jsonify({ "federated_instances": { "linked": linked,