From a9fb6f252553ae49a2ba372434073824babe31e4 Mon Sep 17 00:00:00 2001 From: clarkzjw Date: Thu, 23 Feb 2023 21:46:27 -0800 Subject: bot: support changing default toot visibility --- callback.py | 21 ++++++++++----------- 1 file changed, 10 insertions(+), 11 deletions(-) (limited to 'callback.py') diff --git a/callback.py b/callback.py index 1abef5e..cb6a8d3 100644 --- a/callback.py +++ b/callback.py @@ -60,7 +60,7 @@ async def process_media_group(context: CallbackContext): with db.connection_context(): u = User.get(User.telegram_user_id == context.user_data["user_id"]) - content_type = "text/markdown" if u.home_instance_type == "pleroma" else "text/plain" + content_type = "text/markdown" if u.home_instance_type == "pleroma" else None for media_dict in context.job.data: if len(media_id) >= 4: @@ -124,11 +124,11 @@ async def callback_location_sharing(update: Update, context: ContextTypes.DEFAUL poi = query_poi_by_fsq_id(context.user_data.get("fsq_id")) content = generate_toot_text(poi["name"], poi["locality"], poi["region"], poi["latitude"], poi["longitude"]) - with db.connection_context(): - u = User.get(User.telegram_user_id == update.effective_user.id) - content_type = "text/markdown" if u.home_instance_type == "pleroma" else "text/plain" + u = get_user_by_id(str(update.effective_user.id)) + content_type = "text/markdown" if u["home_instance_type"] == "pleroma" else None + status = get_mastodon_client(update.effective_user.id).status_post(content, - visibility=TOOT_VISIBILITY_PRIVATE, + visibility=u["tool_visibility"], content_type=content_type, media_ids=[]) @@ -208,12 +208,11 @@ async def _process_location_selection(context: ContextTypes.DEFAULT_TYPE) -> int content = generate_toot_text(poi_name, "", "", context.user_data.get("latitude"), context.user_data.get("longitude")) - with db.connection_context(): - u = User.get(User.telegram_user_id == context.user_data["user_id"]) - content_type = "text/markdown" if u.home_instance_type == "pleroma" else "text/plain" + u = get_user_by_id(context.user_data["user_id"]) + content_type = "text/markdown" if u["home_instance_type"] == "pleroma" else None status = get_mastodon_client(context.user_data["user_id"]).status_post(content, - visibility=TOOT_VISIBILITY_PRIVATE, + visibility=u["toot_visibility"], content_type=content_type, media_ids=[]) @@ -268,7 +267,7 @@ async def callback_add_comment(update: Update, context: ContextTypes.DEFAULT_TYP with db.connection_context(): u = User.get(User.telegram_user_id == context.user_data["user_id"]) - content_type = "text/markdown" if u.home_instance_type == "pleroma" else "text/plain" + content_type = "text/markdown" if u.home_instance_type == "pleroma" else None comment = update.effective_message.text get_mastodon_client(update.effective_user.id).status_update(id=context.user_data.get(KEY_TOOT_STATUS_ID), @@ -329,7 +328,7 @@ async def callback_add_media(update: Update, context: CallbackContext): with db.connection_context(): u = User.get(User.telegram_user_id == context.user_data["user_id"]) - content_type = "text/markdown" if u.home_instance_type == "pleroma" else "text/plain" + content_type = "text/markdown" if u.home_instance_type == "pleroma" else None mastodon_client.status_update(status=status_content, id=status_id, -- cgit v1.2.3