Revert "fix(posts): split copy_text and callback_data into separate buttons per Bot API spec"

This reverts commit b96bffda37.
This commit is contained in:
admin committed 2026-10-30 14:52:27 +02:00
1 parent b96bffda37
commit 3a6cc1067f
3 files changed
+6 -18

No files matched your search

+1 -1
View File
@@ -1 +1 @@
0.1.0+87
0.1.0+86
+2 -12
View File
@@ -103,22 +103,12 @@ def subscription_plans_keyboard() -> InlineKeyboardMarkup:
def post_copy_keyboard(post_text: str, post_index: int) -> InlineKeyboardMarkup:
"""Кнопка копирования поста.
По доке Bot API (InlineKeyboardButton): «Exactly one of the fields other than
text/icon_custom_emoji_id/style must be used» — copy_text и callback_data в одной
кнопке не работают: Telegram трактует такую кнопку как callback-кнопку и копирование
не происходит. Поэтому две отдельные кнопки: левая чисто копирует текст, правая
пишет нажатие в статистику.
"""
"""Кнопка копирования поста: клик копирует текст (copy_text), нажатие пишется в статистику (callback_data)."""
return InlineKeyboardMarkup(
inline_keyboard=[[
InlineKeyboardButton(
text="📋 Скопировать",
copy_text=CopyTextButton(text=post_text[:256]),
),
InlineKeyboardButton(
text="📊",
copy_text=CopyTextButton(text=post_text),
callback_data=f"copy_post:{post_index}",
),
]],
+3 -5
View File
@@ -1232,10 +1232,9 @@ class PostCopyButtonTests(unittest.IsolatedAsyncioTestCase):
):
await bot._send_three_posts(cast(Any, message), ["Пост А", "Пост Б"], user_id=None)
first = message.answer.await_args_list[0]
copy_button, stats_button = first.kwargs["reply_markup"].inline_keyboard[0]
self.assertEqual(copy_button.copy_text.text, "Пост А")
self.assertIsNone(copy_button.callback_data) # по доке: copy_text и callback_data в одной кнопке несовместимы
self.assertEqual(stats_button.callback_data, "copy_post:0")
button = first.kwargs["reply_markup"].inline_keyboard[0][0]
self.assertEqual(button.copy_text.text, "Пост А")
self.assertEqual(button.callback_data, "copy_post:0")
async def test_copy_callback_records_event_and_keeps_button(self):
callback = SimpleNamespace(
@@ -1243,7 +1242,6 @@ class PostCopyButtonTests(unittest.IsolatedAsyncioTestCase):
message=MagicMock(spec=bot.Message),
answer=AsyncMock(),
)
callback.message.edit_reply_markup = AsyncMock()
with patch.object(bot.asyncio, "to_thread", new=AsyncMock()) as to_thread:
await bot.post_copy_pressed(cast(Any, callback))
to_thread.assert_awaited_once()