From 0f13479cb6753709728b61300d9513cd61b27d8f Mon Sep 17 00:00:00 2001 From: user Date: Mon, 28 Oct 2024 17:43:53 +0300 Subject: [PATCH] purchase notifications --- app/core/background/indexer_service.py | 26 ++++++++++++++++ app/core/models/_telegram/templates/player.py | 28 ++++-------------- locale/en/LC_MESSAGES/sanic_telegram_bot.mo | Bin 2773 -> 2839 bytes locale/en/LC_MESSAGES/sanic_telegram_bot.po | 3 ++ 4 files changed, 34 insertions(+), 23 deletions(-) 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 c19a57dca08117ea27e1e2845d432172042272b3..1b66abd8be8bc3a137a3832884749e62c89d56fb 100644 GIT binary patch delta 704 zcmX}qJxBvV5QgDN?lk_zXf*yr#Y9PwGPV*yK|w6E2-w&JQ4}$RfM6G}v6EPcpjZj1 zg%m<68#@a@Eo?+9MeJ;}5PZMO>A>;q?cL4p%-%!nxUc*ab&re~;Tq<017>ObKt&~J z){cj$=VuthI`-qO@0&kwj#-rXKJ3LbcHkO1=7nQhzJy>nLV0Hig z2KC-ECh-f$Fz&J#W-);|)Pg&xJo`9=r#OI@*oC*=eA(=UK|j_0pmrE*HXFnwMsO0B zaRIf^IVw>dNAV6b_=);H6>6BlJ?^upja;ERbMHTY#R%)$CxaPuTFkC-4%e`QJ{@2Q zRdJxL;W*~FpG7Trf)iLpRrZLT_>OAzH);b8FH@%%oR$~m4u3%L|Dkp%)NX~6>MXT; zb%uOiXTaM)7@N4%75ztAlp4I?l#Iq0HG2P#j`%O)N~xA=ciOSe&1&00HxMqa6>_Eg c>ehT=x>&4jIP-4%B6Eq&LL$$^MJVO`0>ijF_5c6? delta 658 zcmYk)J4gdT5P;!H?&2BWMw9p=KF~f|3yOukAec^!T8S7TmU2W=S=fjMBHAk2C@HK& zB8XydCqBT=!a_)+h5ziW;K1E?yO+$)&R!|;826uJ?w$~R_WHpQuBQ+;A{Q2E#C6o) zY+@YCn8b7Iy`6u>81psk#Hb_Ejw#eUX^i4{Fz?GW51J^09heJVNYRe>?fX+40g;r4$ z6|o-=aTKpm|Nm+I#x2I47ZkFM+L0sFycalyRlH?=aqFoPA8-fL^hbAkZGFR8#!f@9 zPzJ{sFQM+Jge`c2+S*Ih4pdQ3QM;?5oBIn+$85@{2%!O{Lfr+$o6v+b!i1i;Cf4@q znUdFh3r(mk{vYhYL^F5YZ4VbGWeU<_wS$sfSX`OUZshZ8y9eP~<=B~YD_`EQ^9%i? BI6D9U 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"