1
0
mirror of https://github.com/ihabunek/toot synced 2024-12-25 00:20:55 +01:00

Add basic support for Mastodon Lists

Fixes issue #255
This commit is contained in:
Dan Schwarz 2023-03-13 20:50:43 -04:00 committed by Ivan Habunek
parent 040427884b
commit 6bcd43a6ae
No known key found for this signature in database
GPG Key ID: CDBD63C43A30BB95
2 changed files with 34 additions and 6 deletions

View File

@ -398,7 +398,9 @@ class TUI(urwid.Frame):
def show_goto_menu(self):
user_timelines = self.config.get("timelines", {})
menu = GotoMenu(user_timelines)
user_lists = api.get_lists(self.app, self.user) or []
menu = GotoMenu(user_timelines, user_lists)
urwid.connect_signal(menu, "home_timeline",
lambda x: self.goto_home_timeline())
urwid.connect_signal(menu, "public_timeline",
@ -411,10 +413,12 @@ class TUI(urwid.Frame):
lambda x, local: self.goto_conversations())
urwid.connect_signal(menu, "hashtag_timeline",
lambda x, tag, local: self.goto_tag_timeline(tag, local=local))
urwid.connect_signal(menu, "list_timeline",
lambda x, list_item: self.goto_list_timeline(list_item))
self.open_overlay(menu, title="Go to", options=dict(
align="center", width=("relative", 60),
valign="middle", height=16 + len(user_timelines),
valign="middle", height=17 + len(user_timelines) + len(user_lists),
))
def show_help(self):
@ -468,6 +472,13 @@ class TUI(urwid.Frame):
)
promise.add_done_callback(lambda *args: self.close_overlay())
def goto_list_timeline(self, list_item):
self.timeline_generator = api.timeline_list_generator(
self.app, self.user, list_item['id'], limit=40)
promise = self.async_load_timeline(
is_initial=True, timeline_name=f"\N{clipboard}{list_item['title']}")
promise.add_done_callback(lambda *args: self.close_overlay())
def show_media(self, status):
urls = [m["url"] for m in status.original.data["media_attachments"]]
if urls:
@ -660,12 +671,19 @@ class TUI(urwid.Frame):
def refresh_timeline(self):
# No point in refreshing the bookmarks timeline
if not self.timeline or self.timeline.name == 'bookmarks':
# and we don't have a good way to refresh a
# list timeline yet (no reference to list ID kept)
if (not self.timeline
or self.timeline.name == 'bookmarks'
or self.timeline.name.startswith("\N{clipboard}")):
return
if self.timeline.name.startswith("#"):
self.timeline_generator = api.tag_timeline_generator(
self.app, self.user, self.timeline.name[1:], limit=40)
elif self.timeline.name.startswith("\N{clipboard}"):
self.timeline_generator = api.tag_timeline_generator(
self.app, self.user, self.timeline.name[1:], limit=40)
else:
if self.timeline.name.endswith("public"):
self.timeline_generator = api.public_timeline_generator(

View File

@ -102,20 +102,21 @@ class GotoMenu(urwid.ListBox):
"bookmark_timeline",
"notification_timeline",
"conversation_timeline",
"list_timeline",
]
def __init__(self, user_timelines):
def __init__(self, user_timelines, user_lists):
self.hash_edit = EditBox(caption="Hashtag: ")
self.message_widget = urwid.Text("")
actions = list(self.generate_actions(user_timelines))
actions = list(self.generate_actions(user_timelines, user_lists))
walker = urwid.SimpleFocusListWalker(actions)
super().__init__(walker)
def get_hashtag(self):
return self.hash_edit.edit_text.strip().lstrip("#")
def generate_actions(self, user_timelines):
def generate_actions(self, user_timelines, user_lists):
def _home(button):
self._emit("home_timeline")
@ -147,6 +148,11 @@ class GotoMenu(urwid.ListBox):
self._emit("hashtag_timeline", tag, local)
return on_press
def mk_on_press_user_list(list_item):
def on_press(btn):
self._emit("list_timeline", list_item)
return on_press
yield Button("Home timeline", on_press=_home)
yield Button("Local public timeline", on_press=_local_public)
yield Button("Global public timeline", on_press=_global_public)
@ -164,6 +170,10 @@ class GotoMenu(urwid.ListBox):
yield Button(f"#{tag}" + (" (local)" if is_local else ""),
on_press=mk_on_press_user_hashtag(tag, is_local))
for list_item in user_lists:
yield Button(f"\N{clipboard}{list_item['title']}",
on_press=mk_on_press_user_list(list_item))
yield urwid.Divider()
yield self.hash_edit
yield Button("Local hashtag timeline", on_press=lambda x: _hashtag(True))