diff --git a/toot/api.py b/toot/api.py index 3f10c37..84d5de1 100644 --- a/toot/api.py +++ b/toot/api.py @@ -287,6 +287,18 @@ def _timeline_generator(app, user, path, params=None): path = _get_next_path(response.headers) +def _notif_timeline_generator(app, user, path, params=None): + while path: + response = http.get(app, user, path, params) + notification = response.json() + statuses = [] + for n in notification: + if n['status']: + statuses.append(n['status']) + yield statuses + path = _get_next_path(response.headers) + + def home_timeline_generator(app, user, limit=20): path = "/api/v1/timelines/home" params = {"limit": limit} @@ -311,6 +323,13 @@ def bookmark_timeline_generator(app, user, limit=20): return _timeline_generator(app, user, path, params) +def notification_timeline_generator(app, user, limit=20): + # exclude all but mentions and statuses + exclude_types = ["follow", "favourite", "reblog", "poll", "follow_request"] + params = {"exclude_types[]": exclude_types, "limit": limit} + return _notif_timeline_generator(app, user, '/api/v1/notifications', params) + + def timeline_list_generator(app, user, list_id, limit=20): path = f"/api/v1/timelines/list/{list_id}" return _timeline_generator(app, user, path, {'limit': limit}) diff --git a/toot/tui/app.py b/toot/tui/app.py index 1b8fbf1..aa4f52e 100644 --- a/toot/tui/app.py +++ b/toot/tui/app.py @@ -438,13 +438,14 @@ class TUI(urwid.Frame): lambda x, local: self.goto_public_timeline(local)) urwid.connect_signal(menu, "bookmark_timeline", lambda x, local: self.goto_bookmarks()) - + urwid.connect_signal(menu, "notification_timeline", + lambda x, local: self.goto_notifications()) urwid.connect_signal(menu, "hashtag_timeline", lambda x, tag, local: self.goto_tag_timeline(tag, local=local)) self.open_overlay(menu, title="Go to", options=dict( align="center", width=("relative", 60), - valign="middle", height=10 + len(user_timelines), + valign="middle", height=11 + len(user_timelines), )) def show_help(self): @@ -474,6 +475,12 @@ class TUI(urwid.Frame): promise = self.async_load_timeline(is_initial=True, timeline_name="bookmarks") promise.add_done_callback(lambda *args: self.close_overlay()) + def goto_notifications(self): + self.timeline_generator = api.notification_timeline_generator( + self.app, self.user, limit=40) + promise = self.async_load_timeline(is_initial=True, timeline_name="notifications") + promise.add_done_callback(lambda *args: self.close_overlay()) + def goto_tag_timeline(self, tag, local): self.timeline_generator = api.tag_timeline_generator( self.app, self.user, tag, local=local, limit=40) diff --git a/toot/tui/overlays.py b/toot/tui/overlays.py index df7085f..1e006c3 100644 --- a/toot/tui/overlays.py +++ b/toot/tui/overlays.py @@ -100,6 +100,7 @@ class GotoMenu(urwid.ListBox): "public_timeline", "hashtag_timeline", "bookmark_timeline", + "notification_timeline", ] def __init__(self, user_timelines): @@ -125,6 +126,9 @@ class GotoMenu(urwid.ListBox): def _bookmarks(button): self._emit("bookmark_timeline", False) + def _notifications(button): + self._emit("notification_timeline", False) + def _hashtag(local): hashtag = self.get_hashtag() if hashtag: @@ -147,6 +151,7 @@ class GotoMenu(urwid.ListBox): yield Button("Local public timeline", on_press=_local_public) yield Button("Global public timeline", on_press=_global_public) yield Button("Bookmarks", on_press=_bookmarks) + yield Button("Notifications", on_press=_notifications) yield urwid.Divider() yield self.hash_edit yield Button("Local hashtag timeline", on_press=lambda x: _hashtag(True))