From: Simon Tatham Date: Fri, 8 Dec 2023 07:07:29 +0000 (+0000) Subject: Ability to [un]favourite posts. X-Git-Url: https://www.chiark.greenend.org.uk/ucgi/~ian/git?a=commitdiff_plain;h=654b7d84f4d35019d03d107311922fe48c0d4087;p=mastodonochrome.git Ability to [un]favourite posts. I had a conversation yesterday about how I should use that button more, so I guess my personal client needs to have the functionality! --- diff --git a/cursesclient.py b/cursesclient.py index 2e28903..5187135 100644 --- a/cursesclient.py +++ b/cursesclient.py @@ -425,6 +425,8 @@ class File(Activity): return 'quit' elif ch in {'s', 'S'}: self.send_mode() + elif ch in {'f', 'F'}: + self.favourite_mode() elif self.mode == 'select': if ch in {'q', 'Q'}: self.mode = 'normal' @@ -435,9 +437,17 @@ class File(Activity): elif (self.select_type == 'send' and ch in {' ', 'i', 'I', 'a', 'A', 'l', 'L'}): self.send_complete() + elif (self.select_type == 'favourite' and + ch in {'e', 'E', ' '}): + self.favourite_complete(+1) + elif (self.select_type == 'favourite' and + ch in {'d', 'D'}): + self.favourite_complete(-1) def send_mode(self): pass # not supported + def favourite_mode(self): + pass # not supported class ObjectFile(File): def __init__(self, cc, constructor, feed, title): @@ -523,6 +533,9 @@ class ObjectFile(File): if self.mode == 'select': if self.select_type == 'send': sl.keys.append(('SPACE', 'Reply')) + elif self.select_type == 'favourite': + sl.keys.append(('SPACE', 'Fave')) + sl.keys.append(('D', 'Unfave')) sl.keys.append(('-', None)) sl.keys.append(('+', None)) sl.keys.append(('Q', 'Quit')) @@ -540,6 +553,10 @@ class ObjectFile(File): self.mode = 'select' self.select_type = 'send' self.select_target = self.index_by_line[self.linepos-1] + def favourite_mode(self): + self.mode = 'select' + self.select_type = 'favourite' + self.select_target = self.index_by_line[self.linepos-1] def prev_select_target(self): self.select_target = max(self.minpos, self.select_target-1) def next_select_target(self): @@ -572,6 +589,11 @@ class ObjectFile(File): self.push_to(self.cc.new_composer( initial_content, reply_header, reply_id)) + def favourite_complete(self, direction): + self.mode = 'normal' + reply_id = self.statuses[self.select_target].get_reply_id() + verb = "favourite" if direction > 0 else "unfavourite" + self.cc.post(f"statuses/{reply_id}/{verb}") def move_to(self, pos): old_linepos = self.linepos