From 2464dd8782eee316767682b2edceec089fed6f92 Mon Sep 17 00:00:00 2001 From: Thomas Sileo Date: Tue, 28 Aug 2018 22:14:48 +0200 Subject: [PATCH] Fixes invalid likes/boost --- app.py | 18 ++++++++++++++---- templates/stream.html | 2 ++ templates/utils.html | 4 ++-- 3 files changed, 18 insertions(+), 6 deletions(-) diff --git a/app.py b/app.py index 81cc10b..76edaf1 100644 --- a/app.py +++ b/app.py @@ -930,7 +930,7 @@ def note_by_id(note_id): thread = _build_thread(data) app.logger.info(f"thread={thread!r}") - likes = list( + raw_likes = list( DB.activities.find( { "meta.undo": False, @@ -944,10 +944,15 @@ def note_by_id(note_id): } ) ) - likes = [doc["meta"]["actor"] for doc in likes] + likes = [] + for doc in raw_likes: + try: + likes.append(doc["meta"]["actor"]) + except Exception: + app.logger.exception(f"invalid doc: {doc!r}") app.logger.info(f"likes={likes!r}") - shares = list( + raw_shares = list( DB.activities.find( { "meta.undo": False, @@ -960,7 +965,12 @@ def note_by_id(note_id): } ) ) - shares = [doc["meta"]["actor"] for doc in shares] + shares = [] + for doc in raw_shares: + try: + shares.append(doc["meta"]["actor"]) + except Exception: + app.logger.exception(f"invalid doc: {doc!r}") app.logger.info(f"shares={shares!r}") return render_template( diff --git a/templates/stream.html b/templates/stream.html index ca22897..37d1394 100644 --- a/templates/stream.html +++ b/templates/stream.html @@ -14,7 +14,9 @@ {% if item | has_type('Announce') %} {% set boost_actor = item.meta.actor %} + {% if boost_actor %}

{{ boost_actor.name or boost_actor.preferredUsername }} boosted

+ {% endif %} {% if item.meta.object %} {{ utils.display_note(item.meta.object, ui=True) }} {% endif %} diff --git a/templates/utils.html b/templates/utils.html index 3659366..6dc11e1 100644 --- a/templates/utils.html +++ b/templates/utils.html @@ -195,14 +195,14 @@
{% if likes %}
-

{{ meta.count_like }} likes

{% for like in likes %} +

{{ likes|length }} likes

{% for like in likes %} {{ display_actor_inline(like) }} {% endfor %}
{% endif %} {% if shares %}
-

{{ meta.count_boost }} boosts

{% for boost in shares %} +

{{ shares|length }} boosts

{% for boost in shares %} {{ display_actor_inline(boost) }} {% endfor %}