From a1490461bdad97d6ae63f116ac0e9b0e4b8785d4 Mon Sep 17 00:00:00 2001 From: Daniel Schwarz Date: Fri, 3 Feb 2023 21:28:18 -0500 Subject: [PATCH] Add relationship support to Account overlay Display relationship details such as followed_by, blocked_by, and add buttons to un/follow, un/mute, un/block. Buttons are nonfunctional for now --- toot/debugger.py | 12 ++++++++++++ toot/tui/app.py | 3 ++- toot/tui/overlays.py | 20 +++++++++++++++++--- 3 files changed, 31 insertions(+), 4 deletions(-) create mode 100644 toot/debugger.py diff --git a/toot/debugger.py b/toot/debugger.py new file mode 100644 index 0000000..ba4aee9 --- /dev/null +++ b/toot/debugger.py @@ -0,0 +1,12 @@ +from os import getenv + +def initialize_debugger(): + import multiprocessing + + if multiprocessing.current_process().pid > 1: + import debugpy + + debugpy.listen(("0.0.0.0", 9000)) + print("VSCode Debugger is ready to be attached on port 9000, press F5", flush=True) + debugpy.wait_for_client() + print("VSCode Debugger is now attached", flush=True) diff --git a/toot/tui/app.py b/toot/tui/app.py index 64c50c7..12b0473 100644 --- a/toot/tui/app.py +++ b/toot/tui/app.py @@ -521,8 +521,9 @@ class TUI(urwid.Frame): def show_account(self, account_id): account = api.whois(self.app, self.user, account_id) + relationship = api.get_relationship(self.app, self.user, account_id) self.open_overlay( - widget=Account(account), + widget=Account(account, relationship), title="Account", ) diff --git a/toot/tui/overlays.py b/toot/tui/overlays.py index de9dbe6..b91d30f 100644 --- a/toot/tui/overlays.py +++ b/toot/tui/overlays.py @@ -205,12 +205,20 @@ class Help(urwid.Padding): class Account(urwid.ListBox): """Shows account data and provides various actions""" - def __init__(self, account): - actions = list(self.generate_contents(account)) + def __init__(self, account, relationship): + actions = list(self.generate_contents(account, relationship)) walker = urwid.SimpleListWalker(actions) super().__init__(walker) - def generate_contents(self, account): + def generate_contents(self, account, relationship): + if relationship['requested']: + yield urwid.Text(("light grey", "< Follow request is pending >")) + else: + yield Button("Unfollow" if relationship['following'] else "Follow") + yield Button("Unmute" if relationship['muting'] else "Mute") + yield Button("Unblock" if relationship['blocking'] else "Block") + yield urwid.Divider("─") + yield urwid.Divider() yield urwid.Text([('green', f"@{account['acct']}"), f" {account['display_name']}"]) if account["note"]: @@ -232,6 +240,12 @@ class Account(urwid.ListBox): if "suspended" in account and account["suspended"]: yield urwid.Text([("warning", "Suspended \N{cross mark}")]) yield urwid.Divider() + if relationship["followed_by"]: + yield urwid.Text(("green", "Follows you \N{busts in silhouette}")) + yield urwid.Divider() + if relationship["blocked_by"]: + yield urwid.Text(("warning", "Blocks you \N{no entry}")) + yield urwid.Divider() yield urwid.Text(["Followers: ", ("yellow", f"{account['followers_count']}")]) yield urwid.Text(["Following: ", ("yellow", f"{account['following_count']}")])