From 41d96249ba7c64fcf36544b2c16e9d83c13f47ec Mon Sep 17 00:00:00 2001 From: Denis Laxalde Date: Wed, 13 Feb 2019 21:05:23 +0100 Subject: [PATCH 1/2] Add favourite/unfavourite actions to curses ui --- toot/ui/app.py | 25 +++++++++++++++++++++++++ toot/ui/parsers.py | 1 + 2 files changed, 26 insertions(+) diff --git a/toot/ui/app.py b/toot/ui/app.py index 1f7ca55..701ab36 100644 --- a/toot/ui/app.py +++ b/toot/ui/app.py @@ -294,6 +294,7 @@ class HelpModal(Modal): " k or ↑ - move up", " v - view current toot in browser", " b - toggle boost status", + " f - toggle favourite status", " q - quit application", " s - show sensitive content" "", @@ -371,6 +372,9 @@ class TimelineApp: elif key.lower() == 'b': self.toggle_reblog() + elif key.lower() == 'f': + self.toggle_favourite() + elif key == 'KEY_RESIZE': self.setup_windows() self.full_redraw() @@ -403,6 +407,27 @@ class TimelineApp: self.right.draw(status) + def toggle_favourite(self): + """Favourite or unfavourite selected status.""" + status = self.get_selected_status() + assert status + app, user = self.app, self.user + if not app or not user: + self.footer.draw_message("You must be logged in to favourite", Color.RED) + return + status_id = status['id'] + if status['favourited']: + self.footer.draw_message("Undoing favourite status...", Color.YELLOW) + api.unfavourite(app, user, status_id) + self.footer.draw_message("✓ Status unfavourited", Color.GREEN) + else: + self.footer.draw_message("Favourite status...", Color.YELLOW) + api.favourite(app, user, status_id) + self.footer.draw_message("✓ Status favourited", Color.GREEN) + status['favourited'] = not status['favourited'] + + self.right.draw(status) + def select_previous(self): """Move to the previous status in the timeline.""" self.footer.clear_message() diff --git a/toot/ui/parsers.py b/toot/ui/parsers.py index e9d7a45..7db4595 100644 --- a/toot/ui/parsers.py +++ b/toot/ui/parsers.py @@ -15,6 +15,7 @@ def parse_status(status): 'boosted_by': boosted_by, 'created_at': created_at, 'content': content, + 'favourited': status.get('favourited'), 'id': status['id'], 'media_attachments': _status['media_attachments'], 'url': _status['url'], From 3d0c7be1e051ff5c4938d2cd43dd1cb0268871ca Mon Sep 17 00:00:00 2001 From: Denis Laxalde Date: Thu, 14 Feb 2019 20:39:58 +0100 Subject: [PATCH 2/2] Indicate if status has been favorited in left pane of curses ui Showing a yellow star in the right corner of second line. --- toot/ui/app.py | 3 +++ 1 file changed, 3 insertions(+) diff --git a/toot/ui/app.py b/toot/ui/app.py index 701ab36..9658e72 100644 --- a/toot/ui/app.py +++ b/toot/ui/app.py @@ -134,6 +134,9 @@ class StatusListWindow: self.pad.addstr(offset + 1, 1, " " + date.ljust(12), color) self.pad.addstr(offset + 2, 1, " " + time.ljust(12), color) + if status['favourited']: + self.pad.addstr(offset + 2, width - 3, '⭐', Color.YELLOW) + if draw_divider: draw_horizontal_divider(self.pad, offset + 3)