Browse Source

Save thumb for .webm stickers

master
Eduard Kuzmenko 3 years ago
parent
commit
ff45b07245
  1. 20
      src/components/wrappers.ts
  2. 5
      src/lib/appManagers/appDocsManager.ts

20
src/components/wrappers.ts

@ -1203,7 +1203,7 @@ export function wrapSticker({doc, div, middleware, lazyLoadQueue, group, play, o
let loadThumbPromise = deferredPromise<void>(); let loadThumbPromise = deferredPromise<void>();
let haveThumbCached = false; let haveThumbCached = false;
if((doc.thumbs?.length || doc.stickerCachedThumbs) && !div.firstElementChild && (!downloaded || stickerType === 2 || onlyThumb) && withThumb !== false/* && doc.thumbs[0]._ !== 'photoSizeEmpty' */) { if((doc.thumbs?.length || doc.stickerCachedThumbs) && !div.firstElementChild && (!downloaded || stickerType === 2 || stickerType === 3 || onlyThumb) && withThumb !== false/* && doc.thumbs[0]._ !== 'photoSizeEmpty' */) {
let thumb = doc.stickerCachedThumbs && doc.stickerCachedThumbs[toneIndex] || doc.thumbs[0]; let thumb = doc.stickerCachedThumbs && doc.stickerCachedThumbs[toneIndex] || doc.thumbs[0];
//console.log('wrap sticker', thumb, div); //console.log('wrap sticker', thumb, div);
@ -1565,7 +1565,7 @@ export function wrapSticker({doc, div, middleware, lazyLoadQueue, group, play, o
} }
const thumbImage = div.firstElementChild !== media && div.firstElementChild; const thumbImage = div.firstElementChild !== media && div.firstElementChild;
needFadeIn = (needFadeIn || !downloaded || thumbImage) && rootScope.settings.animationsEnabled; needFadeIn = (needFadeIn || !downloaded || (stickerType === 1 ? thumbImage : (!thumbImage || thumbImage.tagName === 'svg'))) && rootScope.settings.animationsEnabled;
media.classList.add('media-sticker'); media.classList.add('media-sticker');
@ -1584,6 +1584,18 @@ export function wrapSticker({doc, div, middleware, lazyLoadQueue, group, play, o
thumbImage.classList.add('fade-out'); thumbImage.classList.add('fade-out');
} }
if(stickerType === 3 && !appDocsManager.isSavingLottiePreview(doc, toneIndex)) {
// const perf = performance.now();
assumeType<HTMLVideoElement>(media);
const canvas = document.createElement('canvas');
canvas.width = width * window.devicePixelRatio;
canvas.height = height * window.devicePixelRatio;
const ctx = canvas.getContext('2d');
ctx.drawImage(media, 0, 0, canvas.width, canvas.height);
appDocsManager.saveLottiePreview(doc, canvas, toneIndex);
// console.log('perf', performance.now() - perf);
}
if(stickerType === 3 && group) { if(stickerType === 3 && group) {
animationIntersector.addAnimation(media as HTMLVideoElement, group); animationIntersector.addAnimation(media as HTMLVideoElement, group);
} }
@ -1617,11 +1629,11 @@ export function wrapSticker({doc, div, middleware, lazyLoadQueue, group, play, o
} }
}; };
const loadPromise: Promise<RLottiePlayer | void> = lazyLoadQueue && (!downloaded || stickerType === 2) ? const loadPromise: Promise<RLottiePlayer | void> = lazyLoadQueue && (!downloaded || stickerType === 2 || stickerType === 3) ?
(lazyLoadQueue.push({div, load}), Promise.resolve()) : (lazyLoadQueue.push({div, load}), Promise.resolve()) :
load(); load();
if(downloaded && (stickerType === 1 || stickerType === 3)) { if(downloaded && (stickerType === 1/* || stickerType === 3 */)) {
loadThumbPromise = loadPromise as any; loadThumbPromise = loadPromise as any;
if(loadPromises) { if(loadPromises) {
loadPromises.push(loadThumbPromise); loadPromises.push(loadThumbPromise);

5
src/lib/appManagers/appDocsManager.ts

@ -391,6 +391,11 @@ export class AppDocsManager {
return download; return download;
} }
public isSavingLottiePreview(doc: MyDocument, toneIndex: number) {
const key = doc.id + '-' + toneIndex;
return !!this.savingLottiePreview[key];
}
public saveLottiePreview(doc: MyDocument, canvas: HTMLCanvasElement, toneIndex: number) { public saveLottiePreview(doc: MyDocument, canvas: HTMLCanvasElement, toneIndex: number) {
const key = doc.id + '-' + toneIndex; const key = doc.id + '-' + toneIndex;
if(this.savingLottiePreview[key]/* || true */) return; if(this.savingLottiePreview[key]/* || true */) return;

Loading…
Cancel
Save