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AyB,EAAY,GAAKnC,EAEjB,IACE,MAAMqI,QAAkBvK,KAAKC,QAAQqK,WAAWvF,GAC5CwF,IAEFlG,EAAYkG,EAAU5J,IAAMuB,GAE9B,MAAOuB,OAQC+G,OCtKdxK,KAAKgC,iBAAiB,WDyKf,SAA6BrC,GAKlC,IAAKA,EAAEuC,KAAM,OACb,MAAMuI,EAAS9K,EAAE8K,OACjB,GAAoB,gBAAhB9K,EAAEuC,KAAK7B,KAAwB,CAEjC,MAAM6B,EAAOmC,EAAYoG,EAAO9J,KAAO0D,EAAY,GAC/CnC,WACKmC,EAAYoG,EAAO9J,WACnB0D,EAAY,GACnB1E,EAAE+G,UAAUL,EAAiBoE,EAAQvI,KAGzC,GAAoB,4BAAhBvC,EAAEuC,KAAK7B,KAAoC,CAE7C,MAAM4J,EAAiCtK,EAAEuC,KAAKoD,QAC9C3F,EAAE+G,UAAU,WAENuD,EAAazE,eACaxF,KAAKiF,aAAayF,iBAAiB,CAAExE,IAAK+D,EAAazE,UACrEmF,SAASC,GAAMA,EAAEjB,UAGjCvF,EAAmByG,IAAIZ,EAAaxJ,WAC7B8E,EAAiB0E,IARd,IAYM,8BAAhBtK,EAAEuC,KAAK7B,MACTV,EAAE+G,UA5HNjH,eAAA,GAG0B,IAHQ,OAChC+F,EADgC,uBAEhCsF,GACwB,EACxB,MAAMC,QAAsB/K,KAAKiF,aAAayF,mBACxCM,EAAgBF,GAA0B3D,OAAO8D,UACvDF,EAAcJ,SAASV,KAEE,MAArBA,EAAa/D,KACT+D,EAAa/H,KAAKsD,SAAWA,GAAUyE,EAAa/H,KAAKzB,WAAauK,IAE1Ef,EAAaN,WAiHHuB,CAAmBvL,EAAEuC,KAAKoD,c","sources":["webpack://telegram-t/./src/config.ts","webpack://telegram-t/./src/util/schedulers.ts","webpack://telegram-t/./src/serviceWorker/progressive.ts","webpack://telegram-t/./src/util/generateIdFor.ts","webpack://telegram-t/./src/serviceWorker/download.ts","webpack://telegram-t/./src/serviceWorker/assetCache.ts","webpack://telegram-t/./src/serviceWorker/pushNotification.ts","webpack://telegram-t/./src/serviceWorker.ts"],"sourcesContent":["import type { ApiLimitType } from './global/types';\n\nexport const APP_NAME = process.env.APP_NAME || 'Telegram WebZ';\nexport const APP_VERSION = process.env.APP_VERSION!;\n\nexport const PRODUCTION_HOSTNAME = 'web.telegram.org';\n\nexport const DEBUG = process.env.APP_ENV !== 'production';\nexport const DEBUG_MORE = false;\n\nexport const IS_MOCKED_CLIENT = process.env.APP_MOCKED_CLIENT === '1';\nexport const IS_TEST = process.env.APP_ENV === 'test';\nexport const IS_PERF = process.env.APP_ENV === 'perf';\nexport const IS_BETA = process.env.APP_ENV === 'staging';\n\nexport const BETA_CHANGELOG_URL = 'https://telegra.ph/WebZ-Beta-04-01';\n\nexport const DEBUG_ALERT_MSG = 'Shoot!\\nSomething went wrong, please see the error details in Dev Tools Console.';\nexport const DEBUG_GRAMJS = false;\n\nexport const PAGE_TITLE = 'Telegram';\nexport const INACTIVE_MARKER = ' [Inactive]';\n\nexport const DEBUG_PAYMENT_SMART_GLOCAL = false;\n\nexport const SESSION_USER_KEY = 'user_auth';\nexport const LEGACY_SESSION_KEY = 'GramJs:sessionId';\nexport const PASSCODE_CACHE_NAME = 'tt-passcode';\n\nexport const GLOBAL_STATE_CACHE_DISABLED = false;\nexport const GLOBAL_STATE_CACHE_KEY = 'tt-global-state';\nexport const GLOBAL_STATE_CACHE_USER_LIST_LIMIT = 500;\nexport const GLOBAL_STATE_CACHE_CHAT_LIST_LIMIT = 200;\nexport const GLOBAL_STATE_CACHE_CHATS_WITH_MESSAGES_LIMIT = 30;\nexport const GLOBAL_STATE_CACHE_CUSTOM_EMOJI_LIMIT = 150;\n\nexport const MEDIA_CACHE_DISABLED = false;\nexport const MEDIA_CACHE_NAME = 'tt-media';\nexport const MEDIA_CACHE_NAME_AVATARS = 'tt-media-avatars';\nexport const MEDIA_PROGRESSIVE_CACHE_DISABLED = false;\nexport const MEDIA_PROGRESSIVE_CACHE_NAME = 'tt-media-progressive';\nexport const MEDIA_CACHE_MAX_BYTES = 512 * 1024; // 512 KB\nexport const CUSTOM_BG_CACHE_NAME = 'tt-custom-bg';\nexport const LANG_CACHE_NAME = 'tt-lang-packs-v13';\nexport const ASSET_CACHE_NAME = 'tt-assets';\nexport const AUTODOWNLOAD_FILESIZE_MB_LIMITS = [1, 5, 10, 50, 100, 500];\n\nexport const DOWNLOAD_WORKERS = 16;\nexport const UPLOAD_WORKERS = 16;\n\nconst isBigScreen = typeof window !== 'undefined' && window.innerHeight >= 900;\n\nexport const MIN_PASSWORD_LENGTH = 1;\n\nexport const MESSAGE_LIST_SLICE = isBigScreen ? 60 : 40;\nexport const MESSAGE_LIST_VIEWPORT_LIMIT = MESSAGE_LIST_SLICE * 2;\n\nexport const CHAT_HEIGHT_PX = 72;\nexport const CHAT_LIST_SLICE = isBigScreen ? 30 : 25;\nexport const CHAT_LIST_LOAD_SLICE = 100;\nexport const SHARED_MEDIA_SLICE = 42;\nexport const MESSAGE_SEARCH_SLICE = 42;\nexport const GLOBAL_SEARCH_SLICE = 20;\nexport const MEMBERS_SLICE = 30;\nexport const MEMBERS_LOAD_SLICE = 200;\nexport const PINNED_MESSAGES_LIMIT = 50;\nexport const BLOCKED_LIST_LIMIT = 100;\nexport const PROFILE_PHOTOS_LIMIT = 40;\nexport const PROFILE_SENSITIVE_AREA = 500;\nexport const COMMON_CHATS_LIMIT = 100;\nexport const GROUP_CALL_PARTICIPANTS_LIMIT = 100;\nexport const REACTION_LIST_LIMIT = 100;\nexport const REACTION_UNREAD_SLICE = 100;\nexport const MENTION_UNREAD_SLICE = 100;\n\nexport const TOP_CHAT_MESSAGES_PRELOAD_LIMIT = 20;\n\nexport const SPONSORED_MESSAGE_CACHE_MS = 300000; // 5 min\n\nexport const DEFAULT_VOLUME = 1;\nexport const DEFAULT_PLAYBACK_RATE = 1;\nexport const PLAYBACK_RATE_FOR_AUDIO_MIN_DURATION = 20 * 60; // 20 min\n\nexport const ANIMATION_LEVEL_MIN = 0;\nexport const ANIMATION_LEVEL_MED = 1;\nexport const ANIMATION_LEVEL_MAX = 2;\nexport const ANIMATION_LEVEL_DEFAULT = ANIMATION_LEVEL_MAX;\n\nexport const DEFAULT_MESSAGE_TEXT_SIZE_PX = 16;\nexport const IOS_DEFAULT_MESSAGE_TEXT_SIZE_PX = 17;\nexport const MACOS_DEFAULT_MESSAGE_TEXT_SIZE_PX = 15;\n\nexport const DRAFT_DEBOUNCE = 10000; // 10s\nexport const SEND_MESSAGE_ACTION_INTERVAL = 3000; // 3s\n\nexport const EDITABLE_INPUT_ID = 'editable-message-text';\nexport const EDITABLE_INPUT_MODAL_ID = 'editable-message-text-modal';\n// eslint-disable-next-line max-len\nexport const EDITABLE_INPUT_CSS_SELECTOR = `.messages-layout .Transition__slide--active #${EDITABLE_INPUT_ID}, .messages-layout .Transition > .to #${EDITABLE_INPUT_ID}`;\n\nexport const CUSTOM_APPENDIX_ATTRIBUTE = 'data-has-custom-appendix';\n\n// Screen width where Pinned Message / Audio Player in the Middle Header can be safely displayed\nexport const SAFE_SCREEN_WIDTH_FOR_STATIC_RIGHT_COLUMN = 1440; // px\n// Screen width where Pinned Message / Audio Player in the Middle Header shouldn't collapse with ChatInfo\nexport const SAFE_SCREEN_WIDTH_FOR_CHAT_INFO = 1150; // px\n\nexport const MIN_SCREEN_WIDTH_FOR_STATIC_RIGHT_COLUMN = 1275; // px\nexport const MIN_SCREEN_WIDTH_FOR_STATIC_LEFT_COLUMN = 925; // px\nexport const MAX_SCREEN_WIDTH_FOR_EXPAND_PINNED_MESSAGES = 1340; // px\nexport const MOBILE_SCREEN_MAX_WIDTH = 600; // px\nexport const MOBILE_SCREEN_LANDSCAPE_MAX_WIDTH = 950; // px\nexport const MOBILE_SCREEN_LANDSCAPE_MAX_HEIGHT = 450; // px\n\nexport const LOCAL_MESSAGE_MIN_ID = 1e11; // `Date.now()` is always used as base\nexport const TMP_CHAT_ID = '0';\n\nexport const ANIMATION_END_DELAY = 100;\n\nexport const FAST_SMOOTH_MAX_DISTANCE = 1500;\nexport const FAST_SMOOTH_MIN_DURATION = 250;\nexport const FAST_SMOOTH_MAX_DURATION = 600;\nexport const FAST_SMOOTH_SHORT_TRANSITION_MAX_DISTANCE = 500; // px\n\n// Average duration of message sending animation\nexport const API_UPDATE_THROTTLE = Math.round((FAST_SMOOTH_MIN_DURATION + FAST_SMOOTH_MAX_DURATION) / 2);\nexport const API_THROTTLE_RESET_UPDATES = new Set([\n 'newMessage', 'newScheduledMessage', 'deleteMessages', 'deleteScheduledMessages', 'deleteHistory',\n]);\n\nexport const LOCK_SCREEN_ANIMATION_DURATION_MS = 200;\n\nexport const STICKER_SIZE_INLINE_DESKTOP_FACTOR = 13;\nexport const STICKER_SIZE_INLINE_MOBILE_FACTOR = 11;\nexport const STICKER_SIZE_AUTH = 160;\nexport const STICKER_SIZE_AUTH_MOBILE = 120;\nexport const STICKER_SIZE_PICKER = 64;\nexport const EMOJI_SIZE_PICKER = 40;\nexport const STICKER_SIZE_GENERAL_SETTINGS = 48;\nexport const STICKER_SIZE_PICKER_HEADER = 32;\nexport const STICKER_SIZE_SEARCH = 64;\nexport const STICKER_SIZE_MODAL = 64;\nexport const EMOJI_SIZE_MODAL = 40;\nexport const STICKER_SIZE_TWO_FA = 160;\nexport const STICKER_SIZE_PASSCODE = 160;\nexport const STICKER_SIZE_DISCUSSION_GROUPS = 140;\nexport const STICKER_SIZE_FOLDER_SETTINGS = 100;\nexport const STICKER_SIZE_INLINE_BOT_RESULT = 100;\nexport const STICKER_SIZE_JOIN_REQUESTS = 140;\nexport const STICKER_SIZE_INVITES = 140;\nexport const RECENT_STICKERS_LIMIT = 20;\nexport const RECENT_SYMBOL_SET_ID = 'recent';\nexport const FAVORITE_SYMBOL_SET_ID = 'favorite';\nexport const CHAT_STICKER_SET_ID = 'chatStickers';\nexport const PREMIUM_STICKER_SET_ID = 'premium';\n\nexport const BASE_EMOJI_KEYWORD_LANG = 'en';\n\nexport const MENU_TRANSITION_DURATION = 200;\nexport const SLIDE_TRANSITION_DURATION = 450;\n\nexport const VIDEO_MOV_TYPE = 'video/quicktime';\nexport const VIDEO_WEBM_TYPE = 'video/webm';\n\nexport const SUPPORTED_IMAGE_CONTENT_TYPES = new Set([\n 'image/png', 'image/gif', 'image/jpeg',\n]);\n\nexport const SUPPORTED_VIDEO_CONTENT_TYPES = new Set([\n 'video/mp4', // video/quicktime added dynamically in environment.ts\n]);\n\nexport const SUPPORTED_AUDIO_CONTENT_TYPES = new Set([\n 'audio/mp3',\n 'audio/ogg',\n 'audio/wav',\n 'audio/mpeg',\n 'audio/flac',\n 'audio/aac',\n 'audio/m4a',\n 'audio/mp4',\n 'audio/x-m4a',\n]);\n\nexport const CONTENT_TYPES_WITH_PREVIEW = new Set([\n ...SUPPORTED_IMAGE_CONTENT_TYPES,\n ...SUPPORTED_VIDEO_CONTENT_TYPES,\n]);\n\nexport const CONTENT_NOT_SUPPORTED = 'The message is not supported on this version of Telegram.';\n\n// eslint-disable-next-line max-len\nexport const RE_LINK_TEMPLATE = '((ftp|https?):\\\\/\\\\/)?((www\\\\.)?[-a-zA-Z0-9@:%._+~#=]{1,256}\\\\.[a-zA-Z0-9()]{1,63})\\\\b([-a-zA-Z0-9()@:%_+.~#?&/=]*)';\nexport const RE_MENTION_TEMPLATE = '(@[\\\\w\\\\d_-]+)';\nexport const RE_TG_LINK = /^tg:(\\/\\/)?([?=&\\d\\w_-]+)?/;\nexport const RE_TME_LINK = /^(https?:\\/\\/)?([-a-zA-Z0-9@:%_+~#=]{1,32}\\.)?t\\.me/;\nexport const RE_TELEGRAM_LINK = /^(https?:\\/\\/)?telegram\\.org\\//;\nexport const TME_LINK_PREFIX = 'https://t.me/';\n\n// eslint-disable-next-line max-len\nexport const COUNTRIES_WITH_12H_TIME_FORMAT = new Set(['AU', 'BD', 'CA', 'CO', 'EG', 'HN', 'IE', 'IN', 'JO', 'MX', 'MY', 'NI', 'NZ', 'PH', 'PK', 'SA', 'SV', 'US']);\n\n// MTProto constants\nexport const SERVICE_NOTIFICATIONS_USER_ID = '777000';\nexport const REPLIES_USER_ID = '1271266957'; // TODO For Test connection ID must be equal to 708513\nexport const ALL_FOLDER_ID = 0;\nexport const ARCHIVED_FOLDER_ID = 1;\nexport const DELETED_COMMENTS_CHANNEL_ID = '-777';\nexport const MAX_MEDIA_FILES_FOR_ALBUM = 10;\nexport const MAX_ACTIVE_PINNED_CHATS = 5;\nexport const SCHEDULED_WHEN_ONLINE = 0x7FFFFFFE;\nexport const DEFAULT_LANG_CODE = 'en';\nexport const DEFAULT_LANG_PACK = 'android';\nexport const LANG_PACKS = ['android', 'ios', 'tdesktop', 'macos'] as const;\nexport const FEEDBACK_URL = 'https://bugs.telegram.org/?tag_ids=41&sort=time';\n\nexport const LIGHT_THEME_BG_COLOR = '#99BA92';\nexport const DARK_THEME_BG_COLOR = '#0F0F0F';\nexport const DEFAULT_PATTERN_COLOR = '#4A8E3A8C';\nexport const DARK_THEME_PATTERN_COLOR = '#0A0A0A8C';\nexport const MAX_UPLOAD_FILEPART_SIZE = 524288;\n\n// Group calls\nexport const GROUP_CALL_VOLUME_MULTIPLIER = 100;\nexport const GROUP_CALL_DEFAULT_VOLUME = 100 * GROUP_CALL_VOLUME_MULTIPLIER;\nexport const GROUP_CALL_THUMB_VIDEO_DISABLED = true;\n\nexport const DEFAULT_LIMITS: Record<ApiLimitType, readonly [number, number]> = {\n uploadMaxFileparts: [4000, 8000],\n stickersFaved: [5, 10],\n savedGifs: [200, 400],\n dialogFiltersChats: [100, 200],\n dialogFilters: [10, 20],\n dialogFolderPinned: [5, 10],\n captionLength: [1024, 2048],\n channels: [500, 1000],\n channelsPublic: [10, 20],\n aboutLength: [70, 140],\n};\n","type Scheduler =\n typeof requestAnimationFrame\n | typeof onTickEnd;\n\nexport function debounce<F extends AnyToVoidFunction>(\n fn: F,\n ms: number,\n shouldRunFirst = true,\n shouldRunLast = true,\n) {\n let waitingTimeout: number | undefined;\n\n return (...args: Parameters<F>) => {\n if (waitingTimeout) {\n clearTimeout(waitingTimeout);\n waitingTimeout = undefined;\n } else if (shouldRunFirst) {\n fn(...args);\n }\n\n // eslint-disable-next-line no-restricted-globals\n waitingTimeout = self.setTimeout(() => {\n if (shouldRunLast) {\n fn(...args);\n }\n\n waitingTimeout = undefined;\n }, ms);\n };\n}\n\nexport function throttle<F extends AnyToVoidFunction>(\n fn: F,\n ms: number,\n shouldRunFirst = true,\n) {\n let interval: number | undefined;\n let isPending: boolean;\n let args: Parameters<F>;\n\n return (..._args: Parameters<F>) => {\n isPending = true;\n args = _args;\n\n if (!interval) {\n if (shouldRunFirst) {\n isPending = false;\n fn(...args);\n }\n\n // eslint-disable-next-line no-restricted-globals\n interval = self.setInterval(() => {\n if (!isPending) {\n // eslint-disable-next-line no-restricted-globals\n self.clearInterval(interval!);\n interval = undefined;\n return;\n }\n\n isPending = false;\n fn(...args);\n }, ms);\n }\n };\n}\n\nexport function throttleWithRaf<F extends AnyToVoidFunction>(fn: F) {\n return throttleWith(fastRaf, fn);\n}\n\nexport function throttleWithPrimaryRaf<F extends AnyToVoidFunction>(fn: F) {\n return throttleWith(fastRafPrimary, fn);\n}\n\nexport function throttleWithTickEnd<F extends AnyToVoidFunction>(fn: F) {\n return throttleWith(onTickEnd, fn);\n}\n\nexport function throttleWith<F extends AnyToVoidFunction>(schedulerFn: Scheduler, fn: F) {\n let waiting = false;\n let args: Parameters<F>;\n\n return (..._args: Parameters<F>) => {\n args = _args;\n\n if (!waiting) {\n waiting = true;\n\n schedulerFn(() => {\n waiting = false;\n fn(...args);\n });\n }\n };\n}\n\nexport function onIdle(cb: NoneToVoidFunction, timeout?: number) {\n // eslint-disable-next-line no-restricted-globals\n if (self.requestIdleCallback) {\n // eslint-disable-next-line no-restricted-globals\n self.requestIdleCallback(cb, { timeout });\n } else {\n onTickEnd(cb);\n }\n}\n\nexport const pause = (ms: number) => new Promise<void>((resolve) => {\n setTimeout(() => resolve(), ms);\n});\n\nexport function rafPromise() {\n return new Promise<void>((resolve) => {\n fastRaf(resolve);\n });\n}\n\nlet fastRafCallbacks: NoneToVoidFunction[] | undefined;\nlet fastRafPrimaryCallbacks: NoneToVoidFunction[] | undefined;\n\n// May result in an immediate execution if called from another `requestAnimationFrame` callback\nexport function fastRaf(callback: NoneToVoidFunction, isPrimary = false) {\n if (!fastRafCallbacks) {\n fastRafCallbacks = isPrimary ? [] : [callback];\n fastRafPrimaryCallbacks = isPrimary ? [callback] : [];\n\n requestAnimationFrame(() => {\n const currentCallbacks = fastRafCallbacks!;\n const currentPrimaryCallbacks = fastRafPrimaryCallbacks!;\n fastRafCallbacks = undefined;\n fastRafPrimaryCallbacks = undefined;\n currentPrimaryCallbacks.forEach((cb) => cb());\n currentCallbacks.forEach((cb) => cb());\n });\n } else if (isPrimary) {\n fastRafPrimaryCallbacks!.push(callback);\n } else {\n fastRafCallbacks.push(callback);\n }\n}\n\nexport function fastRafPrimary(callback: NoneToVoidFunction) {\n fastRaf(callback, true);\n}\n\nlet onTickEndCallbacks: NoneToVoidFunction[] | undefined;\nlet onTickEndPrimaryCallbacks: NoneToVoidFunction[] | undefined;\n\nexport function onTickEnd(callback: NoneToVoidFunction, isPrimary = false) {\n if (!onTickEndCallbacks) {\n onTickEndCallbacks = isPrimary ? [] : [callback];\n onTickEndPrimaryCallbacks = isPrimary ? [callback] : [];\n\n Promise.resolve().then(() => {\n const currentCallbacks = onTickEndCallbacks!;\n const currentPrimaryCallbacks = onTickEndPrimaryCallbacks!;\n onTickEndCallbacks = undefined;\n onTickEndPrimaryCallbacks = undefined;\n currentPrimaryCallbacks.forEach((cb) => cb());\n currentCallbacks.forEach((cb) => cb());\n });\n } else if (isPrimary) {\n onTickEndPrimaryCallbacks!.push(callback);\n } else {\n onTickEndCallbacks.push(callback);\n }\n}\n\nexport function onTickEndPrimary(callback: NoneToVoidFunction) {\n onTickEnd(callback, true);\n}\n\nlet beforeUnloadCallbacks: NoneToVoidFunction[] | undefined;\n\nexport function onBeforeUnload(callback: NoneToVoidFunction, isLast = false) {\n if (!beforeUnloadCallbacks) {\n beforeUnloadCallbacks = [];\n // eslint-disable-next-line no-restricted-globals\n self.addEventListener('beforeunload', () => {\n beforeUnloadCallbacks!.forEach((cb) => cb());\n });\n }\n\n if (isLast) {\n beforeUnloadCallbacks.push(callback);\n } else {\n beforeUnloadCallbacks.unshift(callback);\n }\n\n return () => {\n beforeUnloadCallbacks = beforeUnloadCallbacks!.filter((cb) => cb !== callback);\n };\n}\n","import { pause } from '../util/schedulers';\nimport generateIdFor from '../util/generateIdFor';\nimport {\n DEBUG,\n MEDIA_CACHE_MAX_BYTES,\n MEDIA_PROGRESSIVE_CACHE_DISABLED,\n MEDIA_PROGRESSIVE_CACHE_NAME,\n} from '../config';\n\ndeclare const self: ServiceWorkerGlobalScope;\n\ntype PartInfo = {\n type: 'PartInfo';\n arrayBuffer: ArrayBuffer;\n mimeType: 'string';\n fullSize: number;\n};\n\ntype RequestStates = {\n resolve: (response: PartInfo) => void;\n reject: () => void;\n};\n\nconst MB = 1024 * 1024;\nconst DEFAULT_PART_SIZE = 0.5 * MB;\nconst MAX_END_TO_CACHE = 2 * MB - 1; // We only cache the first 2 MB of each file\nconst PART_TIMEOUT = 60000;\n\nconst requestStates = new Map<string, RequestStates>();\n\nexport async function respondForProgressive(e: FetchEvent) {\n const { url } = e.request;\n const range = e.request.headers.get('range');\n const bytes = /^bytes=(\\d+)-(\\d+)?$/g.exec(range || '')!;\n const start = Number(bytes[1]);\n const originalEnd = Number(bytes[2]);\n\n let end = originalEnd;\n if (!end || (end - start + 1) > DEFAULT_PART_SIZE) {\n end = start + DEFAULT_PART_SIZE - 1;\n }\n\n // Optimization for Safari\n if (start === 0 && end === 1) {\n const match = e.request.url.match(/fileSize=(\\d+)&mimeType=([\\w/]+)/);\n const fileSize = match && Number(match[1]);\n const mimeType = match?.[2];\n\n if (fileSize && mimeType) {\n return new Response(new Uint8Array(2).buffer, {\n status: 206,\n statusText: 'Partial Content',\n headers: [\n ['Content-Range', `bytes 0-1/${fileSize}`],\n ['Accept-Ranges', 'bytes'],\n ['Content-Length', '2'],\n ['Content-Type', mimeType],\n ],\n });\n }\n }\n\n const cacheKey = `${url}?start=${start}&end=${end}`;\n const [cachedArrayBuffer, cachedHeaders] = !MEDIA_PROGRESSIVE_CACHE_DISABLED ? await fetchFromCache(cacheKey) : [];\n\n if (DEBUG) {\n // eslint-disable-next-line no-console\n console.log(\n `FETCH PROGRESSIVE ${cacheKey} (request: ${start}-${originalEnd}) CACHED: ${Boolean(cachedArrayBuffer)}`,\n );\n }\n\n if (cachedArrayBuffer) {\n return new Response(cachedArrayBuffer, {\n status: 206,\n statusText: 'Partial Content',\n headers: cachedHeaders,\n });\n }\n\n let partInfo;\n try {\n partInfo = await requestPart(e, { url, start, end });\n } catch (err) {\n if (DEBUG) {\n // eslint-disable-next-line no-console\n console.error('FETCH PROGRESSIVE', err);\n }\n }\n\n if (!partInfo) {\n return new Response('', {\n status: 500,\n statusText: 'Failed to fetch progressive part',\n });\n }\n\n const { arrayBuffer, fullSize, mimeType } = partInfo;\n\n const partSize = Math.min(end - start + 1, arrayBuffer.byteLength);\n end = start + partSize - 1;\n const arrayBufferPart = arrayBuffer.slice(0, partSize);\n const headers = [\n ['Content-Range', `bytes ${start}-${end}/${fullSize}`],\n ['Accept-Ranges', 'bytes'],\n ['Content-Length', String(partSize)],\n ['Content-Type', mimeType],\n ];\n\n if (!MEDIA_PROGRESSIVE_CACHE_DISABLED && partSize <= MEDIA_CACHE_MAX_BYTES && end < MAX_END_TO_CACHE) {\n saveToCache(cacheKey, arrayBufferPart, headers);\n }\n\n return new Response(arrayBufferPart, {\n status: 206,\n statusText: 'Partial Content',\n headers,\n });\n}\n\n// We can not cache 206 responses: https://github.com/GoogleChrome/workbox/issues/1644#issuecomment-638741359\nasync function fetchFromCache(cacheKey: string) {\n const cache = await self.caches.open(MEDIA_PROGRESSIVE_CACHE_NAME);\n\n return Promise.all([\n cache.match(`${cacheKey}&type=arrayBuffer`).then((r) => (r ? r.arrayBuffer() : undefined)),\n cache.match(`${cacheKey}&type=headers`).then((r) => (r ? r.json() : undefined)),\n ]);\n}\n\nasync function saveToCache(cacheKey: string, arrayBuffer: ArrayBuffer, headers: HeadersInit) {\n const cache = await self.caches.open(MEDIA_PROGRESSIVE_CACHE_NAME);\n\n return Promise.all([\n cache.put(new Request(`${cacheKey}&type=arrayBuffer`), new Response(arrayBuffer)),\n cache.put(new Request(`${cacheKey}&type=headers`), new Response(JSON.stringify(headers))),\n ]);\n}\n\nexport async function requestPart(\n e: FetchEvent,\n params: { url: string; start: number; end: number },\n): Promise<PartInfo | undefined> {\n const isDownload = params.url.includes('/download/');\n const client = isDownload ? (await self.clients.matchAll())\n .find((c) => c.type === 'window' && c.frameType === 'top-level')\n : await (self.clients.get(e.clientId));\n if (!client) {\n return undefined;\n }\n\n const messageId = generateIdFor(requestStates);\n const requestState = {} as RequestStates;\n\n let isResolved = false;\n const promise = Promise.race([\n pause(PART_TIMEOUT).then(() => (isResolved ? undefined : Promise.reject(new Error('ERROR_PART_TIMEOUT')))),\n new Promise<PartInfo>((resolve, reject) => {\n Object.assign(requestState, { resolve, reject });\n }),\n ]);\n\n requestStates.set(messageId, requestState);\n promise\n .catch(() => undefined)\n .finally(() => {\n requestStates.delete(messageId);\n isResolved = true;\n });\n\n client.postMessage({\n type: 'requestPart',\n messageId,\n params,\n });\n\n return promise;\n}\n\nself.addEventListener('message', (e) => {\n const { type, messageId, result } = e.data as {\n type: string;\n messageId: string;\n result: PartInfo;\n };\n\n if (type === 'partResponse') {\n const requestState = requestStates.get(messageId);\n if (requestState) {\n requestState.resolve(result);\n }\n }\n});\n","const generateIdFor = (store: AnyLiteral) => {\n let id;\n\n do {\n id = String(Math.random()).replace('0.', 'id');\n } while (store.hasOwnProperty(id));\n\n return id;\n};\n\nexport default generateIdFor;\n","import { DEBUG } from '../config';\nimport { requestPart } from './progressive';\n\nconst DOWNLOAD_PART_SIZE = 1024 * 1024;\nconst TEST_PART_SIZE = 64 * 1024;\n\nconst QUEUE_SIZE = 8;\n\nclass FilePartQueue<T> {\n queue: Promise<T>[];\n\n constructor() {\n this.queue = [];\n }\n\n push(task: Promise<T>) {\n this.queue.push(task);\n }\n\n async pop(): Promise<T> {\n const result = await this.queue.shift()!;\n return result;\n }\n\n get size() {\n return this.queue.length;\n }\n}\n\nexport async function respondForDownload(e: FetchEvent) {\n const { url } = e.request;\n\n let partInfo;\n try {\n partInfo = await requestPart(e, { url, start: 0, end: TEST_PART_SIZE });\n } catch (err) {\n if (DEBUG) {\n // eslint-disable-next-line no-console\n console.error('FETCH DOWNLOAD', err);\n }\n }\n\n if (!partInfo) {\n return new Response('', {\n status: 500,\n statusText: 'Failed to fetch file to download',\n });\n }\n\n const matchedFilename = e.request.url.match(/filename=(.*)/);\n const filenameHeader = matchedFilename ? `filename=\"${decodeURIComponent(matchedFilename[1])}\"` : '';\n const { fullSize, mimeType } = partInfo;\n\n const headers = [\n ['Content-Length', String(fullSize)],\n ['Content-Type', mimeType],\n ['Content-Disposition', `attachment; ${filenameHeader}`],\n ];\n\n const queue = new FilePartQueue<ArrayBuffer | undefined>();\n const enqueue = (offset: number) => {\n queue.push(requestPart(e, { url, start: offset, end: offset + DOWNLOAD_PART_SIZE - 1 })\n .then((part) => part?.arrayBuffer));\n return offset + DOWNLOAD_PART_SIZE;\n };\n let lastOffset = 0;\n const stream = new ReadableStream({\n start() {\n for (let i = 0; i < QUEUE_SIZE; i++) {\n if (lastOffset >= fullSize) break;\n lastOffset = enqueue(lastOffset);\n }\n },\n\n async pull(controller) {\n const buffer = await queue.pop();\n if (!buffer) {\n controller.close();\n return;\n }\n controller.enqueue(new Uint8Array(buffer));\n\n if (buffer.byteLength < DOWNLOAD_PART_SIZE) {\n controller.close();\n return;\n }\n\n if (lastOffset < fullSize) {\n lastOffset = enqueue(lastOffset);\n }\n },\n });\n\n return new Response(stream, {\n status: 200,\n statusText: 'OK',\n headers,\n });\n}\n","import { ASSET_CACHE_NAME } from '../config';\nimport { pause } from '../util/schedulers';\n\ndeclare const self: ServiceWorkerGlobalScope;\n\n// An attempt to fix freezing UI on iOS\nconst CACHE_TIMEOUT = 3000;\n\nexport async function respondWithCache(e: FetchEvent) {\n const cacheResult = await withTimeout(async () => {\n const cache = await self.caches.open(ASSET_CACHE_NAME);\n const cached = await cache.match(e.request);\n\n return { cache, cached };\n }, CACHE_TIMEOUT);\n\n const { cache, cached } = cacheResult || {};\n\n if (cache && cached) {\n if (cached.ok) {\n return cached;\n } else {\n await cache.delete(e.request);\n }\n }\n\n const remote = await fetch(e.request);\n\n if (remote.ok && cache) {\n cache.put(e.request, remote.clone());\n }\n\n return remote;\n}\n\nasync function withTimeout<T>(cb: () => Promise<T>, timeout: number) {\n let isResolved = false;\n\n try {\n return await Promise.race([\n pause(timeout).then(() => (isResolved ? undefined : Promise.reject(new Error('TIMEOUT')))),\n cb(),\n ]);\n } catch (err) {\n // eslint-disable-next-line no-console\n console.error(err);\n return undefined;\n } finally {\n isResolved = true;\n }\n}\n\nexport function clearAssetCache() {\n return self.caches.delete(ASSET_CACHE_NAME);\n}\n","import { APP_NAME, DEBUG, DEBUG_MORE } from '../config';\n\ndeclare const self: ServiceWorkerGlobalScope;\n\nenum Boolean {\n True = '1',\n False = '0',\n}\n\ntype PushData = {\n custom: {\n msg_id?: string;\n channel_id?: string;\n chat_id?: string;\n from_id?: string;\n };\n mute: Boolean;\n badge: Boolean;\n loc_key: string;\n loc_args: string[];\n random_id: number;\n title: string;\n description: string;\n};\n\ntype NotificationData = {\n messageId?: number;\n chatId?: string;\n title: string;\n body: string;\n icon?: string;\n reaction?: string;\n shouldReplaceHistory?: boolean;\n};\n\ntype FocusMessageData = {\n chatId?: string;\n messageId?: number;\n reaction?: string;\n shouldReplaceHistory?: boolean;\n};\n\ntype CloseNotificationData = {\n lastReadInboxMessageId?: number;\n chatId: string;\n};\n\nlet lastSyncAt = new Date().valueOf();\nconst shownNotifications = new Set();\nconst clickBuffer: Record<string, NotificationData> = {};\n\nfunction getPushData(e: PushEvent | Notification): PushData | undefined {\n try {\n return e.data.json();\n } catch (error) {\n if (DEBUG) {\n // eslint-disable-next-line no-console\n console.log('[SW] Unable to parse push notification data', e.data);\n }\n return undefined;\n }\n}\n\nfunction getChatId(data: PushData) {\n if (data.custom.from_id) {\n return data.custom.from_id;\n }\n\n // Chats and channels have “negative” IDs\n if (data.custom.chat_id || data.custom.channel_id) {\n return `-${data.custom.chat_id || data.custom.channel_id}`;\n }\n\n return undefined;\n}\n\nfunction getMessageId(data: PushData) {\n if (!data.custom.msg_id) return undefined;\n return parseInt(data.custom.msg_id, 10);\n}\n\nfunction getNotificationData(data: PushData): NotificationData {\n return {\n chatId: getChatId(data),\n messageId: getMessageId(data),\n title: data.title || APP_NAME,\n body: data.description,\n };\n}\n\nasync function getClients() {\n const appUrl = new URL(self.registration.scope).origin;\n const clients = await self.clients.matchAll({ type: 'window' }) as WindowClient[];\n return clients.filter((client) => {\n return new URL(client.url).origin === appUrl;\n });\n}\n\nasync function playNotificationSound(id: string) {\n const clients = await getClients();\n const client = clients[0];\n if (!client) return;\n client.postMessage({\n type: 'playNotificationSound',\n payload: { id },\n });\n}\n\nfunction showNotification({\n chatId,\n messageId,\n body,\n title,\n icon,\n reaction,\n shouldReplaceHistory,\n}: NotificationData) {\n const isFirstBatch = new Date().valueOf() - lastSyncAt < 1000;\n const tag = String(isFirstBatch ? 0 : chatId || 0);\n const options: NotificationOptions = {\n body,\n data: {\n chatId,\n messageId,\n reaction,\n count: 1,\n shouldReplaceHistory,\n },\n icon: icon || 'icon-192x192.png',\n badge: 'icon-192x192.png',\n tag,\n vibrate: [200, 100, 200],\n };\n\n return Promise.all([\n // TODO Remove condition when reaction badges are implemented\n !reaction ? playNotificationSound(String(messageId) || chatId || '') : undefined,\n self.registration.showNotification(title, options),\n ]);\n}\n\nasync function closeNotifications({\n chatId,\n lastReadInboxMessageId,\n}: CloseNotificationData) {\n const notifications = await self.registration.getNotifications();\n const lastMessageId = lastReadInboxMessageId || Number.MAX_VALUE;\n notifications.forEach((notification) => {\n if (\n notification.tag === '0'\n || (notification.data.chatId === chatId && notification.data.messageId <= lastMessageId)\n ) {\n notification.close();\n }\n });\n}\n\nexport function handlePush(e: PushEvent) {\n if (DEBUG) {\n // eslint-disable-next-line no-console\n console.log('[SW] Push received event', e);\n if (e.data) {\n // eslint-disable-next-line no-console\n console.log('[SW] Push received with data', e.data.json());\n }\n }\n\n const data = getPushData(e);\n\n // Do not show muted notifications\n if (!data || data.mute === Boolean.True) return;\n\n const notification = getNotificationData(data);\n\n // Don't show already triggered notification\n if (shownNotifications.has(notification.messageId)) {\n shownNotifications.delete(notification.messageId);\n return;\n }\n\n e.waitUntil(showNotification(notification));\n}\n\nasync function focusChatMessage(client: WindowClient, data: FocusMessageData) {\n if (!data.chatId) return;\n client.postMessage({\n type: 'focusMessage',\n payload: data,\n });\n if (!client.focused) {\n // Catch \"focus not allowed\" DOM Exceptions\n try {\n await client.focus();\n } catch (error) {\n if (DEBUG) {\n // eslint-disable-next-line no-console\n console.warn('[SW] ', error);\n }\n }\n }\n}\n\nexport function handleNotificationClick(e: NotificationEvent) {\n const appUrl = self.registration.scope;\n e.notification.close(); // Android needs explicit close.\n const { data } = e.notification;\n const notifyClients = async () => {\n const clients = await getClients();\n await Promise.all(clients.map((client) => {\n clickBuffer[client.id] = data;\n return focusChatMessage(client, data);\n }));\n if (!self.clients.openWindow || clients.length > 0) return undefined;\n // Store notification data for default client (fix for android)\n clickBuffer[0] = data;\n // If there is no opened client we need to open one and wait until it is fully loaded\n try {\n const newClient = await self.clients.openWindow(appUrl);\n if (newClient) {\n // Store notification data until client is fully loaded\n clickBuffer[newClient.id] = data;\n }\n } catch (error) {\n if (DEBUG) {\n // eslint-disable-next-line no-console\n console.warn('[SW] ', error);\n }\n }\n return undefined;\n };\n e.waitUntil(notifyClients());\n}\n\nexport function handleClientMessage(e: ExtendableMessageEvent) {\n if (DEBUG_MORE) {\n // eslint-disable-next-line no-console\n console.log('[SW] New message from client', e);\n }\n if (!e.data) return;\n const source = e.source as WindowClient;\n if (e.data.type === 'clientReady') {\n // focus on chat message when client is fully ready\n const data = clickBuffer[source.id] || clickBuffer[0];\n if (data) {\n delete clickBuffer[source.id];\n delete clickBuffer[0];\n e.waitUntil(focusChatMessage(source, data));\n }\n }\n if (e.data.type === 'showMessageNotification') {\n // store messageId for already shown notification\n const notification: NotificationData = e.data.payload;\n e.waitUntil((async () => {\n // Close existing notification if it is already shown\n if (notification.chatId) {\n const notifications = await self.registration.getNotifications({ tag: notification.chatId });\n notifications.forEach((n) => n.close());\n }\n // Mark this notification as shown if it was handled locally\n shownNotifications.add(notification.messageId);\n return showNotification(notification);\n })());\n }\n\n if (e.data.type === 'closeMessageNotifications') {\n e.waitUntil(closeNotifications(e.data.payload));\n }\n}\n\nself.addEventListener('sync', () => {\n lastSyncAt = Date.now();\n});\n","import { DEBUG } from './config';\nimport { respondForProgressive } from './serviceWorker/progressive';\nimport { respondForDownload } from './serviceWorker/download';\nimport { respondWithCache, clearAssetCache } from './serviceWorker/assetCache';\nimport { handlePush, handleNotificationClick, handleClientMessage } from './serviceWorker/pushNotification';\nimport { pause } from './util/schedulers';\n\ndeclare const self: ServiceWorkerGlobalScope;\n\nconst ASSET_CACHE_PATTERN = /[\\da-f]{20}.*\\.(js|css|woff2?|svg|png|jpg|jpeg|tgs|json|wasm)$/;\nconst ACTIVATE_TIMEOUT = 3000;\n\nself.addEventListener('install', (e) => {\n if (DEBUG) {\n // eslint-disable-next-line no-console\n console.log('ServiceWorker installed');\n }\n\n // Activate worker immediately\n e.waitUntil(self.skipWaiting());\n});\n\nself.addEventListener('activate', (e) => {\n if (DEBUG) {\n // eslint-disable-next-line no-console\n console.log('ServiceWorker activated');\n }\n\n e.waitUntil(\n Promise.race([\n // An attempt to fix freezing UI on iOS\n pause(ACTIVATE_TIMEOUT),\n Promise.all([\n clearAssetCache(),\n // Become available to all pages\n self.clients.claim(),\n ]),\n ]),\n );\n});\n\nself.addEventListener('fetch', (e: FetchEvent) => {\n const { url } = e.request;\n\n if (url.includes('/progressive/')) {\n e.respondWith(respondForProgressive(e));\n return true;\n }\n\n if (url.includes('/download/')) {\n e.respondWith(respondForDownload(e));\n return true;\n }\n\n if (url.startsWith('http') && url.match(ASSET_CACHE_PATTERN)) {\n e.respondWith(respondWithCache(e));\n return true;\n }\n\n return false;\n});\n\nself.addEventListener('push', handlePush);\nself.addEventListener('notificationclick', handleNotificationClick);\nself.addEventListener('message', handleClientMessage);\n"],"names":["MEDIA_PROGRESSIVE_CACHE_NAME","ASSET_CACHE_NAME","SUPPORTED_IMAGE_CONTENT_TYPES","window","innerHeight","Math","round","Set","SUPPORTED_VIDEO_CONTENT_TYPES","pause","ms","Promise","resolve","setTimeout","DEFAULT_PART_SIZE","requestStates","Map","async","requestPart","e","params","client","url","includes","self","clients","matchAll","find","c","type","frameType","get","clientId","messageId","store","id","String","random","replace","hasOwnProperty","generateIdFor","requestState","isResolved","promise","race","then","undefined","reject","Error","Object","assign","set","catch","finally","delete","postMessage","addEventListener","result","data","DOWNLOAD_PART_SIZE","FilePartQueue","constructor","this","queue","push","task","shift","size","length","respondWithCache","cacheResult","cb","timeout","cache","caches","open","cached","match","request","err","console","error","withTimeout","ok","remote","fetch","put","clone","Boolean","lastSyncAt","Date","valueOf","shownNotifications","clickBuffer","getChatId","custom","from_id","chat_id","channel_id","getMessageId","msg_id","parseInt","getClients","appUrl","URL","registration","scope","origin","filter","playNotificationSound","payload","showNotification","chatId","body","title","icon","reaction","shouldReplaceHistory","isFirstBatch","options","count","badge","tag","vibrate","all","focusChatMessage","focused","focus","now","ASSET_CACHE_PATTERN","waitUntil","skipWaiting","claim","respondWith","range","headers","bytes","exec","start","Number","end","fileSize","mimeType","Response","Uint8Array","buffer","status","statusText","cacheKey","cachedArrayBuffer","cachedHeaders","r","arrayBuffer","json","fetchFromCache","partInfo","fullSize","partSize","min","byteLength","arrayBufferPart","slice","Request","JSON","stringify","saveToCache","respondForProgressive","matchedFilename","filenameHeader","decodeURIComponent","enqueue","offset","part","lastOffset","stream","ReadableStream","i","controller","pop","close","respondForDownload","startsWith","getPushData","mute","True","notification","description","getNotificationData","has","map","openWindow","newClient","notifyClients","source","getNotifications","forEach","n","add","lastReadInboxMessageId","notifications","lastMessageId","MAX_VALUE","closeNotifications"],"sourceRoot":""}