From 2c9048618f34ef457af5fc53e3e7e23352d46089 Mon Sep 17 00:00:00 2001 From: Manuel Cortez Date: Sat, 12 Nov 2022 15:16:20 -0600 Subject: [PATCH] Added visibility as a variable template for toots --- src/mastodon.defaults | 2 +- src/sessions/mastodon/templates.py | 7 +++++-- 2 files changed, 6 insertions(+), 3 deletions(-) diff --git a/src/mastodon.defaults b/src/mastodon.defaults index fdc2a482..7705c05f 100644 --- a/src/mastodon.defaults +++ b/src/mastodon.defaults @@ -44,7 +44,7 @@ braille_reporting = boolean(default=True) speech_reporting = boolean(default=True) [templates] -toot = string(default="$display_name, $safe_text $image_descriptions $date. $source") +toot = string(default="$display_name, $safe_text $image_descriptions $date. $visibility. $source") person = string(default="$display_name (@$screen_name). $followers followers, $following following, $toots toots. Joined $created_at.") conversation = string(default="Conversation with $users. Last message: $last_toot") diff --git a/src/sessions/mastodon/templates.py b/src/sessions/mastodon/templates.py index c93036e2..549e8eca 100644 --- a/src/sessions/mastodon/templates.py +++ b/src/sessions/mastodon/templates.py @@ -9,7 +9,7 @@ from . import utils, compose # This will be used for the edit template dialog. # Available variables for toot objects. # safe_text will be the content warning in case a toot contains one, text will always be the full text, no matter if has a content warning or not. -toot_variables = ["date", "display_name", "screen_name", "source", "lang", "safe_text", "text", "image_descriptions"] +toot_variables = ["date", "display_name", "screen_name", "source", "lang", "safe_text", "text", "image_descriptions", "visibility"] person_variables = ["display_name", "screen_name", "description", "followers", "following", "favorites", "toots", "created_at"] conversation_variables = ["users", "last_toot"] @@ -59,6 +59,7 @@ def render_toot(toot, template, relative_times=False, offset_hours=0): $safe_text: Safe text to display. If a content warning is applied in toots, display those instead of the whole toot. $text: Toot text. This always displays the full text, even if there is a content warning present. $image_descriptions: Information regarding image descriptions added by twitter users. + $visibility: toot's visibility: public, not listed, followers only or direct. """ global toot_variables available_data = dict() @@ -79,7 +80,9 @@ def render_toot(toot, template, relative_times=False, offset_hours=0): else: text = process_text(toot, safe=False) safe_text = process_text(toot) - available_data.update(lang=toot.language, text=text, safe_text=safe_text) + visibility_settings = dict(public=_("Public"), unlisted=_("Not listed"), private=_("Followers only"), direct=_("Direct")) + visibility = visibility_settings.get(toot.visibility) + available_data.update(lang=toot.language, text=text, safe_text=safe_text, visibility=visibility) # process image descriptions image_descriptions = "" if toot.reblog != None: