chiark / gitweb /
Ability to [un]favourite posts.
authorSimon Tatham <anakin@pobox.com>
Fri, 8 Dec 2023 07:07:29 +0000 (07:07 +0000)
committerSimon Tatham <anakin@pobox.com>
Fri, 8 Dec 2023 07:07:29 +0000 (07:07 +0000)
I had a conversation yesterday about how I should use that button
more, so I guess my personal client needs to have the functionality!

cursesclient.py

index 2e2890341e2da0de133e081970517cc0f1c4e5b5..51871350915fa70b76c2b634d9fe9125b00233ae 100644 (file)
@@ -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