Commit Diff


commit - b5ebf4c73102fa0f823ff1c0eaad49c387aeb3a5
commit + 3601f1e9b8cf6ad43170a5a87b4254efd32ac30d
blob - 843f5dd7dfffa7f84b7d37c64ec19bfef628b0fe
blob + 4c889b567270a0ca3d25d70848322816751150e0
--- lonk.py
+++ lonk.py
@@ -229,12 +229,15 @@ def _create_schema(db_con):
                 convoy TEXT,
                 client_id INTEGER,
                 honk_id INTEGER,
-                honker TEXT,
+                handle TEXT,
+                oondle TEXT,
                 url TEXT,
                 html TEXT,
                 date TEXT,
                 public INTEGER,
                 handles TEXT,
+                honker_url TEXT,
+                oonker_url TEXT,
                 FOREIGN KEY (client_id) REFERENCES client (client_id),
                 UNIQUE (convoy, client_id),
                 UNIQUE (honk_id, client_id)
@@ -259,6 +262,19 @@ def _create_schema(db_con):
     db_con.execute(
         """
         CREATE TABLE
+            xonker (
+                xonker_id INTEGER PRIMARY KEY,
+                client_id INTEGER,
+                convoy_id INTEGER,
+                url TEXT NOT NULL,
+                FOREIGN KEY (client_id) REFERENCES client (client_id),
+                FOREIGN KEY (convoy_id) REFERENCES convoy (convoy_id)
+            )
+        """
+    )
+    db_con.execute(
+        """
+        CREATE TABLE
             meta (
                 db_schema_version INTEGER
             )
@@ -279,34 +295,36 @@ def db_connect():
 
 
 class _LonkTreeItem:
-    def __init__(self, convoy_id, convoy, honk_id, honker, url, html, date, public, handles):
+    def __init__(self, convoy_id, convoy, honk_id, handle, oondle, url, html, date, public, handles, honker, oonker):
         self.convoy_id = convoy_id
         self.convoy = convoy
         self.honk_id = honk_id
-        self.honker = honker
+        self.handle = handle
+        self.oondle = oondle
         self.url = url
         self.html = html
         self.date = date
         self.public = bool(public)
         self.handles = handles
+        self.honker = honker
+        self.oonker = oonker
         self.donks = []
-        self.reposters = []
         self.thread = []
 
     def iterate_honks(self):
         if self.html is not None:
-            handle = self.honker
-            if self.reposters:
-                handle += " (🔁 " + ", ".join(reason for reason in set(self.reposters)) + ")"
             yield {
                 "Convoy": self.convoy,
-                "Handle": handle,
+                "Handle": self.handle,
+                "Oondle": self.oondle,
                 "ID": self.honk_id,
                 "XID": self.url,
                 "HTML": self.html,
                 "Date": self.date,
                 "Public": self.public,
                 "Handles": self.handles,
+                "Honker": self.honker,
+                "Oonker": self.oonker,
                 "Donks": [
                     {"URL": donk[0], "Media": donk[1], "Desc": donk[2]}
                     for donk in self.donks
@@ -326,7 +344,14 @@ def page_lonk(db_con, client_id, lonk_url, honk_url):
 
         if convoy not in lonk_page:
             row = db_con.execute(
-                "SELECT convoy_id, convoy, honk_id, honker, url, html, date, public, handles FROM convoy WHERE client_id=? AND convoy=?",
+                """
+                SELECT
+                    convoy_id, convoy, honk_id, handle, oondle, url, html, date, public, handles, honker_url, oonker_url
+                FROM 
+                    convoy 
+                WHERE 
+                    client_id=? AND convoy=?
+                """,
                 (client_id, convoy)
             ).fetchone()
             if row:
@@ -345,23 +370,20 @@ def page_lonk(db_con, client_id, lonk_url, honk_url):
                         lonk_page[convoy].donks.append((donk_url, donk_mime, donk_text))
 
         if convoy not in lonk_page:
-            def _save_convoy(convoy, honker, honk):
+            def _save_convoy(convoy, honk):
                 is_public = 1 if honk.get("Public") else 0
                 row = db_con.execute(
                     """
                     INSERT INTO 
-                        convoy(convoy, client_id, honk_id, honker, url, html, date, public, handles)
+                        convoy(convoy, client_id, honk_id, handle, oondle, url, html, date, public, handles, honker_url, oonker_url)
                     VALUES 
-                        (?, ?, ?, ?, ?, ?, ?, ?, ?)
+                        (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)
                     RETURNING
-                        convoy_id
+                        convoy_id, convoy, honk_id, handle, oondle, url, html, date, public, handles, honker_url, oonker_url
                     """,
-                    (convoy, client_id, honk["ID"], honker, honk["XID"], honk["HTML"], honk["Date"], is_public, honk["Handles"])
+                    (convoy, client_id, honk["ID"], honk["Handle"], honk.get("Oondle"), honk["XID"], honk["HTML"], honk["Date"], is_public, honk["Handles"], honk.get("Honker"), honk.get("Oonker"))
                 ).fetchone()
-                convoy_id, = row
-                lonk_page[convoy] = _LonkTreeItem(
-                    convoy_id, convoy, honk["ID"], honker, honk["XID"], honk["HTML"], honk["Date"], is_public, honk["Handles"]
-                )
+                lonk_page[convoy] = _LonkTreeItem(*row)
 
                 for donk in (honk.get("Donks") or []):
                     donk_url = honk_url.build_url(path=f'/d/{donk["XID"]}') if donk.get("XID") else donk["URL"]
@@ -375,16 +397,13 @@ def page_lonk(db_con, client_id, lonk_url, honk_url):
             if honk.get("RID"):
                 for honk_in_convoy in honk_url.do_get("gethonks", page="convoy", c=convoy)["honks"]:
                     if not honk_in_convoy.get("RID"):
-                        honker = honk_in_convoy.get("Oondle") or honk_in_convoy["Handle"]
-                        _save_convoy(convoy, honker, honk_in_convoy)
+                        _save_convoy(convoy, honk_in_convoy)
                         break
                 else:
-                    _save_convoy(convoy, None, {"ID": None, "XID": None, "HTML": None, "Date": None, "Handles": None})
+                    _save_convoy(convoy, {"ID": None, "Handle": None, "XID": None, "HTML": None, "Date": None, "Handles": None})
             else:
-                _save_convoy(convoy, honk.get("Oondle") or honk["Handle"], honk)
+                _save_convoy(convoy, honk)
 
-        if honk.get("What") == "bonked":
-            lonk_page[convoy].reposters.append(honk["Handle"])
         if honk.get("RID"):
             lonk_page[convoy].thread.append(honk)
 
@@ -405,11 +424,6 @@ def page_convoy(db_con, client_id, lonk_url, honk_url)
         return
 
     gethonks_answer = honk_url.do_get("gethonks", page="convoy", c=query["c"])
-    gethonks_answer["honks"] = [
-        honk
-        for honk in (gethonks_answer.pop("honks", None) or [])
-        if honk.get("What") != "bonked"
-    ]
     print("20 text/gemini\r")
     print(f"# 𝓗 onk: convoy {query['c']}\r")
     print("\r")
@@ -445,6 +459,27 @@ def page_longago(db_con, client_id, lonk_url, honk_url
     print_gethonks(gethonks_answer, lonk_url, honk_url)
 
 
+def page_myhonks(db_con, client_id, lonk_url, honk_url):
+    gethonks_answer = honk_url.do_get("gethonks", page="myhonks")
+    print("20 text/gemini\r")
+    print("# 𝓗 onk: my honks")
+    print("\r")
+    print_gethonks(gethonks_answer, lonk_url, honk_url)
+
+
+def page_honker(db_con, client_id, lonk_url, honk_url):
+    xid = {pair[0]: pair[1] for pair in parse_qsl(lonk_url.query)}.get("xid")
+    if not xid:
+        print("51 Not found\r")
+        return
+
+    gethonks_answer = honk_url.do_get("gethonks", page="honker", xid=xid)
+    print("20 text/gemini\r")
+    print(f"# 𝓗 onk: honks of {xid}\r")
+    print("\r")
+    print_gethonks(gethonks_answer, lonk_url, honk_url)
+
+
 def print_gethonks(gethonks_answer, lonk_url, honk_url):
 
     def _menu():
@@ -464,19 +499,19 @@ def print_gethonks(gethonks_answer, lonk_url, honk_url
         print(f"=> {honk_url.build_url(path='honkers')} honkers\r")
         print(f"=> {lonk_url.build('search')} search\r")
         print(f"=> {lonk_url.build('longago')} long ago\r")
+        print(f"=> {lonk_url.build('myhonks')} my honks\r")
 
     _menu()
     print("\r")
     print("\r")
 
     for honk in gethonks_answer.get("honks") or []:
-        if honk.get("What") == "bonked":
-            continue
-
         convoy = honk["Convoy"]
         re_url = honk.get("RID")
+        oondle = honk.get("Oondle")
+        from_ = f'{oondle} (🔁 {honk["Handle"]})' if oondle else f'{honk["Handle"]}'
         lines = [
-            f'##{"# ↱" if re_url else ""} From {honk["Handle"]} {honk["Date"]}',
+            f'##{"# ↱" if re_url else ""} From {from_} {honk["Date"]}',
             f'=> {lonk_url.build("convoy", urlencode({"c": convoy}))} Convoy {convoy}',
             f'=> {honk["XID"]}',
         ]
@@ -494,6 +529,9 @@ def print_gethonks(gethonks_answer, lonk_url, honk_url
         if honk.get("Public"):
             lines.append(f'=> {lonk_url.build("bonk", urlencode({"w": honk["XID"]}))} ↺ bonk')
         lines.append(f'=> {honk_url.build_url(path="newhonk", query=urlencode({"rid": honk["XID"]}))} ↱ honk back')
+        for xonker in (honk.get("Honker"), honk.get("Oonker")):
+            if xonker:
+                lines.append(f'=> {lonk_url.build("honker", urlencode({"xid": xonker}))} honks of {xonker}')
         print("\r\n".join(lines))
         print("\r")
 
@@ -555,7 +593,7 @@ def bonk(db_con, client_id, lonk_url, honk_url):
         return
 
     bonk_answer = honk_url.do_get("zonkit",  wherefore="bonk", what=what, answer_is_json=False)
-    print(f'30 {lonk_url.build([])}\r')
+    print(f'30 {lonk_url.build("myhonks")}\r')
 
 
 def authenticated(cert_hash, lonk_url, fn_impl):
@@ -591,6 +629,10 @@ def vgi(cert_hash, raw_url):
         authenticated(cert_hash, lonk_url, page_search)
     elif lonk_url.page == "longago":
         authenticated(cert_hash, lonk_url, page_longago)
+    elif lonk_url.page == "myhonks":
+        authenticated(cert_hash, lonk_url, page_myhonks)
+    elif lonk_url.page == "honker":
+        authenticated(cert_hash, lonk_url, page_honker)
     elif lonk_url.page == "bonk":
         authenticated(cert_hash, lonk_url, bonk)
     elif lonk_url.page == "ask_server":