purchase notifications

This commit is contained in:
user 2024-10-28 17:43:53 +03:00
parent 2609495b91
commit 0f13479cb6
4 changed files with 34 additions and 23 deletions

View File

@ -3,6 +3,7 @@ from base64 import b64decode
from datetime import datetime from datetime import datetime
from base58 import b58encode from base58 import b58encode
from sqlalchemy import and_
from tonsdk.boc import Cell from tonsdk.boc import Cell
from tonsdk.utils import Address 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._blockchain.ton.toncenter import toncenter
from app.core._utils.send_status import send_status from app.core._utils.send_status import send_status
from app.core.logger import make_log from app.core.logger import make_log
from app.core.models import UserContent
from app.core.models.node_storage import StoredContent from app.core.models.node_storage import StoredContent
from app.core._utils.resolve_content import resolve_content from app.core._utils.resolve_content import resolve_content
from app.core.models.wallet_connection import WalletConnection 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") make_log("Indexer", "Service running", level="debug")
with db_session() as session: 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( content_without_cid = session.query(StoredContent).filter(
StoredContent.content_id == None StoredContent.content_id == None
) )
@ -224,6 +248,8 @@ async def main_fn(memory, ):
await asyncio.sleep(5) await asyncio.sleep(5)
seqno += 1 seqno += 1
# if __name__ == '__main__': # if __name__ == '__main__':
# loop = asyncio.get_event_loop() # loop = asyncio.get_event_loop()
# loop.run_until_complete(main()) # loop.run_until_complete(main())

View File

@ -72,7 +72,11 @@ class PlayerTemplates:
if self.bot_id == 1: if self.bot_id == 1:
inline_keyboard_array.append([{ inline_keyboard_array.append([{
'text': self.user.translated('shareTrack_button'), '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: else:
inline_keyboard_array.append([{ inline_keyboard_array.append([{
@ -101,28 +105,6 @@ class PlayerTemplates:
) )
if not have_access: if not have_access:
template_kwargs['audio'] = URLInputFile(local_content_url + '?seconds_limit=30') 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}") 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( for kmsg in self.db_session.query(KnownTelegramMessage).filter_by(

View File

@ -161,3 +161,6 @@ msgstr "Open smartcontract"
msgid "noWalletConnected" msgid "noWalletConnected"
msgstr "No wallet connected" msgstr "No wallet connected"
msgid "openTrackInApp_button"
msgstr "Open in app"