Skip to content

Commit

Permalink
Add --type and --exclude-type options to notification
Browse files Browse the repository at this point in the history
  • Loading branch information
ihabunek committed Nov 14, 2024
1 parent 4b88b86 commit 20eec3b
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 8 deletions.
12 changes: 12 additions & 0 deletions toot/cli/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,18 @@
PRIVACY_CHOICES = ["public", "unlisted", "private"]
VISIBILITY_CHOICES = ["public", "unlisted", "private", "direct"]
IMAGE_FORMAT_CHOICES = ["block", "iterm", "kitty"]
NOTIFICATION_TYPE_CHOICES = [
"mention",
"status",
"reblog",
"follow",
"follow_request",
"favourite",
"poll",
"update",
"admin.sign_up",
"admin.report",
]
TUI_COLORS = {
"1": 1,
"16": 16,
Expand Down
28 changes: 20 additions & 8 deletions toot/cli/timelines.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@
import click

from toot import api
from toot.cli import InstanceParamType, cli, get_context, pass_context, Context, json_option
from typing import Optional
from toot.cli import NOTIFICATION_TYPE_CHOICES, InstanceParamType, cli, get_context, pass_context, Context, json_option
from typing import Optional, Tuple
from toot.cli.validators import validate_instance

from toot.entities import Notification, Status, from_dict
Expand Down Expand Up @@ -119,9 +119,21 @@ def bookmarks(
"--reverse", "-r", is_flag=True,
help="Reverse the order of the shown notifications (newest on top)"
)
@click.option(
"--type", "-t", "types",
type=click.Choice(NOTIFICATION_TYPE_CHOICES),
multiple=True,
help="Types to include in the result, can be specified multiple times"
)
@click.option(
"--exclude-type", "-e", "exclude_types",
type=click.Choice(NOTIFICATION_TYPE_CHOICES),
multiple=True,
help="Types to exclude in the result, can be specified multiple times"
)
@click.option(
"--mentions", "-m", is_flag=True,
help="Show only mentions"
help="Show only mentions (same as --type mention, overrides --type, DEPRECATED)"
)
@json_option
@pass_context
Expand All @@ -130,6 +142,8 @@ def notifications(
clear: bool,
reverse: bool,
mentions: bool,
types: Tuple[str],
exclude_types: Tuple[str],
json: bool,
):
"""Show notifications"""
Expand All @@ -138,13 +152,11 @@ def notifications(
click.secho("✓ Notifications cleared", fg="green")
return

exclude = []
if mentions:
# Filter everything except mentions
# https://docs.joinmastodon.org/methods/notifications/
exclude = ["follow", "favourite", "reblog", "poll", "follow_request"]
print_warning("`--mentions` option is deprecated in favour of `--type mentions`")
types = ("mention",)

response = api.get_notifications(ctx.app, ctx.user, exclude_types=exclude)
response = api.get_notifications(ctx.app, ctx.user, types=types, exclude_types=exclude_types)

if json:
if reverse:
Expand Down

0 comments on commit 20eec3b

Please # to comment.