From 9c730f70897c0c4899e457008a6307d752875b4e Mon Sep 17 00:00:00 2001 From: linus Date: Sun, 8 Oct 2023 22:36:18 +0200 Subject: [PATCH] Added visibility setting for mastodon posts --- crosspost.py | 15 +++++++++++---- settings.py | 3 +++ 2 files changed, 14 insertions(+), 4 deletions(-) diff --git a/crosspost.py b/crosspost.py index 3e92316..e79756b 100644 --- a/crosspost.py +++ b/crosspost.py @@ -332,17 +332,24 @@ def toot(post, replyTo, images, doPost): writeLog("Uploading image " + filename) res = mastodon.media_post(filename) mediaIds.append(res.id) + # Visibility is set to whatever is set in the settings file. If that is hybrid, it sets the visibility either to public or unlisted depending on + # if it is a reply in a thread or not. + visibility = settings.mastodonVisibility + if visibility == "hybrid" and replyTo: + visibility = "unlisted" + elif visibility == "hybrid": + visibility = "public" # I wanted to make this part a little neater, but didn't get it to work and gave up. So here we are. # If post is both reply and has images it is posted as both a reply and with images (duh). # If just either of the two it is posted with just that, and if neither it is just posted as a text post. if replyTo and mediaIds: - a = mastodon.status_post(post, in_reply_to_id=replyTo, media_ids=mediaIds) + a = mastodon.status_post(post, in_reply_to_id=replyTo, media_ids=mediaIds, visibility=visibility) elif replyTo: - a = mastodon.status_post(post, in_reply_to_id=replyTo, visibility="unlisted") + a = mastodon.status_post(post, in_reply_to_id=replyTo, visibility=visibility) elif mediaIds: - a = mastodon.status_post(post, media_ids=mediaIds, visibility="unlisted") + a = mastodon.status_post(post, media_ids=mediaIds, visibility=visibility) else: - a = mastodon.status_post(post, visibility="unlisted") + a = mastodon.status_post(post, visibility=visibility) writeLog("Posted to mastodon") id = a["id"] return id diff --git a/settings.py b/settings.py index 77bec07..8e0b81e 100644 --- a/settings.py +++ b/settings.py @@ -28,6 +28,9 @@ maxRetries = 5 # Sets max time limit (in hours) for fetching posts. If no database exists, all posts within this time # period will be posted. postTimeLimit = 12 +# mastodonVisibility sets what visibility should be used when posting to Mastodon. Options are "public" for always public, "unlisted" for always unlisted, +# "private" for always private and "hybrid" for all posts public except responses in threads (meaning first post in a thread is public and the rest unlisted). +mastodonVisibility = "hybrid" # Override settings with environment variables if they exist Twitter = os.environ.get('TWITTER_CROSSPOSTING').lower() == 'true' if os.environ.get('TWITTER_CROSSPOSTING') else Twitter