Skip to content

Commit

Permalink
AP users: make show protocol-specific UI like remote follow conditional
Browse files Browse the repository at this point in the history
for #512
  • Loading branch information
snarfed committed Jun 4, 2023
1 parent 47b3dd2 commit d30eccb
Show file tree
Hide file tree
Showing 4 changed files with 30 additions and 5 deletions.
26 changes: 21 additions & 5 deletions pages.py
Expand Up @@ -55,14 +55,14 @@ def web_user_redirects(**kwargs):

@app.get(f'/<any({",".join(PROTOCOLS)}):protocol>/<id>')
def user(protocol, id):
# TODO: unify this with followers_or_following, others
cls = PROTOCOLS[protocol]
g.user = cls.get_by_id(id)
if not g.user:
g.user = cls.query(cls.readable_id == id).get()

if not g.user or not g.user.direct:
return USER_NOT_FOUND_HTML, 404
elif id != g.user.readable_or_key_id(): # this also handles use_instead
elif id != g.user.readable_or_key_id(): # this also handles use_instead
return redirect(g.user.user_page_path(), code=301)

assert not g.user.use_instead
Expand Down Expand Up @@ -94,9 +94,17 @@ def user(protocol, id):

@app.get(f'/<any({",".join(PROTOCOLS)}):protocol>/<id>/<any(followers,following):collection>')
def followers_or_following(protocol, id, collection):
g.user = PROTOCOLS[protocol].get_by_id(id) # g.user is used in template
# TODO: unify this with user, feed
cls = PROTOCOLS[protocol]
g.user = cls.get_by_id(id)
if not g.user:
g.user = cls.query(cls.readable_id == id).get()
if not g.user or not g.user.direct:
return USER_NOT_FOUND_HTML, 404
elif id != g.user.readable_or_key_id(): # this also handles use_instead
return redirect(g.user.user_page_path(), code=301)

assert not g.user.use_instead

followers, before, after = Follower.fetch_page(id, collection)

Expand All @@ -123,9 +131,17 @@ def feed(protocol, id):
if format not in ('html', 'atom', 'rss'):
error(f'format {format} not supported; expected html, atom, or rss')

g.user = PROTOCOLS[protocol].get_by_id(id)
# TODO: unify this with user, followers_or_following
cls = PROTOCOLS[protocol]
g.user = cls.get_by_id(id)
if not g.user:
return render_template('user_not_found.html', domain=id), 404
g.user = cls.query(cls.readable_id == id).get()
if not g.user or not g.user.direct:
return USER_NOT_FOUND_HTML, 404
elif id != g.user.readable_or_key_id(): # this also handles use_instead
return redirect(g.user.user_page_path(), code=301)

assert not g.user.use_instead

objects, _, _ = Object.query(
Object.domains == id, Object.labels == 'feed') \
Expand Down
2 changes: 2 additions & 0 deletions templates/following.html
Expand Up @@ -8,6 +8,7 @@

<div class="row big">Following</div>

{% if g.user.LABEL != 'activitypub' %}
<div class="row">
<form method="post" action="/follow/start">
<p>
Expand All @@ -20,6 +21,7 @@
</p>
</form>
</div>
{% endif %}

{% with page_name="following" %}
{% include "_followers.html" %}
Expand Down
4 changes: 4 additions & 0 deletions templates/user.html
Expand Up @@ -4,6 +4,7 @@

{% block content %}

{% if g.user.LABEL == 'web' %}
{% if g.user.has_redirects == False %}
<div class="row promo warning">
<form method="post" action="/web-site">
Expand Down Expand Up @@ -35,6 +36,7 @@
</form>
</div>
{% endif %}
{% endif %}

{% include "user_addresses.html" %}

Expand All @@ -48,6 +50,7 @@
&middot; <a href="{{ g.user.ap_actor() }}">ActivityPub</a>
</div>

{% if g.user.LABEL != 'activitypub' %}
<div class="row">
<form method="post" action="/remote-follow">
<p>
Expand All @@ -60,6 +63,7 @@
</p>
</form>
</div>
{% endif %}

{% include "activities.html" %}

Expand Down
3 changes: 3 additions & 0 deletions templates/user_addresses.html
Expand Up @@ -12,12 +12,15 @@

<nobr>
{{ util.pretty_link(g.user.web_url(), text_prefix='馃寪', attrs={'title': 'Web site'})|safe }}

{% if g.user.LABEL != 'activitypub' %}
<form method="post" action="/webmention-interactive">
<input name="source" type="hidden" value="{{ g.user.web_url() }}/" />
<button id="update-profile-button" type="submit"
title="Update profile from web site"
class="btn btn-default glyphicon glyphicon-refresh"></button>
</form>
{% endif %}
</nobr>
</div>
</div>

0 comments on commit d30eccb

Please sign in to comment.