diff --git a/app/core/background/indexer_service.py b/app/core/background/indexer_service.py index 75e818f..b6b2bdb 100644 --- a/app/core/background/indexer_service.py +++ b/app/core/background/indexer_service.py @@ -3,6 +3,7 @@ from base64 import b64decode from datetime import datetime from base58 import b58encode +from sqlalchemy import and_ from tonsdk.boc import Cell from tonsdk.utils import Address @@ -10,6 +11,7 @@ from app.core._blockchain.ton.platform import platform from app.core._blockchain.ton.toncenter import toncenter from app.core._utils.send_status import send_status from app.core.logger import make_log +from app.core.models import UserContent from app.core.models.node_storage import StoredContent from app.core._utils.resolve_content import resolve_content from app.core.models.wallet_connection import WalletConnection @@ -32,6 +34,28 @@ async def indexer_loop(memory, platform_found: bool, seqno: int) -> [bool, int]: make_log("Indexer", "Service running", level="debug") with db_session() as session: + new_licenses = session.query(UserContent).filter( + and_( + ~UserContent.meta.contains({'notification_sent': True}), + UserContent.type == 'nft/listen' + ) + ).all() + for new_license in new_licenses: + licensed_content = session.query(StoredContent).filter( + StoredContent.id == new_license.content_id + ).first() + if not licensed_content: + make_log("Indexer", f"Licensed content not found: {new_license.content_id}", level="error") + + user = new_license.user + if user.telegram_id and licensed_content: + await (Wrapped_CBotChat(memory._telegram_bot, chat_id=user.telegram_id)).send_content( + session, licensed_content + ) + + new_license.meta = {**new_license.meta, 'notification_sent': True} + session.commit() + content_without_cid = session.query(StoredContent).filter( StoredContent.content_id == None ) @@ -224,6 +248,8 @@ async def main_fn(memory, ): await asyncio.sleep(5) seqno += 1 + + # if __name__ == '__main__': # loop = asyncio.get_event_loop() # loop.run_until_complete(main()) diff --git a/app/core/models/_telegram/templates/player.py b/app/core/models/_telegram/templates/player.py index d1fc9a1..c1c49b1 100644 --- a/app/core/models/_telegram/templates/player.py +++ b/app/core/models/_telegram/templates/player.py @@ -72,7 +72,11 @@ class PlayerTemplates: if self.bot_id == 1: inline_keyboard_array.append([{ 'text': self.user.translated('shareTrack_button'), - 'switch_inline_query': f"C{content.cid.serialize_v2()}" + 'switch_inline_query': f"C{content.cid.serialize_v2()}", + }]) + inline_keyboard_array.append([{ + 'text': self.user.translated('openTrackInApp_button'), + 'url': f"https://t.me/{CLIENT_TELEGRAM_BOT_USERNAME}/content?startapp={content.cid.serialize_v2()}" }]) else: inline_keyboard_array.append([{ @@ -101,28 +105,6 @@ class PlayerTemplates: ) if not have_access: template_kwargs['audio'] = URLInputFile(local_content_url + '?seconds_limit=30') - purchase_action = self.db_session.query(UserAction).filter_by( - type='purchase', - from_address=user_wallet_address, - content_id=content.id, - status='requested' - ).first() - if purchase_action: - inline_keyboard_array.append([{ - 'text': self.user.translated('gotoWallet_button'), - 'url': purchase_action.meta['confirmation_url'] - }]) - inline_keyboard_array.append([{ - 'text': self.user.translated('cancelPurchase_button'), - 'callback_data': f'PC_{content.id}_cancel' - }]) - text = self.user.translated('p_playerContext_purchaseRequested') - else: - inline_keyboard_array.append([{ - 'text': self.user.translated('buyTrackListenLicense_button').format(price=str(round(0.15, 3))), - 'callback_data': f'PC_{content.id}' - }]) - text = self.user.translated('p_playerContext_preview') make_log("TG-Player", f"Send content {content_type} ({content_encoding}) to chat {self._chat_id}. {cd_log}") for kmsg in self.db_session.query(KnownTelegramMessage).filter_by( diff --git a/locale/en/LC_MESSAGES/sanic_telegram_bot.mo b/locale/en/LC_MESSAGES/sanic_telegram_bot.mo index c19a57d..1b66abd 100644 Binary files a/locale/en/LC_MESSAGES/sanic_telegram_bot.mo and b/locale/en/LC_MESSAGES/sanic_telegram_bot.mo differ diff --git a/locale/en/LC_MESSAGES/sanic_telegram_bot.po b/locale/en/LC_MESSAGES/sanic_telegram_bot.po index 5f7e7fb..4cf4d01 100644 --- a/locale/en/LC_MESSAGES/sanic_telegram_bot.po +++ b/locale/en/LC_MESSAGES/sanic_telegram_bot.po @@ -161,3 +161,6 @@ msgstr "Open smartcontract" msgid "noWalletConnected" msgstr "No wallet connected" + +msgid "openTrackInApp_button" +msgstr "Open in app"