diff --git a/toot/api.py b/toot/api.py index 910b3b5..3bb2c89 100644 --- a/toot/api.py +++ b/toot/api.py @@ -293,6 +293,14 @@ def _notification_timeline_generator(app, user, path, params=None): path = _get_next_path(response.headers) +def _conversation_timeline_generator(app, user, path, params=None): + while path: + response = http.get(app, user, path, params) + conversation = response.json() + yield [c["last_status"] for c in conversation if c["last_status"]] + path = _get_next_path(response.headers) + + def home_timeline_generator(app, user, limit=20): path = "/api/v1/timelines/home" params = {"limit": limit} @@ -324,6 +332,12 @@ def notification_timeline_generator(app, user, limit=20): return _notification_timeline_generator(app, user, "/api/v1/notifications", params) +def conversation_timeline_generator(app, user, limit=20): + path = "/api/v1/conversations" + params = {"limit": limit} + return _conversation_timeline_generator(app, user, path, 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 aa4f52e..2ded137 100644 --- a/toot/tui/app.py +++ b/toot/tui/app.py @@ -440,6 +440,8 @@ class TUI(urwid.Frame): lambda x, local: self.goto_bookmarks()) urwid.connect_signal(menu, "notification_timeline", lambda x, local: self.goto_notifications()) + urwid.connect_signal(menu, "conversation_timeline", + lambda x, local: self.goto_conversations()) urwid.connect_signal(menu, "hashtag_timeline", lambda x, tag, local: self.goto_tag_timeline(tag, local=local)) @@ -481,6 +483,15 @@ class TUI(urwid.Frame): promise = self.async_load_timeline(is_initial=True, timeline_name="notifications") promise.add_done_callback(lambda *args: self.close_overlay()) + def goto_conversations(self): + self.timeline_generator = api.conversation_timeline_generator( + self.app, self.user, limit=40 + ) + promise = self.async_load_timeline( + is_initial=True, timeline_name="conversations" + ) + 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 d5f370a..51601da 100644 --- a/toot/tui/overlays.py +++ b/toot/tui/overlays.py @@ -101,6 +101,7 @@ class GotoMenu(urwid.ListBox): "hashtag_timeline", "bookmark_timeline", "notification_timeline", + "conversation_timeline", ] def __init__(self, user_timelines): @@ -129,6 +130,9 @@ class GotoMenu(urwid.ListBox): def _notifications(button): self._emit("notification_timeline", False) + def _conversations(button): + self._emit("conversation_timeline", False) + def _hashtag(local): hashtag = self.get_hashtag() if hashtag: @@ -152,6 +156,7 @@ class GotoMenu(urwid.ListBox): yield Button("Global public timeline", on_press=_global_public) yield Button("Bookmarks", on_press=_bookmarks) yield Button("Notifications", on_press=_notifications) + yield Button("Conversations", on_press=_conversations) yield urwid.Divider() yield self.hash_edit yield Button("Local hashtag timeline", on_press=lambda x: _hashtag(True))