Fix Question display

Pleroma does not set the `endTime` field as Mastodon does.
This commit is contained in:
Thomas Sileo 2019-06-29 11:33:29 +02:00
parent 42bf96e44a
commit 1189910b53
3 changed files with 11 additions and 7 deletions

7
app.py
View file

@ -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"]:

View file

@ -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 %}

View file

@ -38,6 +38,7 @@
{% set aid = obj.id | quote_plus %}
{% endif %}
{% set real_end_time = obj.closed or obj.endTime %}
<div class="note-box">
<div class="note h-entry" id="activity-{{ obj.id | permalink_id }}">
@ -95,7 +96,7 @@
{% endfor %}
</ul>
<p><small>
{% if obj.closed or obj.endTime | gtnow %}
{% if real_end_time | gtnow %}
Ended {{ obj.endTime | format_timeago }} with <strong>{{ total_votes }}</strong> vote{% if total_votes | gtone %}s{% endif %}.
{% else %}
Ends {{ obj.endTime | format_timeago }} (<strong>{{ total_votes }}</strong> vote{% if total_votes | gtone %}s{% endif %} as of now).
@ -108,7 +109,7 @@
<li class="answer">
<span class="answer-text">
{% if not meta.voted_for and not obj.endTime | gtnow %}
{% if not meta.voted_for and not real_end_time | gtnow %}
<span><form action="/api/vote" class="action-form" method="POST">
<input type="hidden" name="redirect" value="{{ redir }}">
<input type="hidden" name="id" value="{{ obj.id }}">
@ -123,8 +124,8 @@
</span>
</li>
{% endfor %}
<p><small>{% if obj.endTime | gtnow %}This question ended {{ obj.endTime | format_timeago }}.</small></p>
{% else %}This question ends {{ obj.endTime | format_timeago }}{% endif %}
<p><small>{% if real_end_time | gtnow %}This question ended {{ real_end_time | format_timeago }}.</small></p>
{% else %}This question ends {{ real_end_time | format_timeago }}{% endif %}
</small></p>
</ul>