too many changes

This commit is contained in:
2026-10-09 02:07:18 +04:00
parent 9885e570b9
commit 833286debd
40 changed files with 1854 additions and 260 deletions
+43 -3
View File
@@ -16,10 +16,50 @@ export const close = () => tg?.close()
export const getQueryId = () => tg?.initDataUnsafe?.query_id ?? null
export const isAttachmentMode = () => !!getQueryId()
/** Показать нативный алерт Telegram, или fallback на browser alert вне TG-контекста */
/**
* Имя чата/собеседника, в который будет отправлено медиа.
* - Личный чат → receiver.first_name (+ last_name если есть)
* - Группа/канал → chat.title
* Возвращает null, если информации нет.
*/
export function getChatName() {
const d = tg?.initDataUnsafe
if (!d) return null
if (d.receiver) {
const name = [d.receiver.first_name, d.receiver.last_name].filter(Boolean).join(' ')
return name || d.receiver.username || null
}
if (d.chat) return d.chat.title ?? null
return null
}
/**
* Тип чата, в который будет отправлено медиа.
* - 'private' → личный чат (есть receiver)
* - 'group' → группа
* - 'supergroup' → супергруппа
* - 'channel' → канал
* - null → неизвестно
*/
export function getChatType() {
const d = tg?.initDataUnsafe
if (!d) return null
if (d.receiver) return 'private'
if (d.chat?.type) return d.chat.type // 'group' | 'supergroup' | 'channel'
return null
}
/**
* Показать нативный алерт Telegram.
* Если WebApp не поддерживает метод (версия < 6.1) или контекст — обычный браузер,
* падаем на стандартный window.alert.
*/
export const showAlert = (msg) => {
if (tg?.showAlert) tg.showAlert(msg)
else alert(msg)
if (tg?.showAlert) {
try { tg.showAlert(msg) } catch { alert(msg) }
} else {
alert(msg)
}
}
/** Применить тему Telegram к CSS-переменным */