From 72b530aeb39bfb86f370fde7842387831dd82767 Mon Sep 17 00:00:00 2001 From: Eduard Kuzmenko Date: Sun, 27 Feb 2022 20:30:12 +0200 Subject: [PATCH] Redirect click from attachment div to preloader Auto-download: Fix downloading thumb of video --- src/components/chat/bubbles.ts | 13 ++++++++++--- src/components/wrappers.ts | 12 ++++++------ 2 files changed, 16 insertions(+), 9 deletions(-) diff --git a/src/components/chat/bubbles.ts b/src/components/chat/bubbles.ts index 9370d068..8a6da5ca 100644 --- a/src/components/chat/bubbles.ts +++ b/src/components/chat/bubbles.ts @@ -60,7 +60,7 @@ import { toast } from "../toast"; import { getElementByPoint } from "../../helpers/dom/getElementByPoint"; import { getMiddleware } from "../../helpers/middleware"; import { cancelEvent } from "../../helpers/dom/cancelEvent"; -import { attachClickEvent } from "../../helpers/dom/clickEvent"; +import { attachClickEvent, simulateClickEvent } from "../../helpers/dom/clickEvent"; import htmlToDocumentFragment from "../../helpers/dom/htmlToDocumentFragment"; import positionElementByIndex from "../../helpers/dom/positionElementByIndex"; import reflowScrollableElement from "../../helpers/dom/reflowScrollableElement"; @@ -1387,6 +1387,13 @@ export default class ChatBubbles { return; } + const preloader = (groupedItem || bubble).querySelector('.preloader-container'); + if(preloader) { + simulateClickEvent(preloader); + cancelEvent(e); + return; + } + const SINGLE_MEDIA_CLASSNAME = 'webpage'; const isSingleMedia = bubble.classList.contains(SINGLE_MEDIA_CLASSNAME); @@ -3212,7 +3219,7 @@ export default class ChatBubbles { isOut, group: CHAT_ANIMATION_GROUP, loadPromises, - autoDownloadSize: this.chat.autoDownload.video, + autoDownload: this.chat.autoDownload, }); //} } else { @@ -3401,7 +3408,7 @@ export default class ChatBubbles { middleware: this.getMiddleware(), group: CHAT_ANIMATION_GROUP, loadPromises, - autoDownloadSize: this.chat.autoDownload.video, + autoDownload: this.chat.autoDownload, searchContext: isRound ? { peerId: this.peerId, inputFilter: {_: 'inputMessagesFilterRoundVoice'}, diff --git a/src/components/wrappers.ts b/src/components/wrappers.ts index c51d304a..fe2c4c1a 100644 --- a/src/components/wrappers.ts +++ b/src/components/wrappers.ts @@ -83,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, autoDownloadSize, size, searchContext}: { +export function wrapVideo({doc, container, message, boxWidth, boxHeight, withTail, isOut, middleware, lazyLoadQueue, noInfo, group, onlyPreview, withoutPreloader, loadPromises, noPlayButton, size, searchContext, autoDownload}: { doc: MyDocument, container?: HTMLElement, message?: Message.message, @@ -99,10 +99,11 @@ export function wrapVideo({doc, container, message, boxWidth, boxHeight, withTai onlyPreview?: boolean, withoutPreloader?: boolean, loadPromises?: Promise[], - autoDownloadSize?: number, + autoDownload?: ChatAutoDownloadSettings, size?: PhotoSize, searchContext?: MediaSearchContext, }) { + const autoDownloadSize = autoDownload?.video; let noAutoDownload = autoDownloadSize === 0; const isAlbumItem = !(boxWidth && boxHeight); const canAutoplay = /* doc.sticker || */( @@ -373,7 +374,7 @@ export function wrapVideo({doc, container, message, boxWidth, boxHeight, withTai middleware, withoutPreloader: true, loadPromises, - autoDownloadSize, + autoDownloadSize: autoDownload?.photo, size }); @@ -1982,7 +1983,6 @@ export function wrapAlbum({groupId, attachmentDiv, middleware, uploading, lazyLo div.dataset.peerId = '' + message.peerId; const mediaDiv = div.firstElementChild as HTMLElement; const isPhoto = media._ === 'photo'; - const autoDownloadSize = autoDownload ? autoDownload[isPhoto ? 'photo' : 'video'] : undefined; if(isPhoto) { wrapPhoto({ photo: media, @@ -1995,7 +1995,7 @@ export function wrapAlbum({groupId, attachmentDiv, middleware, uploading, lazyLo middleware, size, loadPromises, - autoDownloadSize + autoDownloadSize: autoDownload.photo }); } else { wrapVideo({ @@ -2009,7 +2009,7 @@ export function wrapAlbum({groupId, attachmentDiv, middleware, uploading, lazyLo lazyLoadQueue, middleware, loadPromises, - autoDownloadSize + autoDownload }); } });