Support actor without URL

This commit is contained in:
Thomas Sileo 2018-07-22 12:42:36 +02:00
parent f92a6ea3dc
commit 42466ddfba
2 changed files with 20 additions and 13 deletions

23
app.py
View file

@ -274,6 +274,13 @@ def domain(url):
return urlparse(url).netloc
@app.template_filter()
def url_or_id(d):
if 'url' in d:
return d['url']
return d['id']
@app.template_filter()
def get_url(u):
if isinstance(u, dict):
@ -449,14 +456,14 @@ def handle_activitypub_error(error):
return response
@app.errorhandler(Exception)
def handle_other_error(error):
logger.error(
f"caught error {error!r}, {traceback.format_tb(error.__traceback__)}"
)
response = flask_jsonify({})
response.status_code = 500
return response
# @app.errorhandler(Exception)
# def handle_other_error(error):
# logger.error(
# f"caught error {error!r}, {traceback.format_tb(error.__traceback__)}"
# )
# response = flask_jsonify({})
# response.status_code = 500
# return response
# App routes

View file

@ -1,5 +1,5 @@
{% macro display_actor_inline(follower, size=50) -%}
<a class="actor-box" href="{{follower.url | get_url }}" style="clear:both;">
<a class="actor-box" href="{{follower | url_or_id | get_url }}" style="clear:both;">
<span style="float:left;padding-right:15px;">
{% if not follower.icon %}
<img class="actor-icon" src="/static/nopic.png" style="width:{{ size }}px">
@ -8,7 +8,7 @@
</span>
<div class="actor-inline">
<div style="font-weight:bold">{{ follower.name or follower.preferredUsername }}</div>
<small class="lcolor">@{{ follower.preferredUsername }}@{{ follower.url | get_url | domain }}</small>
<small class="lcolor">@{{ follower.preferredUsername }}@{{ follower | url_or_id | get_url | domain }}</small>
</div>
</a>
{%- endmacro %}
@ -25,14 +25,14 @@
<div class="note h-entry" id="activity-{{ obj.id | permalink_id }}">
<div class="h-card p-author">
<a class="u-url u-uid no-hover" href="{{ actor.url | get_url }}"><img class="u-photo" src="{% if not actor.icon %}/static/nopic.png{% else %}{{ actor.icon.url | get_actor_icon_url(50) }}{% endif %}">
<a class="u-url u-uid no-hover" href="{{ actor | url_or_id | get_url }}"><img class="u-photo" src="{% if not actor.icon %}/static/nopic.png{% else %}{{ actor.icon.url | get_actor_icon_url(50) }}{% endif %}">
</a>
<data class="p-name" value="{{ actor.name or actor.preferredUsername }}"></data>
</div>
<div class="note-wrapper">
<a href="{{ actor.url | get_url }}" style="margin:0;text-decoration:none;" class="no-hover"><strong>{{ actor.name or actor.preferredUsername }}</strong>
<span class="l">@{% if not no_color and obj.id | is_from_outbox %}<span class="pcolor">{{ actor.preferredUsername }}</span>{% else %}{{ actor.preferredUsername }}{% endif %}@{% if not no_color and obj.id | is_from_outbox %}<span class="pcolor">{{ actor.url | get_url | domain }}</span>{% else %}{{ actor.url | get_url | domain }}{% endif %}</span></a>
<a href="{{ actor | url_or_id | get_url }}" style="margin:0;text-decoration:none;" class="no-hover"><strong>{{ actor.name or actor.preferredUsername }}</strong>
<span class="l">@{% if not no_color and obj.id | is_from_outbox %}<span class="pcolor">{{ actor.preferredUsername }}</span>{% else %}{{ actor.preferredUsername }}{% endif %}@{% if not no_color and obj.id | is_from_outbox %}<span class="pcolor">{{ actor | url_or_id | get_url | domain }}</span>{% else %}{{ actor | url_or_id | get_url | domain }}{% endif %}</span></a>
{% if not perma %}
<span style="float:right">