Fix wrapping video messages

This commit is contained in:
Eduard Kuzmenko 2023-01-14 01:46:36 +04:00
parent 859c0f1af9
commit 26c1b3b03d

View File

@ -107,6 +107,7 @@ export class AppDocsManager extends AppManager {
// 'audioPerformer', 'sticker', 'stickerEmoji', 'stickerEmojiRaw', // 'audioPerformer', 'sticker', 'stickerEmoji', 'stickerEmojiRaw',
// 'stickerSetInput', 'stickerThumbConverted', 'animated', 'supportsStreaming']); // 'stickerSetInput', 'stickerThumbConverted', 'animated', 'supportsStreaming']);
let type: MyDocument['type'];
for(let i = 0, length = doc.attributes.length; i < length; ++i) { for(let i = 0, length = doc.attributes.length; i < length; ++i) {
const attribute = doc.attributes[i]; const attribute = doc.attributes[i];
switch(attribute._) { switch(attribute._) {
@ -116,10 +117,7 @@ export class AppDocsManager extends AppManager {
case 'documentAttributeAudio': case 'documentAttributeAudio':
doc.duration = attribute.duration; doc.duration = attribute.duration;
doc.type = attribute.pFlags.voice && doc.mime_type === 'audio/ogg' ? 'voice' : 'audio'; type ??= attribute.pFlags.voice && doc.mime_type === 'audio/ogg' ? 'voice' : 'audio';
/* if(apiDoc.type === 'audio') {
apiDoc.supportsStreaming = true;
} */
break; break;
case 'documentAttributeVideo': case 'documentAttributeVideo':
@ -128,9 +126,9 @@ export class AppDocsManager extends AppManager {
doc.h = attribute.h; doc.h = attribute.h;
// apiDoc.supportsStreaming = attribute.pFlags?.supports_streaming/* && apiDoc.size > 524288 */; // apiDoc.supportsStreaming = attribute.pFlags?.supports_streaming/* && apiDoc.size > 524288 */;
if(/* apiDoc.thumbs && */attribute.pFlags.round_message) { if(/* apiDoc.thumbs && */attribute.pFlags.round_message) {
doc.type = 'round'; type ??= 'round';
} else /* if(apiDoc.thumbs) */ { } else /* if(apiDoc.thumbs) */ {
doc.type = 'video'; type ??= 'video';
} }
break; break;
@ -150,28 +148,28 @@ export class AppDocsManager extends AppManager {
// * there can be no thumbs, then it is a document // * there can be no thumbs, then it is a document
if(/* apiDoc.thumbs && */doc.mime_type === 'image/webp' && (doc.thumbs || getEnvironment().IS_WEBP_SUPPORTED)) { if(/* apiDoc.thumbs && */doc.mime_type === 'image/webp' && (doc.thumbs || getEnvironment().IS_WEBP_SUPPORTED)) {
doc.type = 'sticker'; type ??= 'sticker';
doc.sticker = 1; doc.sticker = 1;
} else if(doc.mime_type === 'video/webm') { } else if(doc.mime_type === 'video/webm') {
if(!getEnvironment().IS_WEBM_SUPPORTED) { if(!getEnvironment().IS_WEBM_SUPPORTED) {
break; break;
} }
doc.type = 'sticker'; type ??= 'sticker';
doc.sticker = 3; doc.sticker = 3;
doc.animated = true; doc.animated = true;
} }
break; break;
case 'documentAttributeImageSize': case 'documentAttributeImageSize':
doc.type = 'photo'; type ??= 'photo';
doc.w = attribute.w; doc.w = attribute.w;
doc.h = attribute.h; doc.h = attribute.h;
break; break;
case 'documentAttributeAnimated': case 'documentAttributeAnimated':
if((doc.mime_type === 'image/gif' || doc.mime_type === 'video/mp4')/* && apiDoc.thumbs */) { if((doc.mime_type === 'image/gif' || doc.mime_type === 'video/mp4')/* && apiDoc.thumbs */) {
doc.type = 'gif'; type ??= 'gif';
} }
doc.animated = true; doc.animated = true;
@ -179,6 +177,8 @@ export class AppDocsManager extends AppManager {
} }
} }
doc.type = type;
if(!doc.mime_type) { if(!doc.mime_type) {
const ext = (doc.file_name || '').split('.').pop(); const ext = (doc.file_name || '').split('.').pop();
// @ts-ignore // @ts-ignore
@ -210,6 +210,10 @@ export class AppDocsManager extends AppManager {
doc.type = 'pdf'; doc.type = 'pdf';
} else if(doc.mime_type === EXTENSION_MIME_TYPE_MAP.gif) { } else if(doc.mime_type === EXTENSION_MIME_TYPE_MAP.gif) {
doc.type = 'gif'; doc.type = 'gif';
} else if(doc.mime_type === 'application/x-tgsticker' && doc.file_name === 'AnimatedSticker.tgs') {
doc.type = 'sticker';
doc.animated = true;
doc.sticker = 2;
} }
if(doc.type === 'voice' || doc.type === 'round') { if(doc.type === 'voice' || doc.type === 'round') {
@ -220,9 +224,10 @@ export class AppDocsManager extends AppManager {
doc.file_name = `${doc.type}_${date}${ext ? '.' + ext : ''}`; doc.file_name = `${doc.type}_${date}${ext ? '.' + ext : ''}`;
} }
let supportsStreaming: boolean;
if(isServiceWorkerOnline()) { if(isServiceWorkerOnline()) {
if((doc.type === 'gif' && doc.size > 8e6) || doc.type === 'audio' || doc.type === 'video'/* || doc.mime_type.indexOf('video/') === 0 */) { if((doc.type === 'gif' && doc.size > 8e6) || doc.type === 'audio' || doc.type === 'video'/* || doc.mime_type.indexOf('video/') === 0 */) {
doc.supportsStreaming = true; supportsStreaming = true;
const cacheContext = this.thumbsStorage.getCacheContext(doc); const cacheContext = this.thumbsStorage.getCacheContext(doc);
if(!cacheContext.url) { if(!cacheContext.url) {
@ -231,19 +236,13 @@ export class AppDocsManager extends AppManager {
} }
} }
doc.supportsStreaming = supportsStreaming;
// for testing purposes // for testing purposes
// doc.supportsStreaming = false; // doc.supportsStreaming = false;
// doc.url = ''; // * this will break upload urls // doc.url = ''; // * this will break upload urls
if(!doc.file_name) { doc.file_name ||= '';
doc.file_name = '';
}
if(doc.mime_type === 'application/x-tgsticker' && doc.file_name === 'AnimatedSticker.tgs') {
doc.type = 'sticker';
doc.animated = true;
doc.sticker = 2;
}
/* if(!doc.url) { /* if(!doc.url) {
doc.url = this.getFileURL(doc); doc.url = this.getFileURL(doc);