|
|
@ -9,7 +9,6 @@ import { getEmojiToneIndex } from '../vendor/emoji'; |
|
|
|
import { deferredPromise } from '../helpers/cancellablePromise'; |
|
|
|
import { deferredPromise } from '../helpers/cancellablePromise'; |
|
|
|
import { formatFullSentTime } from '../helpers/date'; |
|
|
|
import { formatFullSentTime } from '../helpers/date'; |
|
|
|
import mediaSizes, { ScreenSize } from '../helpers/mediaSizes'; |
|
|
|
import mediaSizes, { ScreenSize } from '../helpers/mediaSizes'; |
|
|
|
import { formatBytes } from '../helpers/number'; |
|
|
|
|
|
|
|
import { IS_SAFARI } from '../environment/userAgent'; |
|
|
|
import { IS_SAFARI } from '../environment/userAgent'; |
|
|
|
import { Message, PhotoSize, StickerSet } from '../layer'; |
|
|
|
import { Message, PhotoSize, StickerSet } from '../layer'; |
|
|
|
import appDocsManager, { MyDocument } from "../lib/appManagers/appDocsManager"; |
|
|
|
import appDocsManager, { MyDocument } from "../lib/appManagers/appDocsManager"; |
|
|
@ -56,6 +55,8 @@ import throttle from '../helpers/schedulers/throttle'; |
|
|
|
import { SendMessageEmojiInteractionData } from '../types'; |
|
|
|
import { SendMessageEmojiInteractionData } from '../types'; |
|
|
|
import IS_VIBRATE_SUPPORTED from '../environment/vibrateSupport'; |
|
|
|
import IS_VIBRATE_SUPPORTED from '../environment/vibrateSupport'; |
|
|
|
import Row from './row'; |
|
|
|
import Row from './row'; |
|
|
|
|
|
|
|
import { ChatAutoDownloadSettings } from '../helpers/autoDownload'; |
|
|
|
|
|
|
|
import formatBytes from '../helpers/formatBytes'; |
|
|
|
|
|
|
|
|
|
|
|
const MAX_VIDEO_AUTOPLAY_SIZE = 50 * 1024 * 1024; // 50 MB
|
|
|
|
const MAX_VIDEO_AUTOPLAY_SIZE = 50 * 1024 * 1024; // 50 MB
|
|
|
|
|
|
|
|
|
|
|
@ -82,7 +83,7 @@ mediaSizes.addEventListener('changeScreen', (from, to) => { |
|
|
|
} |
|
|
|
} |
|
|
|
}); |
|
|
|
}); |
|
|
|
|
|
|
|
|
|
|
|
export function wrapVideo({doc, container, message, boxWidth, boxHeight, withTail, isOut, middleware, lazyLoadQueue, noInfo, group, onlyPreview, withoutPreloader, loadPromises, noPlayButton, noAutoDownload, size, searchContext}: { |
|
|
|
export function wrapVideo({doc, container, message, boxWidth, boxHeight, withTail, isOut, middleware, lazyLoadQueue, noInfo, group, onlyPreview, withoutPreloader, loadPromises, noPlayButton, autoDownloadSize, size, searchContext}: { |
|
|
|
doc: MyDocument, |
|
|
|
doc: MyDocument, |
|
|
|
container?: HTMLElement, |
|
|
|
container?: HTMLElement, |
|
|
|
message?: Message.message, |
|
|
|
message?: Message.message, |
|
|
@ -98,10 +99,11 @@ export function wrapVideo({doc, container, message, boxWidth, boxHeight, withTai |
|
|
|
onlyPreview?: boolean, |
|
|
|
onlyPreview?: boolean, |
|
|
|
withoutPreloader?: boolean, |
|
|
|
withoutPreloader?: boolean, |
|
|
|
loadPromises?: Promise<any>[], |
|
|
|
loadPromises?: Promise<any>[], |
|
|
|
noAutoDownload?: boolean, |
|
|
|
autoDownloadSize?: number, |
|
|
|
size?: PhotoSize, |
|
|
|
size?: PhotoSize, |
|
|
|
searchContext?: MediaSearchContext, |
|
|
|
searchContext?: MediaSearchContext, |
|
|
|
}) { |
|
|
|
}) { |
|
|
|
|
|
|
|
let noAutoDownload = autoDownloadSize === 0; |
|
|
|
const isAlbumItem = !(boxWidth && boxHeight); |
|
|
|
const isAlbumItem = !(boxWidth && boxHeight); |
|
|
|
const canAutoplay = /* doc.sticker || */( |
|
|
|
const canAutoplay = /* doc.sticker || */( |
|
|
|
( |
|
|
|
( |
|
|
@ -163,7 +165,7 @@ export function wrapVideo({doc, container, message, boxWidth, boxHeight, withTai |
|
|
|
middleware, |
|
|
|
middleware, |
|
|
|
withoutPreloader, |
|
|
|
withoutPreloader, |
|
|
|
loadPromises, |
|
|
|
loadPromises, |
|
|
|
noAutoDownload, |
|
|
|
autoDownloadSize, |
|
|
|
size |
|
|
|
size |
|
|
|
}); |
|
|
|
}); |
|
|
|
|
|
|
|
|
|
|
@ -371,7 +373,7 @@ export function wrapVideo({doc, container, message, boxWidth, boxHeight, withTai |
|
|
|
middleware, |
|
|
|
middleware, |
|
|
|
withoutPreloader: true, |
|
|
|
withoutPreloader: true, |
|
|
|
loadPromises, |
|
|
|
loadPromises, |
|
|
|
noAutoDownload, |
|
|
|
autoDownloadSize, |
|
|
|
size |
|
|
|
size |
|
|
|
}); |
|
|
|
}); |
|
|
|
|
|
|
|
|
|
|
@ -550,7 +552,7 @@ rootScope.addEventListener('download_start', (docId) => { |
|
|
|
}); |
|
|
|
}); |
|
|
|
}); |
|
|
|
}); |
|
|
|
|
|
|
|
|
|
|
|
export function wrapDocument({message, withTime, fontWeight, voiceAsMusic, showSender, searchContext, loadPromises, noAutoDownload, lazyLoadQueue}: { |
|
|
|
export function wrapDocument({message, withTime, fontWeight, voiceAsMusic, showSender, searchContext, loadPromises, autoDownloadSize, lazyLoadQueue}: { |
|
|
|
message: any, |
|
|
|
message: any, |
|
|
|
withTime?: boolean, |
|
|
|
withTime?: boolean, |
|
|
|
fontWeight?: number, |
|
|
|
fontWeight?: number, |
|
|
@ -558,10 +560,11 @@ export function wrapDocument({message, withTime, fontWeight, voiceAsMusic, showS |
|
|
|
showSender?: boolean, |
|
|
|
showSender?: boolean, |
|
|
|
searchContext?: MediaSearchContext, |
|
|
|
searchContext?: MediaSearchContext, |
|
|
|
loadPromises?: Promise<any>[], |
|
|
|
loadPromises?: Promise<any>[], |
|
|
|
noAutoDownload?: boolean, |
|
|
|
autoDownloadSize?: number, |
|
|
|
lazyLoadQueue?: LazyLoadQueue |
|
|
|
lazyLoadQueue?: LazyLoadQueue |
|
|
|
}): HTMLElement { |
|
|
|
}): HTMLElement { |
|
|
|
if(!fontWeight) fontWeight = 500; |
|
|
|
if(!fontWeight) fontWeight = 500; |
|
|
|
|
|
|
|
const noAutoDownload = autoDownloadSize === 0; |
|
|
|
|
|
|
|
|
|
|
|
const doc = (message.media.document || message.media.webpage.document) as MyDocument; |
|
|
|
const doc = (message.media.document || message.media.webpage.document) as MyDocument; |
|
|
|
const uploading = message.pFlags.is_outgoing && message.media?.preloader; |
|
|
|
const uploading = message.pFlags.is_outgoing && message.media?.preloader; |
|
|
@ -682,7 +685,7 @@ export function wrapDocument({message, withTime, fontWeight, voiceAsMusic, showS |
|
|
|
} |
|
|
|
} |
|
|
|
}; |
|
|
|
}; |
|
|
|
|
|
|
|
|
|
|
|
const load = (e: Event) => { |
|
|
|
const load = (e?: Event) => { |
|
|
|
const save = !e || e.isTrusted; |
|
|
|
const save = !e || e.isTrusted; |
|
|
|
const doc = appDocsManager.getDoc(docDiv.dataset.docId); |
|
|
|
const doc = appDocsManager.getDoc(docDiv.dataset.docId); |
|
|
|
let download: DownloadBlob; |
|
|
|
let download: DownloadBlob; |
|
|
@ -690,13 +693,16 @@ export function wrapDocument({message, withTime, fontWeight, voiceAsMusic, showS |
|
|
|
if(!save) { |
|
|
|
if(!save) { |
|
|
|
download = appDocsManager.downloadDoc(doc, queueId); |
|
|
|
download = appDocsManager.downloadDoc(doc, queueId); |
|
|
|
} else if(doc.type === 'pdf') { |
|
|
|
} else if(doc.type === 'pdf') { |
|
|
|
|
|
|
|
const canOpenAfter = appDocsManager.downloading.has(doc.id) || cacheContext.downloaded; |
|
|
|
download = appDocsManager.downloadDoc(doc, queueId); |
|
|
|
download = appDocsManager.downloadDoc(doc, queueId); |
|
|
|
download.then(() => { |
|
|
|
if(canOpenAfter) { |
|
|
|
setTimeout(() => { // wait for preloader animation end
|
|
|
|
download.then(() => { |
|
|
|
const url = appDownloadManager.getCacheContext(doc).url; |
|
|
|
setTimeout(() => { // wait for preloader animation end
|
|
|
|
window.open(url); |
|
|
|
const url = appDownloadManager.getCacheContext(doc).url; |
|
|
|
}, rootScope.settings.animationsEnabled ? 250 : 0); |
|
|
|
window.open(url); |
|
|
|
}); |
|
|
|
}, rootScope.settings.animationsEnabled ? 250 : 0); |
|
|
|
|
|
|
|
}); |
|
|
|
|
|
|
|
} |
|
|
|
} else if(MEDIA_MIME_TYPES_SUPPORTED.has(doc.mime_type) && doc.thumbs?.length) { |
|
|
|
} else if(MEDIA_MIME_TYPES_SUPPORTED.has(doc.mime_type) && doc.thumbs?.length) { |
|
|
|
download = appDocsManager.downloadDoc(doc, queueId); |
|
|
|
download = appDocsManager.downloadDoc(doc, queueId); |
|
|
|
} else { |
|
|
|
} else { |
|
|
@ -726,6 +732,10 @@ export function wrapDocument({message, withTime, fontWeight, voiceAsMusic, showS |
|
|
|
preloader.setManual(); |
|
|
|
preloader.setManual(); |
|
|
|
preloader.attach(downloadDiv); |
|
|
|
preloader.attach(downloadDiv); |
|
|
|
preloader.setDownloadFunction(load); |
|
|
|
preloader.setDownloadFunction(load); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if(autoDownloadSize !== undefined && autoDownloadSize >= doc.size) { |
|
|
|
|
|
|
|
simulateClickEvent(preloader.preloader); |
|
|
|
|
|
|
|
} |
|
|
|
} else { |
|
|
|
} else { |
|
|
|
preloader.attach(downloadDiv); |
|
|
|
preloader.attach(downloadDiv); |
|
|
|
message.media.promise.then(onLoad); |
|
|
|
message.media.promise.then(onLoad); |
|
|
@ -802,7 +812,7 @@ export function wrapDocument({message, withTime, fontWeight, voiceAsMusic, showS |
|
|
|
return img; |
|
|
|
return img; |
|
|
|
} */ |
|
|
|
} */ |
|
|
|
|
|
|
|
|
|
|
|
export function wrapPhoto({photo, message, container, boxWidth, boxHeight, withTail, isOut, lazyLoadQueue, middleware, size, withoutPreloader, loadPromises, noAutoDownload, noBlur, noThumb, noFadeIn, blurAfter}: { |
|
|
|
export function wrapPhoto({photo, message, container, boxWidth, boxHeight, withTail, isOut, lazyLoadQueue, middleware, size, withoutPreloader, loadPromises, autoDownloadSize, noBlur, noThumb, noFadeIn, blurAfter}: { |
|
|
|
photo: MyPhoto | MyDocument, |
|
|
|
photo: MyPhoto | MyDocument, |
|
|
|
message?: any, |
|
|
|
message?: any, |
|
|
|
container: HTMLElement, |
|
|
|
container: HTMLElement, |
|
|
@ -815,7 +825,7 @@ export function wrapPhoto({photo, message, container, boxWidth, boxHeight, withT |
|
|
|
size?: PhotoSize, |
|
|
|
size?: PhotoSize, |
|
|
|
withoutPreloader?: boolean, |
|
|
|
withoutPreloader?: boolean, |
|
|
|
loadPromises?: Promise<any>[], |
|
|
|
loadPromises?: Promise<any>[], |
|
|
|
noAutoDownload?: boolean, |
|
|
|
autoDownloadSize?: number, |
|
|
|
noBlur?: boolean, |
|
|
|
noBlur?: boolean, |
|
|
|
noThumb?: boolean, |
|
|
|
noThumb?: boolean, |
|
|
|
noFadeIn?: boolean, |
|
|
|
noFadeIn?: boolean, |
|
|
@ -840,6 +850,8 @@ export function wrapPhoto({photo, message, container, boxWidth, boxHeight, withT |
|
|
|
}; |
|
|
|
}; |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
let noAutoDownload = autoDownloadSize === 0; |
|
|
|
|
|
|
|
|
|
|
|
if(!size) { |
|
|
|
if(!size) { |
|
|
|
if(boxWidth === undefined) boxWidth = mediaSizes.active.regular.width; |
|
|
|
if(boxWidth === undefined) boxWidth = mediaSizes.active.regular.width; |
|
|
|
if(boxHeight === undefined) boxHeight = mediaSizes.active.regular.height; |
|
|
|
if(boxHeight === undefined) boxHeight = mediaSizes.active.regular.height; |
|
|
@ -897,7 +909,7 @@ export function wrapPhoto({photo, message, container, boxWidth, boxHeight, withT |
|
|
|
middleware, |
|
|
|
middleware, |
|
|
|
withoutPreloader, |
|
|
|
withoutPreloader, |
|
|
|
withTail, |
|
|
|
withTail, |
|
|
|
noAutoDownload, |
|
|
|
autoDownloadSize, |
|
|
|
noBlur, |
|
|
|
noBlur, |
|
|
|
noThumb: true, |
|
|
|
noThumb: true, |
|
|
|
blurAfter: true |
|
|
|
blurAfter: true |
|
|
@ -1895,7 +1907,7 @@ export function prepareAlbum(options: { |
|
|
|
} */ |
|
|
|
} */ |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
export function wrapAlbum({groupId, attachmentDiv, middleware, uploading, lazyLoadQueue, isOut, chat, loadPromises, noAutoDownload}: { |
|
|
|
export function wrapAlbum({groupId, attachmentDiv, middleware, uploading, lazyLoadQueue, isOut, chat, loadPromises, autoDownload}: { |
|
|
|
groupId: string, |
|
|
|
groupId: string, |
|
|
|
attachmentDiv: HTMLElement, |
|
|
|
attachmentDiv: HTMLElement, |
|
|
|
middleware?: () => boolean, |
|
|
|
middleware?: () => boolean, |
|
|
@ -1904,7 +1916,7 @@ export function wrapAlbum({groupId, attachmentDiv, middleware, uploading, lazyLo |
|
|
|
isOut: boolean, |
|
|
|
isOut: boolean, |
|
|
|
chat: Chat, |
|
|
|
chat: Chat, |
|
|
|
loadPromises?: Promise<any>[], |
|
|
|
loadPromises?: Promise<any>[], |
|
|
|
noAutoDownload?: boolean, |
|
|
|
autoDownload?: ChatAutoDownloadSettings, |
|
|
|
}) { |
|
|
|
}) { |
|
|
|
const items: {size: PhotoSize.photoSize, media: any, message: any}[] = []; |
|
|
|
const items: {size: PhotoSize.photoSize, media: any, message: any}[] = []; |
|
|
|
|
|
|
|
|
|
|
@ -1939,7 +1951,9 @@ export function wrapAlbum({groupId, attachmentDiv, middleware, uploading, lazyLo |
|
|
|
div.dataset.mid = '' + message.mid; |
|
|
|
div.dataset.mid = '' + message.mid; |
|
|
|
div.dataset.peerId = '' + message.peerId; |
|
|
|
div.dataset.peerId = '' + message.peerId; |
|
|
|
const mediaDiv = div.firstElementChild as HTMLElement; |
|
|
|
const mediaDiv = div.firstElementChild as HTMLElement; |
|
|
|
if(media._ === 'photo') { |
|
|
|
const isPhoto = media._ === 'photo'; |
|
|
|
|
|
|
|
const autoDownloadSize = autoDownload ? autoDownload[isPhoto ? 'photo' : 'video'] : undefined; |
|
|
|
|
|
|
|
if(isPhoto) { |
|
|
|
wrapPhoto({ |
|
|
|
wrapPhoto({ |
|
|
|
photo: media, |
|
|
|
photo: media, |
|
|
|
message, |
|
|
|
message, |
|
|
@ -1951,7 +1965,7 @@ export function wrapAlbum({groupId, attachmentDiv, middleware, uploading, lazyLo |
|
|
|
middleware, |
|
|
|
middleware, |
|
|
|
size, |
|
|
|
size, |
|
|
|
loadPromises, |
|
|
|
loadPromises, |
|
|
|
noAutoDownload |
|
|
|
autoDownloadSize |
|
|
|
}); |
|
|
|
}); |
|
|
|
} else { |
|
|
|
} else { |
|
|
|
wrapVideo({ |
|
|
|
wrapVideo({ |
|
|
@ -1965,13 +1979,13 @@ export function wrapAlbum({groupId, attachmentDiv, middleware, uploading, lazyLo |
|
|
|
lazyLoadQueue, |
|
|
|
lazyLoadQueue, |
|
|
|
middleware, |
|
|
|
middleware, |
|
|
|
loadPromises, |
|
|
|
loadPromises, |
|
|
|
noAutoDownload |
|
|
|
autoDownloadSize |
|
|
|
}); |
|
|
|
}); |
|
|
|
} |
|
|
|
} |
|
|
|
}); |
|
|
|
}); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
export function wrapGroupedDocuments({albumMustBeRenderedFull, message, bubble, messageDiv, chat, loadPromises, noAutoDownload, lazyLoadQueue, searchContext, useSearch}: { |
|
|
|
export function wrapGroupedDocuments({albumMustBeRenderedFull, message, bubble, messageDiv, chat, loadPromises, autoDownloadSize, lazyLoadQueue, searchContext, useSearch}: { |
|
|
|
albumMustBeRenderedFull: boolean, |
|
|
|
albumMustBeRenderedFull: boolean, |
|
|
|
message: any, |
|
|
|
message: any, |
|
|
|
messageDiv: HTMLElement, |
|
|
|
messageDiv: HTMLElement, |
|
|
@ -1979,7 +1993,7 @@ export function wrapGroupedDocuments({albumMustBeRenderedFull, message, bubble, |
|
|
|
uploading?: boolean, |
|
|
|
uploading?: boolean, |
|
|
|
chat: Chat, |
|
|
|
chat: Chat, |
|
|
|
loadPromises?: Promise<any>[], |
|
|
|
loadPromises?: Promise<any>[], |
|
|
|
noAutoDownload?: boolean, |
|
|
|
autoDownloadSize?: number, |
|
|
|
lazyLoadQueue?: LazyLoadQueue, |
|
|
|
lazyLoadQueue?: LazyLoadQueue, |
|
|
|
searchContext?: MediaSearchContext, |
|
|
|
searchContext?: MediaSearchContext, |
|
|
|
useSearch?: boolean, |
|
|
|
useSearch?: boolean, |
|
|
@ -1995,7 +2009,7 @@ export function wrapGroupedDocuments({albumMustBeRenderedFull, message, bubble, |
|
|
|
const div = wrapDocument({ |
|
|
|
const div = wrapDocument({ |
|
|
|
message, |
|
|
|
message, |
|
|
|
loadPromises, |
|
|
|
loadPromises, |
|
|
|
noAutoDownload, |
|
|
|
autoDownloadSize, |
|
|
|
lazyLoadQueue, |
|
|
|
lazyLoadQueue, |
|
|
|
searchContext |
|
|
|
searchContext |
|
|
|
}); |
|
|
|
}); |
|
|
|