mirror of
https://github.com/ihabunek/toot
synced 2025-02-09 08:38:39 +01:00
Add bookmark timeline and bookmarking to tui
This commit is contained in:
parent
ded7a0c50d
commit
fed5574939
@ -260,6 +260,12 @@ def tag_timeline_generator(app, user, hashtag, local=False, limit=20):
|
|||||||
return _timeline_generator(app, user, path, params)
|
return _timeline_generator(app, user, path, params)
|
||||||
|
|
||||||
|
|
||||||
|
def bookmark_timeline_generator(app, user, limit=20):
|
||||||
|
path = '/api/v1/bookmarks'
|
||||||
|
params = {'limit': limit}
|
||||||
|
return _timeline_generator(app, user, path, params)
|
||||||
|
|
||||||
|
|
||||||
def timeline_list_generator(app, user, list_id, limit=20):
|
def timeline_list_generator(app, user, list_id, limit=20):
|
||||||
path = '/api/v1/timelines/list/{}'.format(list_id)
|
path = '/api/v1/timelines/list/{}'.format(list_id)
|
||||||
return _timeline_generator(app, user, path, {'limit': limit})
|
return _timeline_generator(app, user, path, {'limit': limit})
|
||||||
|
@ -196,6 +196,7 @@ class TUI(urwid.Frame):
|
|||||||
def _zoom(timeline, status_details):
|
def _zoom(timeline, status_details):
|
||||||
self.show_status_zoom(status_details)
|
self.show_status_zoom(status_details)
|
||||||
|
|
||||||
|
urwid.connect_signal(timeline, "bookmark", self.async_toggle_bookmark)
|
||||||
urwid.connect_signal(timeline, "compose", _compose)
|
urwid.connect_signal(timeline, "compose", _compose)
|
||||||
urwid.connect_signal(timeline, "delete", _delete)
|
urwid.connect_signal(timeline, "delete", _delete)
|
||||||
urwid.connect_signal(timeline, "favourite", self.async_toggle_favourite)
|
urwid.connect_signal(timeline, "favourite", self.async_toggle_favourite)
|
||||||
@ -390,12 +391,15 @@ class TUI(urwid.Frame):
|
|||||||
lambda x: self.goto_home_timeline())
|
lambda x: self.goto_home_timeline())
|
||||||
urwid.connect_signal(menu, "public_timeline",
|
urwid.connect_signal(menu, "public_timeline",
|
||||||
lambda x, local: self.goto_public_timeline(local))
|
lambda x, local: self.goto_public_timeline(local))
|
||||||
|
urwid.connect_signal(menu, "bookmark_timeline",
|
||||||
|
lambda x, local: self.goto_bookmarks())
|
||||||
|
|
||||||
urwid.connect_signal(menu, "hashtag_timeline",
|
urwid.connect_signal(menu, "hashtag_timeline",
|
||||||
lambda x, tag, local: self.goto_tag_timeline(tag, local=local))
|
lambda x, tag, local: self.goto_tag_timeline(tag, local=local))
|
||||||
|
|
||||||
self.open_overlay(menu, title="Go to", options=dict(
|
self.open_overlay(menu, title="Go to", options=dict(
|
||||||
align="center", width=("relative", 60),
|
align="center", width=("relative", 60),
|
||||||
valign="middle", height=9 + len(user_timelines),
|
valign="middle", height=10 + len(user_timelines),
|
||||||
))
|
))
|
||||||
|
|
||||||
def show_help(self):
|
def show_help(self):
|
||||||
@ -413,6 +417,12 @@ class TUI(urwid.Frame):
|
|||||||
promise = self.async_load_timeline(is_initial=True, timeline_name="public")
|
promise = self.async_load_timeline(is_initial=True, timeline_name="public")
|
||||||
promise.add_done_callback(lambda *args: self.close_overlay())
|
promise.add_done_callback(lambda *args: self.close_overlay())
|
||||||
|
|
||||||
|
def goto_bookmarks(self):
|
||||||
|
self.timeline_generator = api.bookmark_timeline_generator(
|
||||||
|
self.app, self.user, limit=40)
|
||||||
|
promise = self.async_load_timeline(is_initial=True, timeline_name="bookmarks")
|
||||||
|
promise.add_done_callback(lambda *args: self.close_overlay())
|
||||||
|
|
||||||
def goto_tag_timeline(self, tag, local):
|
def goto_tag_timeline(self, tag, local):
|
||||||
self.timeline_generator = api.tag_timeline_generator(
|
self.timeline_generator = api.tag_timeline_generator(
|
||||||
self.app, self.user, tag, local=local, limit=40)
|
self.app, self.user, tag, local=local, limit=40)
|
||||||
@ -542,6 +552,27 @@ class TUI(urwid.Frame):
|
|||||||
else:
|
else:
|
||||||
self.run_in_thread(_translate, done_callback=_done)
|
self.run_in_thread(_translate, done_callback=_done)
|
||||||
|
|
||||||
|
def async_toggle_bookmark(self, timeline, status):
|
||||||
|
def _bookmark():
|
||||||
|
logger.info("Bookmarking {}".format(status))
|
||||||
|
api.bookmark(self.app, self.user, status.id)
|
||||||
|
|
||||||
|
def _unbookmark():
|
||||||
|
logger.info("Unbookmarking {}".format(status))
|
||||||
|
api.unbookmark(self.app, self.user, status.id)
|
||||||
|
|
||||||
|
def _done(loop):
|
||||||
|
# Create a new Status with flipped bookmarked flag
|
||||||
|
new_data = status.data
|
||||||
|
new_data["bookmarked"] = not status.bookmarked
|
||||||
|
new_status = self.make_status(new_data)
|
||||||
|
timeline.update_status(new_status)
|
||||||
|
|
||||||
|
self.run_in_thread(
|
||||||
|
_unbookmark if status.bookmarked else _bookmark,
|
||||||
|
done_callback=_done
|
||||||
|
)
|
||||||
|
|
||||||
def async_delete_status(self, timeline, status):
|
def async_delete_status(self, timeline, status):
|
||||||
def _delete():
|
def _delete():
|
||||||
api.delete_status(self.app, self.user, status.id)
|
api.delete_status(self.app, self.user, status.id)
|
||||||
|
@ -34,6 +34,7 @@ PALETTE = [
|
|||||||
('green_selected', 'white,bold', 'dark green'),
|
('green_selected', 'white,bold', 'dark green'),
|
||||||
('yellow', 'yellow', ''),
|
('yellow', 'yellow', ''),
|
||||||
('yellow_bold', 'yellow,bold', ''),
|
('yellow_bold', 'yellow,bold', ''),
|
||||||
|
('red', 'dark red', ''),
|
||||||
('warning', 'light red', ''),
|
('warning', 'light red', ''),
|
||||||
]
|
]
|
||||||
|
|
||||||
|
@ -56,6 +56,7 @@ class Status:
|
|||||||
self.author = self._get_author()
|
self.author = self._get_author()
|
||||||
self.favourited = data.get("favourited", False)
|
self.favourited = data.get("favourited", False)
|
||||||
self.reblogged = data.get("reblogged", False)
|
self.reblogged = data.get("reblogged", False)
|
||||||
|
self.bookmarked = data.get("bookmarked", False)
|
||||||
self.in_reply_to = data.get("in_reply_to_id")
|
self.in_reply_to = data.get("in_reply_to_id")
|
||||||
self.url = data.get("url")
|
self.url = data.get("url")
|
||||||
self.mentions = data.get("mentions")
|
self.mentions = data.get("mentions")
|
||||||
|
@ -45,7 +45,7 @@ class StatusLinks(urwid.ListBox):
|
|||||||
class ExceptionStackTrace(urwid.ListBox):
|
class ExceptionStackTrace(urwid.ListBox):
|
||||||
"""Shows an exception stack trace."""
|
"""Shows an exception stack trace."""
|
||||||
def __init__(self, ex):
|
def __init__(self, ex):
|
||||||
lines = traceback.format_exception(etype=type(ex), value=ex, tb=ex.__traceback__)
|
lines = traceback.format_exception(type(ex), value=ex, tb=ex.__traceback__)
|
||||||
walker = urwid.SimpleFocusListWalker([
|
walker = urwid.SimpleFocusListWalker([
|
||||||
urwid.Text(line) for line in lines
|
urwid.Text(line) for line in lines
|
||||||
])
|
])
|
||||||
@ -74,6 +74,7 @@ class GotoMenu(urwid.ListBox):
|
|||||||
"home_timeline",
|
"home_timeline",
|
||||||
"public_timeline",
|
"public_timeline",
|
||||||
"hashtag_timeline",
|
"hashtag_timeline",
|
||||||
|
"bookmark_timeline",
|
||||||
]
|
]
|
||||||
|
|
||||||
def __init__(self, user_timelines):
|
def __init__(self, user_timelines):
|
||||||
@ -96,6 +97,9 @@ class GotoMenu(urwid.ListBox):
|
|||||||
def _global_public(button):
|
def _global_public(button):
|
||||||
self._emit("public_timeline", False)
|
self._emit("public_timeline", False)
|
||||||
|
|
||||||
|
def _bookmarks(button):
|
||||||
|
self._emit("bookmark_timeline", False)
|
||||||
|
|
||||||
def _hashtag(local):
|
def _hashtag(local):
|
||||||
hashtag = self.get_hashtag()
|
hashtag = self.get_hashtag()
|
||||||
if hashtag:
|
if hashtag:
|
||||||
@ -117,6 +121,7 @@ class GotoMenu(urwid.ListBox):
|
|||||||
|
|
||||||
yield Button("Local public timeline", on_press=_local_public)
|
yield Button("Local public timeline", on_press=_local_public)
|
||||||
yield Button("Global public timeline", on_press=_global_public)
|
yield Button("Global public timeline", on_press=_global_public)
|
||||||
|
yield Button("Bookmarks", on_press=_bookmarks)
|
||||||
yield urwid.Divider()
|
yield urwid.Divider()
|
||||||
yield self.hash_edit
|
yield self.hash_edit
|
||||||
yield Button("Local hashtag timeline", on_press=lambda x: _hashtag(True))
|
yield Button("Local hashtag timeline", on_press=lambda x: _hashtag(True))
|
||||||
@ -164,6 +169,7 @@ class Help(urwid.Padding):
|
|||||||
yield urwid.Text(h(" [B] - Boost/unboost status"))
|
yield urwid.Text(h(" [B] - Boost/unboost status"))
|
||||||
yield urwid.Text(h(" [C] - Compose new status"))
|
yield urwid.Text(h(" [C] - Compose new status"))
|
||||||
yield urwid.Text(h(" [F] - Favourite/unfavourite status"))
|
yield urwid.Text(h(" [F] - Favourite/unfavourite status"))
|
||||||
|
yield urwid.Text(h(" [K] - Bookmark/unbookmark status"))
|
||||||
yield urwid.Text(h(" [N] - Translate status if possible (toggle)"))
|
yield urwid.Text(h(" [N] - Translate status if possible (toggle)"))
|
||||||
yield urwid.Text(h(" [R] - Reply to current status"))
|
yield urwid.Text(h(" [R] - Reply to current status"))
|
||||||
yield urwid.Text(h(" [S] - Show text marked as sensitive"))
|
yield urwid.Text(h(" [S] - Show text marked as sensitive"))
|
||||||
|
@ -21,6 +21,7 @@ class Timeline(urwid.Columns):
|
|||||||
"delete", # Delete own status
|
"delete", # Delete own status
|
||||||
"favourite", # Favourite status
|
"favourite", # Favourite status
|
||||||
"focus", # Focus changed
|
"focus", # Focus changed
|
||||||
|
"bookmark", # Bookmark status
|
||||||
"media", # Display media attachments
|
"media", # Display media attachments
|
||||||
"menu", # Show a context menu
|
"menu", # Show a context menu
|
||||||
"next", # Fetch more statuses
|
"next", # Fetch more statuses
|
||||||
@ -67,6 +68,7 @@ class Timeline(urwid.Columns):
|
|||||||
"green": "green_selected",
|
"green": "green_selected",
|
||||||
"yellow": "green_selected",
|
"yellow": "green_selected",
|
||||||
"cyan": "green_selected",
|
"cyan": "green_selected",
|
||||||
|
"red": "green_selected",
|
||||||
None: "green_selected",
|
None: "green_selected",
|
||||||
})
|
})
|
||||||
|
|
||||||
@ -156,6 +158,10 @@ class Timeline(urwid.Columns):
|
|||||||
self.refresh_status_details()
|
self.refresh_status_details()
|
||||||
return
|
return
|
||||||
|
|
||||||
|
if key in ("k", "K"):
|
||||||
|
self._emit("bookmark", status)
|
||||||
|
return
|
||||||
|
|
||||||
if key in ("l", "L"):
|
if key in ("l", "L"):
|
||||||
self._emit("links", status)
|
self._emit("links", status)
|
||||||
return
|
return
|
||||||
@ -308,6 +314,7 @@ class StatusDetails(urwid.Pile):
|
|||||||
)
|
)
|
||||||
|
|
||||||
yield ("pack", urwid.Text([
|
yield ("pack", urwid.Text([
|
||||||
|
("red" if status.bookmarked else "gray", "🠷" if status.bookmarked else " "),
|
||||||
("gray", f"⤶ {status.data['replies_count']} "),
|
("gray", f"⤶ {status.data['replies_count']} "),
|
||||||
("yellow" if status.reblogged else "gray", f"♺ {status.data['reblogs_count']} "),
|
("yellow" if status.reblogged else "gray", f"♺ {status.data['reblogs_count']} "),
|
||||||
("yellow" if status.favourited else "gray", f"★ {status.data['favourites_count']}"),
|
("yellow" if status.favourited else "gray", f"★ {status.data['favourites_count']}"),
|
||||||
@ -322,6 +329,7 @@ class StatusDetails(urwid.Pile):
|
|||||||
"[B]oost",
|
"[B]oost",
|
||||||
"[D]elete" if status.is_mine else "",
|
"[D]elete" if status.is_mine else "",
|
||||||
"[F]avourite",
|
"[F]avourite",
|
||||||
|
"Boo[k]mark",
|
||||||
"[V]iew",
|
"[V]iew",
|
||||||
"[T]hread" if not self.in_thread else "",
|
"[T]hread" if not self.in_thread else "",
|
||||||
"[L]inks",
|
"[L]inks",
|
||||||
|
Loading…
x
Reference in New Issue
Block a user