show user's top known instances on the login page
This commit is contained in:
parent
447923b1f1
commit
4c7a919079
|
@ -211,10 +211,10 @@ def delete(post):
|
|||
|
||||
|
||||
def suggested_instances(limit=5, min_popularity=5, blacklist=tuple()):
|
||||
return (
|
||||
return tuple((ins.instance for ins in (
|
||||
MastodonInstance.query
|
||||
.filter(MastodonInstance.popularity > min_popularity)
|
||||
.filter(~MastodonInstance.instance.in_(blacklist))
|
||||
.order_by(db.desc(MastodonInstance.popularity),
|
||||
MastodonInstance.instance)
|
||||
.limit(limit).all())
|
||||
.limit(limit).all())))
|
||||
|
|
|
@ -35,7 +35,10 @@ def index():
|
|||
|
||||
@app.route('/about/')
|
||||
def about():
|
||||
instances = libforget.mastodon.suggested_instances()
|
||||
ki = KnownInstances(request.cookies.get('forget_known_instances', ''))
|
||||
ki.normalize()
|
||||
instances = ki.top()
|
||||
instances += libforget.mastodon.suggested_instances(blacklist=instances)
|
||||
return render_template(
|
||||
'about.html',
|
||||
mastodon_instances=instances,
|
||||
|
@ -270,7 +273,11 @@ def mastodon_login_step2(instance_url):
|
|||
ki.bump(instance_url)
|
||||
|
||||
resp = redirect(url_for('index'))
|
||||
resp.set_cookie('forget_known_instances', ki.serialize())
|
||||
resp.set_cookie(
|
||||
'forget_known_instances', ki.serialize(),
|
||||
max_age=60*60*24*365,
|
||||
httponly=True
|
||||
)
|
||||
return resp
|
||||
|
||||
|
||||
|
|
|
@ -37,12 +37,12 @@
|
|||
<p>
|
||||
|
||||
{% for instance in mastodon_instances %}
|
||||
<a style='background-color:#282c37' class='btn primary' href="{{ url_for('mastodon_login_step1', instance_url=instance.instance) }}">
|
||||
<a style='background-color:#282c37' class='btn primary' href="{{ url_for('mastodon_login_step1', instance_url=instance) }}">
|
||||
{% if loop.first %}
|
||||
{{picture(st, 'mastodon', (20,40,80), ('webp', 'png'))}}
|
||||
Log in with
|
||||
{% endif %}
|
||||
{{instance.instance}}
|
||||
{{instance}}
|
||||
</a>
|
||||
{% else %}
|
||||
<a style='background-color:#282c37' class='btn primary' href="{{ url_for('mastodon_login_step1') }}">
|
||||
|
|
|
@ -18,7 +18,7 @@
|
|||
<datalist id='instances'>
|
||||
<option value=''>
|
||||
{% for instance in instances %}
|
||||
<option value='{{instance.instance}}'>
|
||||
<option value='{{instance}}'>
|
||||
{% endfor %}
|
||||
</datalist>
|
||||
<input name='confirm' value='Log in' type='submit'/>
|
||||
|
|
Loading…
Reference in New Issue