mirror of
https://github.com/ihabunek/toot.git
synced 2025-02-02 15:07:51 -05:00
Add a --clear option to "notifications" command
This commit is contained in:
parent
5174a751f2
commit
6360e4d07d
@ -546,6 +546,17 @@ def test_notifications(mock_get, capsys):
|
|||||||
])
|
])
|
||||||
|
|
||||||
|
|
||||||
|
@mock.patch('toot.http.post')
|
||||||
|
def test_notifications_clear(mock_post, capsys):
|
||||||
|
console.run_command(app, user, 'notifications', ['--clear'])
|
||||||
|
out, err = capsys.readouterr()
|
||||||
|
out = uncolorize(out)
|
||||||
|
|
||||||
|
mock_post.assert_called_once_with(app, user, '/api/v1/notifications/clear')
|
||||||
|
assert not err
|
||||||
|
assert out == 'Cleared notifications\n'
|
||||||
|
|
||||||
|
|
||||||
def u(user_id, access_token="abc"):
|
def u(user_id, access_token="abc"):
|
||||||
username, instance = user_id.split("@")
|
username, instance = user_id.split("@")
|
||||||
return {
|
return {
|
||||||
|
@ -260,6 +260,10 @@ def get_notifications(app, user):
|
|||||||
return http.get(app, user, '/api/v1/notifications').json()
|
return http.get(app, user, '/api/v1/notifications').json()
|
||||||
|
|
||||||
|
|
||||||
|
def clear_notifications(app, user):
|
||||||
|
http.post(app, user, '/api/v1/notifications/clear')
|
||||||
|
|
||||||
|
|
||||||
def get_instance(domain, scheme="https"):
|
def get_instance(domain, scheme="https"):
|
||||||
url = "{}://{}/api/v1/instance".format(scheme, domain)
|
url = "{}://{}/api/v1/instance".format(scheme, domain)
|
||||||
return http.anon_get(url).json()
|
return http.anon_get(url).json()
|
||||||
|
@ -299,6 +299,11 @@ def instance(app, user, args):
|
|||||||
|
|
||||||
|
|
||||||
def notifications(app, user, args):
|
def notifications(app, user, args):
|
||||||
|
if args.clear:
|
||||||
|
api.clear_notifications(app, user)
|
||||||
|
print_out("<green>Cleared notifications</green>")
|
||||||
|
return
|
||||||
|
|
||||||
width = 100
|
width = 100
|
||||||
for notification in sorted(api.get_notifications(app, user),
|
for notification in sorted(api.get_notifications(app, user),
|
||||||
key=lambda n: datetime.strptime(
|
key=lambda n: datetime.strptime(
|
||||||
|
@ -170,7 +170,13 @@ READ_COMMANDS = [
|
|||||||
Command(
|
Command(
|
||||||
name="notifications",
|
name="notifications",
|
||||||
description="Notifications for logged in user",
|
description="Notifications for logged in user",
|
||||||
arguments=[],
|
arguments=[
|
||||||
|
(["--clear"], {
|
||||||
|
"help": "delete all notifications from the server",
|
||||||
|
"action": 'store_true',
|
||||||
|
"default": False,
|
||||||
|
}),
|
||||||
|
],
|
||||||
require_auth=True,
|
require_auth=True,
|
||||||
),
|
),
|
||||||
Command(
|
Command(
|
||||||
|
Loading…
x
Reference in New Issue
Block a user