Merge pull request #330 from rogarb/conversations

Add conversations support in TUI
pull/327/head^2
Ivan Habunek 2023-03-05 11:34:18 +01:00 zatwierdzone przez GitHub
commit 04beac87ed
Nie znaleziono w bazie danych klucza dla tego podpisu
ID klucza GPG: 4AEE18F83AFDEB23
3 zmienionych plików z 30 dodań i 0 usunięć

Wyświetl plik

@ -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})

Wyświetl plik

@ -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)

Wyświetl plik

@ -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))