kopia lustrzana https://github.com/snarfed/bridgy-fed
rodzic
8abfbbbc71
commit
62007c112f
21
pages.py
21
pages.py
|
@ -374,6 +374,27 @@ def set_username(user=None):
|
|||
return redirect('/settings', code=302)
|
||||
|
||||
|
||||
@app.post('/settings/toggle-notifs')
|
||||
@require_login
|
||||
def toggle_notifs(user=None):
|
||||
"""Toggles DM notifications for a given account.
|
||||
|
||||
Args:
|
||||
user (models.User)
|
||||
"""
|
||||
if user.send_notifs == 'all':
|
||||
user.send_notifs = 'none'
|
||||
verb = 'disabled'
|
||||
else:
|
||||
user.send_notifs = 'all'
|
||||
verb = 'enabled'
|
||||
|
||||
user.put()
|
||||
|
||||
flash(f'DM notifications {verb} for {user.handle_or_id()}.')
|
||||
return redirect('/settings', code=302)
|
||||
|
||||
|
||||
@app.get(f'/<any({",".join(PROTOCOLS)}):protocol>/<id>')
|
||||
# WARNING: this overrides the /ap/... actor URL route in activitypub.py, *only*
|
||||
# for handles with leading @ character. be careful when changing this route!
|
||||
|
|
|
@ -17,7 +17,7 @@
|
|||
</div>
|
||||
|
||||
<div class="row">
|
||||
{% if user.enabled_protocols and not user.status %}
|
||||
{% if user.enabled_protocols and not user.status %} {# Bridging: on #}
|
||||
<span id="{{ user.handle }}-switch-disabled-notice" class="disabled-notice"></span>
|
||||
<a href="{{ user.user_page_path() }}">Bridging: </a>
|
||||
<!-- to {{ user.enabled_protocols|join(', ') }} -->
|
||||
|
@ -46,7 +46,27 @@
|
|||
</p>
|
||||
{% endif %}
|
||||
|
||||
{% else %}
|
||||
<!-- TODO: uncomment when we launch DM notifs
|
||||
<p>
|
||||
<form method="post" action="/settings/toggle-notifs">
|
||||
<input name="key" type="hidden" value="{{ user.key.urlsafe().decode() }}" />
|
||||
DM notifications from unbridged accounts:
|
||||
|
||||
<label class="switch" id="{{ user.handle }}-notifs-wrapper">
|
||||
<input id="{{ user.handle }}-switch" type="checkbox"
|
||||
onClick="event.currentTarget.closest('form').submit()"
|
||||
{% if user.send_notifs == 'all' %}checked{% endif %} />
|
||||
<span class="slider round"></span>
|
||||
</label>
|
||||
<noscript>
|
||||
<input type="submit" class="btn btn-default"
|
||||
value="{{ 'Enable' if user.send_notifs == 'none' else 'Disable' }}" />
|
||||
</noscript>
|
||||
</form>
|
||||
</p>
|
||||
-->
|
||||
|
||||
{% else %} {# Bridging: off #}
|
||||
<label id="{{ user.handle }}-switch-disabled-notice" class="disabled-notice"></label>
|
||||
Bridging:
|
||||
<form method="post" action="/settings/enable">
|
||||
|
|
|
@ -912,6 +912,36 @@ class PagesTest(TestCase):
|
|||
get_flashed_messages())
|
||||
self.assertEqual('yoozer', OtherFake.usernames['http://b.c/a'])
|
||||
|
||||
def test_toggle_notifs(self):
|
||||
user = self.make_user('http://b.c/a', cls=ActivityPub, send_notifs='none',
|
||||
obj_as2={'id': 'http://b.c/a', 'preferredUsername': 'a'})
|
||||
auth = MastodonAuth(id='@a@b.c', access_token_str='',
|
||||
user_json='{"uri":"http://b.c/a"}').put()
|
||||
|
||||
with self.client.session_transaction() as sess:
|
||||
sess[LOGINS_SESSION_KEY] = [('MastodonAuth', '@a@b.c')]
|
||||
|
||||
# toggle on
|
||||
resp = self.client.post('/settings/toggle-notifs', data={
|
||||
'key': user.key.urlsafe().decode(),
|
||||
})
|
||||
self.assertEqual(302, resp.status_code)
|
||||
self.assertEqual('/settings', resp.headers['Location'])
|
||||
self.assertEqual(['DM notifications enabled for @a@b.c.'],
|
||||
get_flashed_messages())
|
||||
self.assertEqual('all', user.key.get().send_notifs)
|
||||
|
||||
# toggle off
|
||||
resp = self.client.post('/settings/toggle-notifs', data={
|
||||
'key': user.key.urlsafe().decode(),
|
||||
})
|
||||
self.assertEqual(302, resp.status_code)
|
||||
self.assertEqual('/settings', resp.headers['Location'])
|
||||
self.assertEqual(['DM notifications enabled for @a@b.c.',
|
||||
'DM notifications disabled for @a@b.c.'],
|
||||
get_flashed_messages())
|
||||
self.assertEqual('none', user.key.get().send_notifs)
|
||||
|
||||
def test_memcache_evict(self):
|
||||
# key = Fake(id='fake:foo').put()
|
||||
self.user.key.get()
|
||||
|
|
Ładowanie…
Reference in New Issue