kopia lustrzana https://github.com/snarfed/bridgy-fed
refactoring: unify followers and following UI page handlers
rodzic
37e389447a
commit
f8fbf1391c
50
pages.py
50
pages.py
|
@ -102,57 +102,31 @@ def user(domain):
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
||||||
@app.get(f'/user/<regex("{common.DOMAIN_RE}"):domain>/followers')
|
@app.get(f'/user/<regex("{common.DOMAIN_RE}"):domain>/<any(followers,following):collection>')
|
||||||
def followers(domain):
|
def followers_or_following(domain, collection):
|
||||||
# unify with following
|
|
||||||
if not (user := User.get_by_id(domain)):
|
if not (user := User.get_by_id(domain)):
|
||||||
return render_template('user_not_found.html', domain=domain), 404
|
return render_template('user_not_found.html', domain=domain), 404
|
||||||
|
|
||||||
|
domain_prop = Follower.dest if collection == 'followers' else Follower.src
|
||||||
query = Follower.query(
|
query = Follower.query(
|
||||||
Follower.status == 'active',
|
Follower.status == 'active',
|
||||||
Follower.dest == domain,
|
domain_prop == domain,
|
||||||
).order(-Follower.updated)
|
).order(-Follower.updated)
|
||||||
followers, before, after = fetch_page(query, Follower)
|
followers, before, after = fetch_page(query, Follower)
|
||||||
|
|
||||||
for f in followers:
|
for f in followers:
|
||||||
f.url = f.src
|
f.url = f.src if collection == 'followers' else f.dest
|
||||||
f.handle = re.sub(r'^https?://(.+)/(users/|@)(.+)$', r'@\3@\1', f.src)
|
f.handle = re.sub(r'^https?://(.+)/(users/|@)(.+)$', r'@\3@\1', f.url)
|
||||||
if f.last_follow:
|
if f.last_follow:
|
||||||
last_follow = json_loads(f.last_follow)
|
last_follow = json_loads(f.last_follow)
|
||||||
actor = last_follow.get('actor', {})
|
person = last_follow.get(
|
||||||
f.name = actor.get('name') or ''
|
'actor' if collection == 'followers' else 'object', {})
|
||||||
f.picture = util.get_url(actor, 'icon')
|
if isinstance(person, dict):
|
||||||
|
f.name = person.get('name') or ''
|
||||||
|
f.picture = util.get_url(person, 'icon') or util.get_url(person, 'image')
|
||||||
|
|
||||||
return render_template(
|
return render_template(
|
||||||
'followers.html',
|
f'{collection}.html',
|
||||||
util=util,
|
|
||||||
**locals()
|
|
||||||
)
|
|
||||||
|
|
||||||
|
|
||||||
@app.get(f'/user/<regex("{common.DOMAIN_RE}"):domain>/following')
|
|
||||||
def following(domain):
|
|
||||||
if not (user := User.get_by_id(domain)):
|
|
||||||
return render_template('user_not_found.html', domain=domain), 404
|
|
||||||
|
|
||||||
query = Follower.query(
|
|
||||||
Follower.status == 'active',
|
|
||||||
Follower.src == domain,
|
|
||||||
).order(-Follower.updated)
|
|
||||||
followers, before, after = fetch_page(query, Follower)
|
|
||||||
|
|
||||||
for f in followers:
|
|
||||||
f.url = f.dest
|
|
||||||
f.handle = re.sub(r'^https?://(.+)/(users/|@)(.+)$', r'@\3@\1', f.dest)
|
|
||||||
if f.last_follow:
|
|
||||||
last_follow = json_loads(f.last_follow)
|
|
||||||
followee = last_follow.get('object', {})
|
|
||||||
# TODO: drop AS1-isms once we've backfilled existing entities to AS2
|
|
||||||
f.name = followee.get('name') or followee.get('displayName') or ''
|
|
||||||
f.picture = util.get_url(followee, 'icon') or util.get_url(followee, 'image')
|
|
||||||
|
|
||||||
return render_template(
|
|
||||||
'following.html',
|
|
||||||
util=util,
|
util=util,
|
||||||
**locals()
|
**locals()
|
||||||
)
|
)
|
||||||
|
|
|
@ -3,6 +3,7 @@ from oauth_dropins.webutil import util
|
||||||
from oauth_dropins.webutil.util import json_dumps, json_loads
|
from oauth_dropins.webutil.util import json_dumps, json_loads
|
||||||
from granary import as2, atom, microformats2, rss
|
from granary import as2, atom, microformats2, rss
|
||||||
|
|
||||||
|
import common
|
||||||
from models import Activity, Follower, User
|
from models import Activity, Follower, User
|
||||||
from . import testutil
|
from . import testutil
|
||||||
from .test_activitypub import LIKE, MENTION, NOTE, REPLY
|
from .test_activitypub import LIKE, MENTION, NOTE, REPLY
|
||||||
|
|
Ładowanie…
Reference in New Issue