chiark / gitweb /
Show boosted toots sensibly.
authorSimon Tatham <anakin@pobox.com>
Sat, 2 Dec 2023 17:28:02 +0000 (17:28 +0000)
committerSimon Tatham <anakin@pobox.com>
Sat, 2 Dec 2023 17:28:02 +0000 (17:28 +0000)
client.py
text.py

index 5cec035eda671239d71a0b2cfcde728c363ff080..fae611c2309cd0305401d3c7ab0c084d05bc92ec 100644 (file)
--- a/client.py
+++ b/client.py
@@ -76,6 +76,13 @@ class Client:
 
 class Status:
     def __init__(self, data):
+        rb = data.get('reblog')
+        if rb is not None:
+            self.booster = data['account']
+            data = rb
+        else:
+            self.booster = None
+
         self.post_id = data['id']
 
         date, suffix = data['created_at'].split(".", 1)
@@ -95,6 +102,9 @@ class Status:
         yield text.SeparatorLine(self.datestamp)
         yield text.FromLine('@' + self.account['acct'],
                             self.account['display_name'])
+        if self.booster is not None:
+            yield text.BoosterLine('@' + self.booster['acct'],
+                                   self.booster['display_name'])
         yield text.BlankLine()
         yield from self.content
         yield text.BlankLine()
diff --git a/text.py b/text.py
index 7dc8905c187aa18d5c0ae42f0f36dcf8b5b73ebd..dfa17eb469cbd60e7f3db11143ec4a175c09e438 100644 (file)
--- a/text.py
+++ b/text.py
@@ -16,6 +16,7 @@ colourmap = {
     'S': [0, 1, 7, 44, 37],
     'D': [0, 7, 44, 37],
     'F': [0, 1, 32],
+    'f': [0, 32],
     'c': [0, 33],
     '#': [0, 36],
     '@': [0, 32],
@@ -99,15 +100,23 @@ class SeparatorLine:
                   ColouredString("]--", 'S'))
         yield ColouredString("-", 'S') * (width - 1 - suffix.width) + suffix
 
-class FromLine:
+class UsernameHeader:
     def __init__(self, account, nameline):
         self.account = account
         self.nameline = nameline
 
     def render(self, width):
         # FIXME: truncate
-        yield (ColouredString("From: ") +
-               ColouredString(f"{self.nameline} ({self.account})", 'F'))
+        yield (ColouredString(self.header + ": ") +
+               ColouredString(f"{self.nameline} ({self.account})",
+                              self.colour))
+
+class FromLine(UsernameHeader):
+    header = "From"
+    colour = "F"
+class BoosterLine(UsernameHeader):
+    header = "Via"
+    colour = "f"
 
 class Paragraph:
     def __init__(self):