fix(posts): keep copy button after press, count every tap

This commit is contained in:
admin committed 2026-10-30 14:33:38 +02:00
1 parent 88230c92b5
commit 992d8645cf
3 files changed
+7 -12

No files matched your search

+1 -1
View File
@@ -1 +1 @@
0.1.0+85
0.1.0+86
+4 -8
View File
@@ -760,16 +760,12 @@ async def clear_command(message: Message, state: FSMContext) -> None:
@router.callback_query(F.data.startswith("copy_post:"))
async def post_copy_pressed(callback: CallbackQuery) -> None:
"""Кнопка «Скопировать»: текст копирует сам Telegram (copy_text), здесь пишем только статистику."""
"""Кнопка «Скопировать»: текст копирует сам Telegram (copy_text), здесь пишем только статистику.
Кнопку не убираем — она работает бесконечно, каждое нажатие считается отдельно.
"""
if callback.from_user is not None:
await asyncio.to_thread(analytics.record_event, callback.from_user.id, "generation", "post_copy")
message = callback.message
if isinstance(message, Message):
try:
await message.edit_reply_markup(reply_markup=None)
except Exception as exc:
if "message is not modified" not in str(exc).casefold():
logger.debug("Copy button removal failed: %s", str(exc)[:120])
await callback.answer()
+2 -3
View File
@@ -1236,18 +1236,17 @@ class PostCopyButtonTests(unittest.IsolatedAsyncioTestCase):
self.assertEqual(button.copy_text.text, "Пост А")
self.assertEqual(button.callback_data, "copy_post:0")
async def test_copy_callback_records_event_and_clears_button(self):
async def test_copy_callback_records_event_and_keeps_button(self):
callback = SimpleNamespace(
from_user=SimpleNamespace(id=42),
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()
self.assertEqual(to_thread.await_args.args[1:], (42, "generation", "post_copy"))
callback.message.edit_reply_markup.assert_awaited_once_with(reply_markup=None)
callback.message.edit_reply_markup.assert_not_awaited()
callback.answer.assert_awaited_once()