From d8f7967e6a706547078215a99f005d12553565ca Mon Sep 17 00:00:00 2001 From: Thomas Sileo Date: Sat, 14 Jul 2018 12:14:08 +0200 Subject: [PATCH] Tweak the admin UI --- Makefile | 4 ++++ activitypub.py | 30 ++++++++++++++++++------------ app.py | 2 +- tasks.py | 3 +++ templates/following.html | 13 ++++++++++++- templates/utils.html | 15 ++++++++------- 6 files changed, 46 insertions(+), 21 deletions(-) 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" %}
- {% for followed in following_data %} + {% for (follow_id, followed) in following_data %} + {% if session.logged_in %} +
+
+ + + + +
+
+ + {% endif %}
{{ utils.display_actor_inline(followed, size=80) }}
diff --git a/templates/utils.html b/templates/utils.html index b6b0e32..d0858b1 100644 --- a/templates/utils.html +++ b/templates/utils.html @@ -65,18 +65,19 @@ permalink {% if meta.count_reply %}{{ meta.count_reply }} replies{% endif %} -{% if meta.count_boost %}{{ meta.count_boost }} boosts{% endif %} -{% if meta.count_like %}{{ meta.count_like }} likes{% endif %} +{% if meta.count_boost and obj.id | is_from_outbox %}{{ meta.count_boost }} boosts{% endif %} +{% if meta.count_like and obj.id | is_from_outbox %}{{ meta.count_like }} likes{% endif %} +{% endif %} + +{% if session.logged_in %} +{% set perma_id = obj.id | permalink_id %} +{% set redir = request.path + "#activity-" + perma_id %} +{% set aid = obj.id | quote_plus %} {% endif %} {% if ui and session.logged_in %} -{% set aid = obj.id | quote_plus %} reply - -{% set perma_id = obj.id | permalink_id %} -{% set redir = request.path + "#activity-" + perma_id %} - {% if meta.boosted %}