diff --git a/src/void_tools/cli.py b/src/void_tools/cli.py index 1cb23c0..d657288 100644 --- a/src/void_tools/cli.py +++ b/src/void_tools/cli.py @@ -30,6 +30,33 @@ def cmd_sync(args): if hasattr(notif.record, 'text'): item["text"] = notif.record.text + # Fetch thread context for replies, quotes, or mentions + if notif.reason in ['reply', 'quote', 'mention']: + try: + # Depending on the notification type, we might need to look up the thread from the subject or the uri + thread_uri = notif.uri + if notif.reason == 'quote' and hasattr(notif.record, 'embed') and hasattr(notif.record.embed, 'record'): + # If we want the context of the quote, the uri is still the post itself, the parent trace handles the quote subject usually + pass + + thread_resp = client.app.bsky.feed.get_post_thread({'uri': thread_uri, 'depth': 0, 'parent_height': 5}) + + context = [] + # Traverse parents recursively + curr = thread_resp.thread + while hasattr(curr, 'parent') and curr.parent: + curr = curr.parent + if hasattr(curr, 'post') and hasattr(curr.post, 'record') and hasattr(curr.post.record, 'text'): + context.insert(0, { + "author": f"@{curr.post.author.handle}", + "text": curr.post.record.text + }) + + if context: + item["thread_context"] = context + except Exception as e: + item["thread_context"] = f"Failed to fetch context: {str(e)}" + inbox.append(item) mapping[local_id] = notif.uri