From 1189910b532b9a829c05537cfcd834dc56b7bacb Mon Sep 17 00:00:00 2001 From: Thomas Sileo Date: Sat, 29 Jun 2019 11:33:29 +0200 Subject: [PATCH] Fix `Question` display Pleroma does not set the `endTime` field as Mastodon does. --- app.py | 7 +++++-- templates/lookup.html | 2 +- templates/utils.html | 9 +++++---- 3 files changed, 11 insertions(+), 7 deletions(-) diff --git a/app.py b/app.py index a899489..7489735 100644 --- a/app.py +++ b/app.py @@ -391,7 +391,7 @@ def gt_ts(val): def format_timeago(val): if val: dt = parser.parse(val) - return timeago.format(dt, datetime.now(timezone.utc)) + return timeago.format(dt.astimezone(timezone.utc), datetime.now(timezone.utc)) return val @@ -405,7 +405,9 @@ def has_type(doc, _types): @app.template_filter() def has_actor_type(doc): - for t in ap.ACTOR_TYPES: + # FIXME(tsileo): skipping the last one "Question", cause Mastodon sends question restuls as an update coming from + # the question... Does Pleroma do that too? + for t in ap.ACTOR_TYPES[:-1]: if has_type(doc, t.value): return True return False @@ -2184,6 +2186,7 @@ def _get_prop(props, name, default=None): def get_client_id_data(url): + # FIXME(tsileo): ensure not localhost via `little_boxes.urlutils.is_url_valid` data = mf2py.parse(url=url) for item in data["items"]: if "h-x-app" in item["type"] or "h-app" in item["type"]: diff --git a/templates/lookup.html b/templates/lookup.html index ebf7213..13675bf 100644 --- a/templates/lookup.html +++ b/templates/lookup.html @@ -29,7 +29,7 @@ {{ utils.display_actor_inline(data, size=80) }} {% elif data | has_type('Create') %} {{ utils.display_note(data.object, ui=True) }} - {% elif data | has_type(['Note', 'Article', 'Video', 'Audio', 'Page']) %} + {% elif data | has_type(['Note', 'Article', 'Video', 'Audio', 'Page', 'Question']) %} {{ utils.display_note(data, ui=True) }} {% elif data | has_type('Announce') %} {% set boost_actor = meta.actor %} diff --git a/templates/utils.html b/templates/utils.html index a5b713c..ed0933e 100644 --- a/templates/utils.html +++ b/templates/utils.html @@ -38,6 +38,7 @@ {% set aid = obj.id | quote_plus %} {% endif %} +{% set real_end_time = obj.closed or obj.endTime %}
@@ -95,7 +96,7 @@ {% endfor %}

- {% if obj.closed or obj.endTime | gtnow %} + {% if real_end_time | gtnow %} Ended {{ obj.endTime | format_timeago }} with {{ total_votes }} vote{% if total_votes | gtone %}s{% endif %}. {% else %} Ends {{ obj.endTime | format_timeago }} ({{ total_votes }} vote{% if total_votes | gtone %}s{% endif %} as of now). @@ -108,7 +109,7 @@

  • -{% if not meta.voted_for and not obj.endTime | gtnow %} +{% if not meta.voted_for and not real_end_time | gtnow %}
    @@ -123,8 +124,8 @@
  • {% endfor %} -

    {% if obj.endTime | gtnow %}This question ended {{ obj.endTime | format_timeago }}.

    - {% else %}This question ends {{ obj.endTime | format_timeago }}{% endif %} +

    {% if real_end_time | gtnow %}This question ended {{ real_end_time | format_timeago }}.

    + {% else %}This question ends {{ real_end_time | format_timeago }}{% endif %}