mirror of
https://github.com/ihabunek/toot.git
synced 2025-06-30 22:18:36 -04:00
Add --json option to notifications
This commit is contained in:
parent
e960267b70
commit
4b88b86b6f
@ -697,9 +697,9 @@ def verify_credentials(app, user) -> Response:
|
||||
return http.get(app, user, '/api/v1/accounts/verify_credentials')
|
||||
|
||||
|
||||
def get_notifications(app, user, types=[], exclude_types=[], limit=20):
|
||||
def get_notifications(app, user, types=[], exclude_types=[], limit=20) -> Response:
|
||||
params = {"types[]": types, "exclude_types[]": exclude_types, "limit": limit}
|
||||
return http.get(app, user, '/api/v1/notifications', params).json()
|
||||
return http.get(app, user, '/api/v1/notifications', params)
|
||||
|
||||
|
||||
def clear_notifications(app, user):
|
||||
|
@ -2,12 +2,12 @@ import sys
|
||||
import click
|
||||
|
||||
from toot import api
|
||||
from toot.cli import InstanceParamType, cli, get_context, pass_context, Context
|
||||
from toot.cli import InstanceParamType, cli, get_context, pass_context, Context, json_option
|
||||
from typing import Optional
|
||||
from toot.cli.validators import validate_instance
|
||||
|
||||
from toot.entities import Notification, Status, from_dict
|
||||
from toot.output import print_notifications, print_timeline
|
||||
from toot.output import print_notifications, print_timeline, print_warning
|
||||
|
||||
|
||||
@cli.command()
|
||||
@ -123,12 +123,14 @@ def bookmarks(
|
||||
"--mentions", "-m", is_flag=True,
|
||||
help="Show only mentions"
|
||||
)
|
||||
@json_option
|
||||
@pass_context
|
||||
def notifications(
|
||||
ctx: Context,
|
||||
clear: bool,
|
||||
reverse: bool,
|
||||
mentions: int,
|
||||
mentions: bool,
|
||||
json: bool,
|
||||
):
|
||||
"""Show notifications"""
|
||||
if clear:
|
||||
@ -142,17 +144,22 @@ def notifications(
|
||||
# https://docs.joinmastodon.org/methods/notifications/
|
||||
exclude = ["follow", "favourite", "reblog", "poll", "follow_request"]
|
||||
|
||||
notifications = api.get_notifications(ctx.app, ctx.user, exclude_types=exclude)
|
||||
response = api.get_notifications(ctx.app, ctx.user, exclude_types=exclude)
|
||||
|
||||
if not notifications:
|
||||
click.echo("You have no notifications")
|
||||
if json:
|
||||
if reverse:
|
||||
print_warning("--reverse is not supported alongside --json, ignoring")
|
||||
click.echo(response.text)
|
||||
return
|
||||
|
||||
notifications = [from_dict(Notification, n) for n in response.json()]
|
||||
if reverse:
|
||||
notifications = reversed(notifications)
|
||||
|
||||
notifications = [from_dict(Notification, n) for n in notifications]
|
||||
print_notifications(notifications)
|
||||
if notifications:
|
||||
print_notifications(notifications)
|
||||
else:
|
||||
click.echo("You have no notifications")
|
||||
|
||||
|
||||
def _show_timeline(generator, reverse, once):
|
||||
|
@ -281,7 +281,7 @@ def print_notification(notification: Notification):
|
||||
print_status(notification.status)
|
||||
|
||||
|
||||
def print_notifications(notifications: t.List[Notification]):
|
||||
def print_notifications(notifications: t.Iterable[Notification]):
|
||||
for notification in notifications:
|
||||
if notification.type not in ["pleroma:emoji_reaction"]:
|
||||
print_divider()
|
||||
|
Loading…
x
Reference in New Issue
Block a user