Browse Source

Support .webm stickers

master
Eduard Kuzmenko 3 years ago
parent
commit
e8dbfbc0c0
  1. 36
      src/components/wrappers.ts
  2. 2
      src/layer.d.ts
  3. 14
      src/lib/appManagers/appDocsManager.ts
  4. 2
      src/scripts/in/schema_additional_params.json

36
src/components/wrappers.ts

@ -96,8 +96,14 @@ export function wrapVideo({doc, container, message, boxWidth, boxHeight, withTai
searchContext?: MediaSearchContext, searchContext?: MediaSearchContext,
}) { }) {
const isAlbumItem = !(boxWidth && boxHeight); const isAlbumItem = !(boxWidth && boxHeight);
const canAutoplay = (doc.type !== 'video' || (doc.size <= MAX_VIDEO_AUTOPLAY_SIZE && !isAlbumItem)) const canAutoplay = doc.sticker || (
&& (doc.type === 'gif' ? rootScope.settings.autoPlay.gifs : rootScope.settings.autoPlay.videos); (
doc.type !== 'video' || (
doc.size <= MAX_VIDEO_AUTOPLAY_SIZE &&
!isAlbumItem
)
) && (doc.type === 'gif' ? rootScope.settings.autoPlay.gifs : rootScope.settings.autoPlay.videos)
);
let spanTime: HTMLElement, spanPlay: HTMLElement; let spanTime: HTMLElement, spanPlay: HTMLElement;
if(!noInfo) { if(!noInfo) {
@ -395,7 +401,7 @@ export function wrapVideo({doc, container, message, boxWidth, boxHeight, withTai
preloader = (message.media as any).preloader as ProgressivePreloader; preloader = (message.media as any).preloader as ProgressivePreloader;
preloader.attach(container, false); preloader.attach(container, false);
noAutoDownload = undefined; noAutoDownload = undefined;
} else if(!cacheContext.downloaded && !doc.supportsStreaming) { } else if(!cacheContext.downloaded && !doc.supportsStreaming && !withoutPreloader) {
preloader = new ProgressivePreloader({ preloader = new ProgressivePreloader({
attachMethod: 'prepend' attachMethod: 'prepend'
}); });
@ -452,14 +458,16 @@ export function wrapVideo({doc, container, message, boxWidth, boxHeight, withTai
} }
let loadPromise: Promise<any> = Promise.resolve(); let loadPromise: Promise<any> = Promise.resolve();
if(preloader && !isUpload) { if((preloader && !isUpload) || withoutPreloader) {
if(!cacheContext.downloaded && !doc.supportsStreaming) { if(!cacheContext.downloaded && !doc.supportsStreaming) {
const promise = loadPromise = appDocsManager.downloadDoc(doc, lazyLoadQueue?.queueId, noAutoDownload); const promise = loadPromise = appDocsManager.downloadDoc(doc, lazyLoadQueue?.queueId, noAutoDownload);
preloader.attach(container, false, promise); if(preloader) {
preloader.attach(container, false, promise);
}
} else if(doc.supportsStreaming) { } else if(doc.supportsStreaming) {
if(noAutoDownload) { if(noAutoDownload) {
loadPromise = Promise.reject(); loadPromise = Promise.reject();
} else if(!cacheContext.downloaded) { // * check for uploading video } else if(!cacheContext.downloaded && preloader) { // * check for uploading video
preloader.attach(container, false, null); preloader.attach(container, false, null);
video.addEventListener(IS_SAFARI ? 'timeupdate' : 'canplay', () => { video.addEventListener(IS_SAFARI ? 'timeupdate' : 'canplay', () => {
preloader.detach(); preloader.detach();
@ -1150,6 +1158,22 @@ export function wrapSticker({doc, div, middleware, lazyLoadQueue, group, play, o
div.dataset.docId = '' + doc.id; div.dataset.docId = '' + doc.id;
div.classList.add('media-sticker-wrapper'); div.classList.add('media-sticker-wrapper');
if(stickerType === 3) {
return wrapVideo({
doc,
boxWidth: width,
boxHeight: height,
container: div,
group,
lazyLoadQueue,
middleware,
withoutPreloader: true,
loadPromises,
noPlayButton: true,
noInfo: true
}).loadPromise;
}
//console.log('wrap sticker', doc, div, onlyThumb); //console.log('wrap sticker', doc, div, onlyThumb);

2
src/layer.d.ts vendored

@ -3237,7 +3237,7 @@ export namespace Document {
duration?: number, duration?: number,
audioTitle?: string, audioTitle?: string,
audioPerformer?: string, audioPerformer?: string,
sticker?: 1 | 2, sticker?: 1 | 2 | 3,
stickerEmoji?: string, stickerEmoji?: string,
stickerEmojiRaw?: string, stickerEmojiRaw?: string,
stickerSetInput?: InputStickerSet.inputStickerSetID, stickerSetInput?: InputStickerSet.inputStickerSetID,

14
src/lib/appManagers/appDocsManager.ts

@ -91,6 +91,16 @@ export class AppDocsManager {
this.docs[doc.id] = doc; this.docs[doc.id] = doc;
} }
if(doc.mime_type === 'video/webm' && !doc.attributes.find(attribute => attribute._ === 'documentAttributeSticker')) {
doc.attributes.push({
_: 'documentAttributeSticker',
alt: '⏱',
stickerset: {
_: 'inputStickerSetEmpty'
}
});
}
// * exclude from state // * exclude from state
// defineNotNumerableProperties(doc, [/* 'thumbs', */'type', 'h', 'w', 'file_name', // defineNotNumerableProperties(doc, [/* 'thumbs', */'type', 'h', 'w', 'file_name',
// 'file', 'duration', 'downloaded', 'url', 'audioTitle', // 'file', 'duration', 'downloaded', 'url', 'audioTitle',
@ -144,6 +154,10 @@ export class AppDocsManager {
if(/* apiDoc.thumbs && */doc.mime_type === 'image/webp' && (doc.thumbs || IS_WEBP_SUPPORTED)) { if(/* apiDoc.thumbs && */doc.mime_type === 'image/webp' && (doc.thumbs || IS_WEBP_SUPPORTED)) {
doc.type = 'sticker'; doc.type = 'sticker';
doc.sticker = 1; doc.sticker = 1;
} else if(doc.mime_type === 'video/webm') {
doc.type = 'sticker';
doc.sticker = 3;
doc.animated = true;
} }
break; break;

2
src/scripts/in/schema_additional_params.json

@ -11,7 +11,7 @@
{"name": "duration", "type": "number"}, {"name": "duration", "type": "number"},
{"name": "audioTitle", "type": "string"}, {"name": "audioTitle", "type": "string"},
{"name": "audioPerformer", "type": "string"}, {"name": "audioPerformer", "type": "string"},
{"name": "sticker", "type": "1 | 2"}, {"name": "sticker", "type": "1 | 2 | 3"},
{"name": "stickerEmoji", "type": "string"}, {"name": "stickerEmoji", "type": "string"},
{"name": "stickerEmojiRaw", "type": "string"}, {"name": "stickerEmojiRaw", "type": "string"},
{"name": "stickerSetInput", "type": "InputStickerSet.inputStickerSetID"}, {"name": "stickerSetInput", "type": "InputStickerSet.inputStickerSetID"},

Loading…
Cancel
Save