kopia lustrzana https://github.com/snarfed/bridgy-fed
rodzic
29158e02e9
commit
a1a7ceef51
|
@ -1048,14 +1048,15 @@ class Follower(ndb.Model):
|
|||
return follower
|
||||
|
||||
@staticmethod
|
||||
def fetch_page(collection):
|
||||
"""Fetches a page of Followers for the current user.
|
||||
def fetch_page(collection, user):
|
||||
"""Fetches a page of :class:`Follower`s for a given user.
|
||||
|
||||
Wraps :func:`fetch_page`. Paging uses the ``before`` and ``after`` query
|
||||
parameters, if available in the request.
|
||||
|
||||
Args:
|
||||
collection (str): ``followers`` or ``following``
|
||||
user (User)
|
||||
|
||||
Returns:
|
||||
(list of Follower, str, str) tuple: results, annotated with an extra
|
||||
|
@ -1068,7 +1069,7 @@ class Follower(ndb.Model):
|
|||
filter_prop = Follower.to if collection == 'followers' else Follower.from_
|
||||
query = Follower.query(
|
||||
Follower.status == 'active',
|
||||
filter_prop == g.user.key,
|
||||
filter_prop == user.key,
|
||||
).order(-Follower.updated)
|
||||
|
||||
followers, before, after = fetch_page(query, Follower, by=Follower.updated)
|
||||
|
|
8
pages.py
8
pages.py
|
@ -53,6 +53,9 @@ def load_user(protocol, id):
|
|||
protocol (str):
|
||||
id (str):
|
||||
|
||||
Returns:
|
||||
models.User:
|
||||
|
||||
Raises:
|
||||
:class:`werkzeug.exceptions.HTTPException` on error or redirect
|
||||
"""
|
||||
|
@ -85,6 +88,7 @@ def load_user(protocol, id):
|
|||
error(f'{protocol} user {id} not found', status=404)
|
||||
|
||||
assert not g.user.use_instead
|
||||
return g.user
|
||||
|
||||
|
||||
@app.route('/')
|
||||
|
@ -158,9 +162,9 @@ def notifications(protocol, id):
|
|||
@app.get(f'/<any({",".join(PROTOCOLS)}):protocol>/<id>/<any(followers,following):collection>')
|
||||
@canonicalize_request_domain(common.PROTOCOL_DOMAINS, common.PRIMARY_DOMAIN)
|
||||
def followers_or_following(protocol, id, collection):
|
||||
load_user(protocol, id)
|
||||
user = load_user(protocol, id)
|
||||
|
||||
followers, before, after = Follower.fetch_page(collection)
|
||||
followers, before, after = Follower.fetch_page(collection, user)
|
||||
num_followers, num_following = g.user.count_followers()
|
||||
return render_template(
|
||||
f'{collection}.html',
|
||||
|
|
Ładowanie…
Reference in New Issue