diff --git a/Makefile b/Makefile index a387a2b..6c7a767 100644 --- a/Makefile +++ b/Makefile @@ -14,6 +14,10 @@ reload-fed: WEB_PORT=5006 CONFIG_DIR=./tests/fixtures/instance1/config docker-compose -p instance1 -f docker-compose-tests.yml up -d --force-recreate --build WEB_PORT=5007 CONFIG_DIR=./tests/fixtures/instance2/config docker-compose -p instance2 -f docker-compose-tests.yml up -d --force-recreate --build +reload-dev: + docker build . -t microblogpub:latest + docker-compose -f docker-compose-dev.yml up -d --force-recreate + update: git pull docker build . -t microblogpub:latest diff --git a/activitypub.py b/activitypub.py index 2e748fa..6ce6483 100644 --- a/activitypub.py +++ b/activitypub.py @@ -103,25 +103,31 @@ class MicroblogPubBackend(Backend): def outbox_new(self, as_actor: ap.Person, activity: ap.BaseActivity) -> None: self.save(Box.OUTBOX, activity) + def followers(self) -> List[str]: + q = { + "box": Box.INBOX.value, + "type": ap.ActivityType.FOLLOW.value, + "meta.undo": False, + } + return [doc["activity"]["actor"] for doc in DB.activities.find(q)] + + def following(self) -> List[str]: + q = { + "box": Box.OUTBOX.value, + "type": ap.ActivityType.FOLLOW.value, + "meta.undo": False, + } + return [doc["activity"]["object"] for doc in DB.activities.find(q)] + def parse_collection( self, payload: Optional[Dict[str, Any]] = None, url: Optional[str] = None ) -> List[str]: """Resolve/fetch a `Collection`/`OrderedCollection`.""" # Resolve internal collections via MongoDB directly if url == ID + "/followers": - q = { - "box": Box.INBOX.value, - "type": ap.ActivityType.FOLLOW.value, - "meta.undo": False, - } - return [doc["activity"]["actor"] for doc in DB.activities.find(q)] + return self.followers() elif url == ID + "/following": - q = { - "box": Box.OUTBOX.value, - "type": ap.ActivityType.FOLLOW.value, - "meta.undo": False, - } - return [doc["activity"]["object"] for doc in DB.activities.find(q)] + return self.following() return super().parse_collection(payload, url) diff --git a/app.py b/app.py index 0febe0f..d431bc1 100644 --- a/app.py +++ b/app.py @@ -1585,7 +1585,7 @@ def following(): following, older_than, newer_than = paginated_query(DB.activities, q) following = [ - get_backend().fetch_iri(doc["activity"]["object"]) for doc in following + (doc["remote_id"], get_backend().fetch_iri(doc["activity"]["object"])) for doc in following ] return render_template( "following.html", diff --git a/tasks.py b/tasks.py index bbb8796..79a1d51 100644 --- a/tasks.py +++ b/tasks.py @@ -37,6 +37,9 @@ def process_new_activity(self, iri: str) -> None: activity = ap.fetch_remote_activity(iri) log.info(f"activity={activity!r}") + # Is the activity expected? + # following = ap.get_backend().following() + tag_stream = False if activity.has_type(ap.ActivityType.ANNOUNCE): tag_stream = True diff --git a/templates/following.html b/templates/following.html index c249b7d..1b96ed1 100644 --- a/templates/following.html +++ b/templates/following.html @@ -8,7 +8,18 @@ {% include "header.html" %}