Browse Source

Redirect click from attachment div to preloader

Auto-download: Fix downloading thumb of video
master
Eduard Kuzmenko 2 years ago
parent
commit
72b530aeb3
  1. 13
      src/components/chat/bubbles.ts
  2. 12
      src/components/wrappers.ts

13
src/components/chat/bubbles.ts

@ -60,7 +60,7 @@ import { toast } from "../toast";
import { getElementByPoint } from "../../helpers/dom/getElementByPoint"; import { getElementByPoint } from "../../helpers/dom/getElementByPoint";
import { getMiddleware } from "../../helpers/middleware"; import { getMiddleware } from "../../helpers/middleware";
import { cancelEvent } from "../../helpers/dom/cancelEvent"; 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 htmlToDocumentFragment from "../../helpers/dom/htmlToDocumentFragment";
import positionElementByIndex from "../../helpers/dom/positionElementByIndex"; import positionElementByIndex from "../../helpers/dom/positionElementByIndex";
import reflowScrollableElement from "../../helpers/dom/reflowScrollableElement"; import reflowScrollableElement from "../../helpers/dom/reflowScrollableElement";
@ -1387,6 +1387,13 @@ export default class ChatBubbles {
return; return;
} }
const preloader = (groupedItem || bubble).querySelector<HTMLElement>('.preloader-container');
if(preloader) {
simulateClickEvent(preloader);
cancelEvent(e);
return;
}
const SINGLE_MEDIA_CLASSNAME = 'webpage'; const SINGLE_MEDIA_CLASSNAME = 'webpage';
const isSingleMedia = bubble.classList.contains(SINGLE_MEDIA_CLASSNAME); const isSingleMedia = bubble.classList.contains(SINGLE_MEDIA_CLASSNAME);
@ -3212,7 +3219,7 @@ export default class ChatBubbles {
isOut, isOut,
group: CHAT_ANIMATION_GROUP, group: CHAT_ANIMATION_GROUP,
loadPromises, loadPromises,
autoDownloadSize: this.chat.autoDownload.video, autoDownload: this.chat.autoDownload,
}); });
//} //}
} else { } else {
@ -3401,7 +3408,7 @@ export default class ChatBubbles {
middleware: this.getMiddleware(), middleware: this.getMiddleware(),
group: CHAT_ANIMATION_GROUP, group: CHAT_ANIMATION_GROUP,
loadPromises, loadPromises,
autoDownloadSize: this.chat.autoDownload.video, autoDownload: this.chat.autoDownload,
searchContext: isRound ? { searchContext: isRound ? {
peerId: this.peerId, peerId: this.peerId,
inputFilter: {_: 'inputMessagesFilterRoundVoice'}, inputFilter: {_: 'inputMessagesFilterRoundVoice'},

12
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, doc: MyDocument,
container?: HTMLElement, container?: HTMLElement,
message?: Message.message, message?: Message.message,
@ -99,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>[],
autoDownloadSize?: number, autoDownload?: ChatAutoDownloadSettings,
size?: PhotoSize, size?: PhotoSize,
searchContext?: MediaSearchContext, searchContext?: MediaSearchContext,
}) { }) {
const autoDownloadSize = autoDownload?.video;
let noAutoDownload = autoDownloadSize === 0; let noAutoDownload = autoDownloadSize === 0;
const isAlbumItem = !(boxWidth && boxHeight); const isAlbumItem = !(boxWidth && boxHeight);
const canAutoplay = /* doc.sticker || */( const canAutoplay = /* doc.sticker || */(
@ -373,7 +374,7 @@ export function wrapVideo({doc, container, message, boxWidth, boxHeight, withTai
middleware, middleware,
withoutPreloader: true, withoutPreloader: true,
loadPromises, loadPromises,
autoDownloadSize, autoDownloadSize: autoDownload?.photo,
size size
}); });
@ -1982,7 +1983,6 @@ export function wrapAlbum({groupId, attachmentDiv, middleware, uploading, lazyLo
div.dataset.peerId = '' + message.peerId; div.dataset.peerId = '' + message.peerId;
const mediaDiv = div.firstElementChild as HTMLElement; const mediaDiv = div.firstElementChild as HTMLElement;
const isPhoto = media._ === 'photo'; const isPhoto = media._ === 'photo';
const autoDownloadSize = autoDownload ? autoDownload[isPhoto ? 'photo' : 'video'] : undefined;
if(isPhoto) { if(isPhoto) {
wrapPhoto({ wrapPhoto({
photo: media, photo: media,
@ -1995,7 +1995,7 @@ export function wrapAlbum({groupId, attachmentDiv, middleware, uploading, lazyLo
middleware, middleware,
size, size,
loadPromises, loadPromises,
autoDownloadSize autoDownloadSize: autoDownload.photo
}); });
} else { } else {
wrapVideo({ wrapVideo({
@ -2009,7 +2009,7 @@ export function wrapAlbum({groupId, attachmentDiv, middleware, uploading, lazyLo
lazyLoadQueue, lazyLoadQueue,
middleware, middleware,
loadPromises, loadPromises,
autoDownloadSize autoDownload
}); });
} }
}); });

Loading…
Cancel
Save