From 22004ca84f838ec16ae43abc9ab2b185fef5bb2e Mon Sep 17 00:00:00 2001 From: clarkzjw Date: Thu, 23 Feb 2023 20:50:42 -0800 Subject: fix mastodon.py missing in status.update() --- callback.py | 25 +++++++++++++++++++++---- 1 file changed, 21 insertions(+), 4 deletions(-) (limited to 'callback.py') diff --git a/callback.py b/callback.py index ecce2bf..1abef5e 100644 --- a/callback.py +++ b/callback.py @@ -57,6 +57,11 @@ async def process_media_group(context: CallbackContext): mastodon_client = get_mastodon_client(context.user_data["user_id"]) media_id = [] chat_id = context.job.data[0].get("chat_id") + + 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" + for media_dict in context.job.data: if len(media_id) >= 4: await context.bot.send_message(chat_id=chat_id, text=PROMPT_MAX_PHOTO_REACHED, reply_markup=MAIN_MENU) @@ -69,6 +74,7 @@ async def process_media_group(context: CallbackContext): mastodon_client.status_update(id=media_dict.get("status_id"), status=media_dict.get("content"), + content_type=content_type, media_ids=media_id) await context.bot.send_message(chat_id=chat_id, text=PROMPT_DONE, reply_markup=MAIN_MENU) @@ -118,8 +124,6 @@ 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"]) - # TODO - # mastodon.py status_update() currently does not support content_type parameter 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" @@ -262,9 +266,14 @@ async def callback_add_comment(update: Update, context: ContextTypes.DEFAULT_TYP context.user_data["user_id"] = update.effective_user.id await context.bot.delete_message(update.effective_chat.id, context.user_data.get(PROMPT_ADD_COMMENT)) + 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" + comment = update.effective_message.text get_mastodon_client(update.effective_user.id).status_update(id=context.user_data.get(KEY_TOOT_STATUS_ID), - status=f"{comment} " + context.user_data.get( + content_type=content_type, + status=f"{comment}\n\n" + context.user_data.get( KEY_TOOT_STATUS_CONTENT)) context.user_data[KEY_TOOT_STATUS_CONTENT] = f"{comment} " + context.user_data.get(KEY_TOOT_STATUS_CONTENT) @@ -317,7 +326,15 @@ async def callback_add_media(update: Update, context: CallbackContext): media = mastodon_client.media_post(img, description=message.caption_html, mime_type="image/jpeg") - mastodon_client.status_update(status=status_content, id=status_id, media_ids=media["id"]) + + 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" + + mastodon_client.status_update(status=status_content, + id=status_id, + content_type=content_type, + media_ids=media["id"]) await update.message.reply_text(text=PROMPT_DONE, reply_markup=MAIN_MENU) -- cgit v1.2.3