[PATCH tooi] TimelineTab: support boosting and favouriting
Export this patch
Add keybinds for F and B to toggle favourite and reblog on a status.
Currently this doesn't update the displayed status; that requires more
work to allow updating existing statuses in a more general way.
---
tooi/api/statuses.py | 20 ++++++++++++++++++++
tooi/messages.py | 9 +++++++++
tooi/tabs/timeline.py | 42 ++++++++++++++++++++++++++++++++++++++++--
3 files changed, 69 insertions(+), 2 deletions(-)
diff --git a/tooi/api/statuses.py b/tooi/api/statuses.py
index 2c2abf6..218bdb1 100644
--- a/tooi/api/statuses.py
+++ b/tooi/api/statuses.py
@@ -44,3 +44,23 @@ async def post(
def drop_empty_values(data: Dict[Any, Any]) -> Dict[Any, Any]:
"""Remove keys whose values are null"""
return {k: v for k, v in data.items() if v is not None}
+
+
+async def set_favourite(status_id: str):
+ path = f"/api/v1/statuses/{status_id}/favourite"
+ await request("POST", path)
+
+
+async def unset_favourite(status_id: str):
+ path = f"/api/v1/statuses/{status_id}/unfavourite"
+ await request("POST", path)
+
+
+async def boost(status_id: str):
+ path = f"/api/v1/statuses/{status_id}/reblog"
+ await request("POST", path)
+
+
+async def unboost(status_id: str):
+ path = f"/api/v1/statuses/{status_id}/unreblog"
+ await request("POST", path)
diff --git a/tooi/messages.py b/tooi/messages.py
index 8e2750c..d9dc809 100644
--- a/tooi/messages.py
+++ b/tooi/messages.py
@@ -57,6 +57,14 @@ class ShowHashtagPicker(Message):
pass
+class ToggleStatusFavourite(StatusMessage):
+ pass
+
+
+class ToggleStatusBoost(StatusMessage):
+ pass
+
+
class GotoHashtagTimeline(Message):
def __init__(self, hashtag: str) -> None:
super().__init__()
@@ -82,6 +90,7 @@ class ShowStatusMenu(StatusMessage):
class StatusReply(StatusMessage):
pass
+
class ShowStatusMessage(Message):
def __init__(self, text: str | None = None):
super().__init__()
diff --git a/tooi/tabs/timeline.py b/tooi/tabs/timeline.py
index 183ca44..759010b 100644
--- a/tooi/tabs/timeline.py
+++ b/tooi/tabs/timeline.py
@@ -5,11 +5,13 @@ from textual.containers import Horizontal
from textual.widgets import TabPane
from tooi.data.events import Event, StatusEvent, MentionEvent
+from tooi.api.statuses import set_favourite, unset_favourite, boost, unboost
from tooi.api.timeline import Timeline
from tooi.context import get_context
from tooi.data.instance import InstanceInfo
-from tooi.messages import ShowAccount, ShowSource, ShowStatusMenu, ShowThread
+from tooi.messages import ShowAccount, ShowSource, ShowStatusMenu, ShowThread, ToggleStatusFavourite
from tooi.messages import EventHighlighted, EventSelected, StatusReply, ShowStatusMessage
+from tooi.messages import ToggleStatusBoost
from tooi.widgets.status_detail import StatusDetail
from tooi.widgets.event_detail import make_event_detail, EventDetailPlaceholder
from tooi.widgets.event_list import EventList
@@ -25,6 +27,8 @@ class TimelineTab(TabPane):
Binding("u", "show_source", "Source"),
Binding("t", "show_thread", "Thread"),
Binding("r", "status_reply", "Reply"),
+ Binding("f", "status_favourite", "(Un)Favourite"),
+ Binding("b", "status_boost", "(Un)Boost"),
Binding("left,h", "scroll_left", "Scroll Left", show=False),
Binding("right,l", "scroll_right", "Scroll Right", show=False),
Binding("s", "show_sensitive", "Show Sensitive", show=False),
@@ -85,7 +89,7 @@ class TimelineTab(TabPane):
newevents = []
- self.post_message(ShowStatusMessage(f"[green]Updating timeline...[/]"))
+ self.post_message(ShowStatusMessage("[green]Updating timeline...[/]"))
try:
async for eventslist in self.timeline.update():
@@ -127,6 +131,40 @@ class TimelineTab(TabPane):
def on_status_selected(self, message: EventSelected):
self.post_message(ShowStatusMenu(message.status))
+ async def on_toggle_status_favourite(self, message: ToggleStatusFavourite):
+ original = message.status.original
+ if original.favourited:
+ await unset_favourite(original.id)
+ else:
+ await set_favourite(original.id)
+
+ def action_status_favourite(self):
+ if event := self.event_list.current:
+ match event:
+ case MentionEvent():
+ self.post_message(ToggleStatusFavourite(event.status))
+ case StatusEvent():
+ self.post_message(ToggleStatusFavourite(event.status))
+ case _:
+ pass
+
+ async def on_toggle_status_boost(self, message: ToggleStatusBoost):
+ original = message.status.original
+ if original.reblogged:
+ await unboost(original.id)
+ else:
+ await boost(original.id)
+
+ def action_status_boost(self):
+ if event := self.event_list.current:
+ match event:
+ case MentionEvent():
+ self.post_message(ToggleStatusBoost(event.status))
+ case StatusEvent():
+ self.post_message(ToggleStatusBoost(event.status))
+ case _:
+ pass
+
def action_show_sensitive(self):
if isinstance(self.event_detail, StatusDetail) and self.event_detail.sensitive:
self.event_detail.reveal()
--
2.43.0