~ihabunek/toot-discuss

Add TOOT_VISIBILITY for default & boost visibility v1 APPLIED

This patch introduces the TOOT_VISIBILITY environment variable, which sets the default visibility value. This affects:

- CLI post (can be overriden by switch)
- CLI reblog (ditto)
- TUI post (can be overriden in TUI)
- TUI reblog (no override yet)

Feel free to change to a more modern config thingy. `~/.config/toot/toot.yml` maybe?

Lim Ding Wen (2):
  TOOT_VISIBILITY controls default visibility
  TOOT_VISIBILITY controls boost visibility

 toot/api.py         | 8 ++++----
 toot/commands.py    | 2 +-
 toot/console.py     | 9 +++++++--
 toot/tui/app.py     | 3 ++-
 toot/tui/compose.py | 3 ++-
 5 files changed, 16 insertions(+), 9 deletions(-)

-- 
2.32.1 (Apple Git-133)
I changed the name to TOOT_POST_VISIBILITY. In the future I plan to support
overriding any commandline option by settings TOOT_<command>_<option>
variable so this change makes it compatible with future plans.

-- Ivan
Export patchset (mbox)
How do I use this?

Copy & paste the following snippet into your terminal to import this patchset into git:

curl -s https://lists.sr.ht/~ihabunek/toot-discuss/patches/37688/mbox | git am -3
Learn more about email & git

[PATCH 1/2] TOOT_VISIBILITY controls default visibility Export this patch

---
 toot/console.py     | 2 +-
 toot/tui/compose.py | 3 ++-
 2 files changed, 3 insertions(+), 2 deletions(-)

diff --git a/toot/console.py b/toot/console.py
index dbb681a..663aab5 100644
--- a/toot/console.py
+++ b/toot/console.py
@@ -348,7 +348,7 @@ POST_COMMANDS = [
            }),
            (["-v", "--visibility"], {
                "type": visibility,
                "default": "public",
                "default": os.getenv("TOOT_VISIBILITY", "public"),
                "help": 'post visibility, one of: %s' % ", ".join(VISIBILITY_CHOICES),
            }),
            (["-s", "--sensitive"], {
diff --git a/toot/tui/compose.py b/toot/tui/compose.py
index 68228b1..4b29958 100644
--- a/toot/tui/compose.py
+++ b/toot/tui/compose.py
@@ -1,5 +1,6 @@
import urwid
import logging
import os

from .constants import VISIBILITY_OPTIONS
from .widgets import Button, EditBox
@@ -30,7 +31,7 @@ class StatusComposer(urwid.Frame):
        self.cw_remove_button = Button("Remove content warning",
            on_press=self.remove_content_warning)

        self.visibility = "public"
        self.visibility = os.getenv("TOOT_VISIBILITY", "public")
        self.visibility_button = Button("Visibility: {}".format(self.visibility),
            on_press=self.choose_visibility)

-- 
2.32.1 (Apple Git-133)

[PATCH 2/2] TOOT_VISIBILITY controls boost visibility Export this patch

TOOT_VISIBILITY controls default boost visibility from CLI, and the boost visibility from TUI (no option to change in TUI yet)
---
 toot/api.py      | 8 ++++----
 toot/commands.py | 2 +-
 toot/console.py  | 7 ++++++-
 toot/tui/app.py  | 3 ++-
 4 files changed, 13 insertions(+), 7 deletions(-)

diff --git a/toot/api.py b/toot/api.py
index 1ce1ec0..a54de0f 100644
--- a/toot/api.py
+++ b/toot/api.py
@@ -18,10 +18,10 @@ def _account_action(app, user, account, action):
    return http.post(app, user, url).json()


def _status_action(app, user, status_id, action):
def _status_action(app, user, status_id, action, data=None):
    url = '/api/v1/statuses/{}/{}'.format(status_id, action)

    return http.post(app, user, url).json()
    return http.post(app, user, url, data=data).json()


def create_app(domain, scheme='https'):
@@ -187,8 +187,8 @@ def unfavourite(app, user, status_id):
    return _status_action(app, user, status_id, 'unfavourite')


def reblog(app, user, status_id):
    return _status_action(app, user, status_id, 'reblog')
def reblog(app, user, status_id, visibility="public"):
    return _status_action(app, user, status_id, 'reblog', data={"visibility": visibility})


def unreblog(app, user, status_id):
diff --git a/toot/commands.py b/toot/commands.py
index 5cbde45..120c964 100644
--- a/toot/commands.py
+++ b/toot/commands.py
@@ -169,7 +169,7 @@ def unfavourite(app, user, args):


def reblog(app, user, args):
    api.reblog(app, user, args.status_id)
    api.reblog(app, user, args.status_id, visibility=args.visibility)
    print_out("<green>✓ Status reblogged</green>")


diff --git a/toot/console.py b/toot/console.py
index 663aab5..51c1d5e 100644
--- a/toot/console.py
+++ b/toot/console.py
@@ -434,7 +434,12 @@ STATUS_COMMANDS = [
    Command(
        name="reblog",
        description="Reblog a status",
        arguments=[status_id_arg],
        arguments=[status_id_arg,
            (["-v", "--visibility"], {
                "type": visibility,
                "default": os.getenv("TOOT_VISIBILITY", "public"),
                "help": 'boost visibility, one of: %s' % ", ".join(VISIBILITY_CHOICES),
            })],
        require_auth=True,
    ),
    Command(
diff --git a/toot/tui/app.py b/toot/tui/app.py
index 037506e..4293f0c 100644
--- a/toot/tui/app.py
+++ b/toot/tui/app.py
@@ -1,5 +1,6 @@
import logging
import urwid
import os

from concurrent.futures import ThreadPoolExecutor

@@ -484,7 +485,7 @@ class TUI(urwid.Frame):
    def async_toggle_reblog(self, timeline, status):
        def _reblog():
            logger.info("Reblogging {}".format(status))
            api.reblog(self.app, self.user, status.id)
            api.reblog(self.app, self.user, status.id, visibility=os.getenv("TOOT_VISIBILITY", "public"))

        def _unreblog():
            logger.info("Unreblogging {}".format(status))
-- 
2.32.1 (Apple Git-133)