From 8027a363598734fb1d190e65fe2595b9cf0b500f Mon Sep 17 00:00:00 2001 From: Thomas Sileo Date: Sun, 3 Jun 2018 23:11:43 +0200 Subject: [PATCH] Start displaying the acor that liked a particular note --- activitypub.py | 8 ++++---- app.py | 12 +++++++++++- templates/note.html | 2 +- templates/utils.html | 30 +++++++++++++++++++++++++++--- 4 files changed, 43 insertions(+), 9 deletions(-) diff --git a/activitypub.py b/activitypub.py index 1b2aed2..80becfb 100644 --- a/activitypub.py +++ b/activitypub.py @@ -246,9 +246,6 @@ class BaseActivity(object): raise ValueError('Invalid actor') return actor['id'] - def reset_object_cache(self) -> None: - self.__obj = None - def get_object(self) -> 'BaseActivity': if self.__obj: return self.__obj @@ -264,9 +261,12 @@ class BaseActivity(object): p = parse_activity(obj) - self.__obj: BaseActivity = p + self.__obj: Optional[BaseActivity] = p return p + def reset_object_cache(self) -> None: + self.__obj = None + def to_dict(self, embed: bool = False, embed_object_id_only: bool = False) -> ObjectType: data = dict(self._data) if embed: diff --git a/app.py b/app.py index f0b6d9a..c7993f5 100644 --- a/app.py +++ b/app.py @@ -464,7 +464,17 @@ def note_by_id(note_id): if data['meta'].get('deleted', False): abort(410) thread = _build_thread(data) - return render_template('note.html', me=ME, thread=thread, note=data) + + + likes = list(DB.inbox.find({ + 'meta.undo': False, + 'type': ActivityType.LIKE.value, + '$or': [{'activity.object.id': data['activity']['object']['id']}, + {'activity.object': data['activity']['object']['id']}], + })) + likes = [ACTOR_SERVICE.get(doc['activity']['actor']) for doc in likes] + + return render_template('note.html', likes=likes, me=ME, thread=thread, note=data) @app.route('/nodeinfo') diff --git a/templates/note.html b/templates/note.html index c6b4ac7..0ff83ed 100644 --- a/templates/note.html +++ b/templates/note.html @@ -16,6 +16,6 @@ {% block content %}
{% include "header.html" %} -{{ utils.display_thread(thread) }} +{{ utils.display_thread(thread, likes) }}
{% endblock %} diff --git a/templates/utils.html b/templates/utils.html index b33185c..07fb19e 100644 --- a/templates/utils.html +++ b/templates/utils.html @@ -1,3 +1,19 @@ +{% macro display_actor_inline(follower) -%} + + +{% if not follower.icon %} + +{% else %} +{% endif %} + +
+
{{ follower.name or follower.preferredUsername }}
+@{{ follower.preferredUsername }}@{{ follower.url | domain }} +
+
+{%- endmacro %} + + {% macro display_actor(follower) -%}
@@ -16,7 +32,7 @@ {%- endmacro %} -{% macro display_note(item, perma=False, ui=False) -%} +{% macro display_note(item, perma=False, ui=False, likes=[]) -%} {% set actor = item.activity.object.attributedTo | get_actor %}
@@ -111,12 +127,20 @@
+{% if likes %} +
+

Liked by

{% for like in likes %} +{{ display_actor_inline(like) }} +{% endfor %} +
+{% endif %} + {%- endmacro %} -{% macro display_thread(thread) -%} +{% macro display_thread(thread, likes=[]) -%} {% for reply in thread %} {% if reply._requested %} -{{ display_note(reply, perma=True, ui=False) }} +{{ display_note(reply, perma=True, ui=False, likes=likes) }} {% else %} {{ display_note(reply, perma=False, ui=True) }} {% endif %}