feat(telegram): native dialogs (experimental, stacked on #136) #137
@@ -11,10 +11,6 @@
|
|||||||
// Split the message around the {bot} token so the bot handle renders as an inline link.
|
// Split the message around the {bot} token so the bot handle renders as an inline link.
|
||||||
const parts = $derived(t('friends.staleInvite').split('{bot}'));
|
const parts = $derived(t('friends.staleInvite').split('{bot}'));
|
||||||
|
|
||||||
// Inside the Mini App with native popups, present the notice as Telegram's own popup instead of
|
|
||||||
// the in-app modal.
|
|
||||||
const useNative = insideTelegram() && telegramDialogsAvailable();
|
|
||||||
|
|
||||||
function openBot() {
|
function openBot() {
|
||||||
if (username) {
|
if (username) {
|
||||||
const url = `https://t.me/${username}`;
|
const url = `https://t.me/${username}`;
|
||||||
@@ -25,12 +21,14 @@
|
|||||||
dismissStaleInvite();
|
dismissStaleInvite();
|
||||||
}
|
}
|
||||||
|
|
||||||
// Native path: raise Telegram's popup when the notice appears; its "open bot" button opens the
|
// Native path: when the notice fires inside the Mini App with native popups, present Telegram's
|
||||||
// bot chat, any other dismissal just clears the notice. The `shown` guard fires it once per notice.
|
// own popup instead of the in-app modal. insideTelegram()/dialogs are evaluated at fire time, not
|
||||||
|
// captured at init: this component mounts before bootstrap loads the SDK, so a captured value
|
||||||
|
// would be stale. The popup's "open bot" button opens the bot chat; any other dismissal clears the
|
||||||
|
// notice; the `shown` guard fires it once per notice.
|
||||||
let shown = false;
|
let shown = false;
|
||||||
$effect(() => {
|
$effect(() => {
|
||||||
if (!useNative) return;
|
if (app.staleInvite && !shown && insideTelegram() && telegramDialogsAvailable()) {
|
||||||
if (app.staleInvite && !shown) {
|
|
||||||
shown = true;
|
shown = true;
|
||||||
void telegramShowPopup(
|
void telegramShowPopup(
|
||||||
botInfoPopup(t('friends.staleInviteTitle'), t('friends.staleInvite'), username ?? '', t('common.ok')),
|
botInfoPopup(t('friends.staleInviteTitle'), t('friends.staleInvite'), username ?? '', t('common.ok')),
|
||||||
@@ -41,7 +39,7 @@
|
|||||||
});
|
});
|
||||||
</script>
|
</script>
|
||||||
|
|
||||||
{#if app.staleInvite && !useNative}
|
{#if app.staleInvite && !(insideTelegram() && telegramDialogsAvailable())}
|
||||||
<Modal title={t('friends.staleInviteTitle')} onclose={dismissStaleInvite}>
|
<Modal title={t('friends.staleInviteTitle')} onclose={dismissStaleInvite}>
|
||||||
<p class="msg">{parts[0]}{#if username}<button type="button" class="bot" onclick={openBot}>@{username}</button>{/if}{parts[1] ?? ''}</p>
|
<p class="msg">{parts[0]}{#if username}<button type="button" class="bot" onclick={openBot}>@{username}</button>{/if}{parts[1] ?? ''}</p>
|
||||||
<button class="ok" onclick={dismissStaleInvite}>{t('common.ok')}</button>
|
<button class="ok" onclick={dismissStaleInvite}>{t('common.ok')}</button>
|
||||||
|
|||||||
@@ -14,10 +14,6 @@
|
|||||||
// as an inline link (the {name} value is substituted first; {bot} is left for the split).
|
// as an inline link (the {name} value is substituted first; {bot} is left for the split).
|
||||||
const parts = $derived(t('friends.welcomeRedeem', { name }).split('{bot}'));
|
const parts = $derived(t('friends.welcomeRedeem', { name }).split('{bot}'));
|
||||||
|
|
||||||
// Inside the Mini App with native popups, present the greeting as Telegram's own popup instead of
|
|
||||||
// the in-app modal.
|
|
||||||
const useNative = insideTelegram() && telegramDialogsAvailable();
|
|
||||||
|
|
||||||
function openBot() {
|
function openBot() {
|
||||||
if (username) {
|
if (username) {
|
||||||
const url = `https://t.me/${username}`;
|
const url = `https://t.me/${username}`;
|
||||||
@@ -28,12 +24,14 @@
|
|||||||
dismissWelcomeRedeem();
|
dismissWelcomeRedeem();
|
||||||
}
|
}
|
||||||
|
|
||||||
// Native path: raise Telegram's popup when the greeting appears; its "open bot" button opens the
|
// Native path: when the greeting fires inside the Mini App with native popups, present Telegram's
|
||||||
// bot chat, any other dismissal just clears it. The `shown` guard fires it once per greeting.
|
// own popup instead of the in-app modal. insideTelegram()/dialogs are evaluated at fire time, not
|
||||||
|
// captured at init: this component mounts before bootstrap loads the SDK, so a captured value
|
||||||
|
// would be stale. The popup's "open bot" button opens the bot chat; any other dismissal clears it;
|
||||||
|
// the `shown` guard fires it once per greeting.
|
||||||
let shown = false;
|
let shown = false;
|
||||||
$effect(() => {
|
$effect(() => {
|
||||||
if (!useNative) return;
|
if (app.welcomeRedeem && !shown && insideTelegram() && telegramDialogsAvailable()) {
|
||||||
if (app.welcomeRedeem && !shown) {
|
|
||||||
shown = true;
|
shown = true;
|
||||||
void telegramShowPopup(
|
void telegramShowPopup(
|
||||||
botInfoPopup(t('friends.welcomeRedeemTitle'), t('friends.welcomeRedeem', { name }), username ?? '', t('common.ok')),
|
botInfoPopup(t('friends.welcomeRedeemTitle'), t('friends.welcomeRedeem', { name }), username ?? '', t('common.ok')),
|
||||||
@@ -44,7 +42,7 @@
|
|||||||
});
|
});
|
||||||
</script>
|
</script>
|
||||||
|
|
||||||
{#if app.welcomeRedeem && !useNative}
|
{#if app.welcomeRedeem && !(insideTelegram() && telegramDialogsAvailable())}
|
||||||
<Modal title={t('friends.welcomeRedeemTitle')} onclose={dismissWelcomeRedeem}>
|
<Modal title={t('friends.welcomeRedeemTitle')} onclose={dismissWelcomeRedeem}>
|
||||||
<p class="msg">{parts[0]}{#if username}<button type="button" class="bot" onclick={openBot}>@{username}</button>{/if}{parts[1] ?? ''}</p>
|
<p class="msg">{parts[0]}{#if username}<button type="button" class="bot" onclick={openBot}>@{username}</button>{/if}{parts[1] ?? ''}</p>
|
||||||
<button class="ok" onclick={dismissWelcomeRedeem}>{t('common.ok')}</button>
|
<button class="ok" onclick={dismissWelcomeRedeem}>{t('common.ok')}</button>
|
||||||
|
|||||||
Reference in New Issue
Block a user