This commit is contained in:
+24
-2
@@ -480,6 +480,8 @@ function configsPage() {
|
||||
telegramModal: null,
|
||||
telegramBusy: false,
|
||||
telegramPromptChecked: false,
|
||||
telegramStatusTimer: null,
|
||||
telegramStatusPolling: false,
|
||||
isAdmin: {% if is_admin %}true{% else %}false{% endif %},
|
||||
init() {
|
||||
this.initTelegramWebApp();
|
||||
@@ -489,6 +491,7 @@ function configsPage() {
|
||||
this.loadRolloutStatus();
|
||||
this.rolloutTimer = setInterval(() => this.loadRolloutStatus(), 10000);
|
||||
}
|
||||
this.telegramStatusTimer = setInterval(() => this.pollTelegramStatus(), 2500);
|
||||
},
|
||||
async request(url, options = {}) {
|
||||
const response = await fetch(url, {
|
||||
@@ -516,11 +519,11 @@ function configsPage() {
|
||||
this.telegram.isWebApp = Boolean(webApp.initData);
|
||||
this.telegram.initData = webApp.initData || '';
|
||||
},
|
||||
async loadTelegramStatus() {
|
||||
async loadTelegramStatus(options = {}) {
|
||||
try {
|
||||
const status = await this.request('/api/telegram-link/status');
|
||||
this.applyTelegramStatus(status);
|
||||
this.maybePromptTelegram();
|
||||
if (options.prompt !== false) this.maybePromptTelegram();
|
||||
} catch (e) {
|
||||
console.warn('telegram status failed', e);
|
||||
}
|
||||
@@ -595,6 +598,25 @@ function configsPage() {
|
||||
this.telegramBusy = false;
|
||||
}
|
||||
},
|
||||
async pollTelegramStatus() {
|
||||
if (this.telegramStatusPolling || this.telegramBusy) return;
|
||||
if (!this.telegram.enabled || !this.telegram.pending) return;
|
||||
if (this.telegramModal !== 'manualGuide' && this.telegramModal !== 'manage') return;
|
||||
|
||||
this.telegramStatusPolling = true;
|
||||
const wasPending = this.telegram.pending;
|
||||
try {
|
||||
await this.loadTelegramStatus({ prompt: false });
|
||||
if (wasPending && this.telegram.linked) {
|
||||
this.telegramModal = 'manage';
|
||||
this.setNotice('success', '{{ t.notice_success_title }}', '{{ t.telegram_saved }}');
|
||||
} else if (wasPending && !this.telegram.pending) {
|
||||
this.telegramModal = 'manage';
|
||||
}
|
||||
} finally {
|
||||
this.telegramStatusPolling = false;
|
||||
}
|
||||
},
|
||||
async copyTelegramSecret() {
|
||||
if (!this.telegram.pending_secret) return;
|
||||
this.clearNotice();
|
||||
|
||||
Reference in New Issue
Block a user