From 3e5bd0f4882822c15d769fa69b4c9241f905b1a5 Mon Sep 17 00:00:00 2001 From: Alexander Zinchuk Date: Fri, 11 Feb 2022 15:12:56 +0100 Subject: [PATCH] Chat: Fix webpage video preview in Safari --- src/api/gramjs/methods/media.ts | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) diff --git a/src/api/gramjs/methods/media.ts b/src/api/gramjs/methods/media.ts index ae47e02b..62e019b1 100644 --- a/src/api/gramjs/methods/media.ts +++ b/src/api/gramjs/methods/media.ts @@ -17,7 +17,7 @@ import * as cacheApi from '../../../util/cacheApi'; type EntityType = ( 'msg' | 'sticker' | 'wallpaper' | 'gif' | 'channel' | 'chat' | 'user' | 'photo' | 'stickerSet' | 'webDocument' | 'document' -); + ); const MEDIA_ENTITY_TYPES = new Set(['msg', 'sticker', 'gif', 'wallpaper', 'photo', 'webDocument', 'document']); const TGS_MIME_TYPE = 'application/x-tgsticker'; @@ -105,8 +105,9 @@ async function download( if (mediaMatch[1] === 'avatar' || mediaMatch[1] === 'profile') { entityType = getEntityTypeById(entityId); } else { - entityType = mediaMatch[1] as 'msg' | 'sticker' | 'wallpaper' | 'gif' | 'stickerSet' | 'photo' | 'webDocument' | - 'document'; + entityType = mediaMatch[1] as ( + 'msg' | 'sticker' | 'wallpaper' | 'gif' | 'stickerSet' | 'photo' | 'webDocument' | 'document' + ); } switch (entityType) { @@ -216,6 +217,10 @@ function getMessageMediaMimeType(message: GramJs.Message, sizeType?: string) { if (message.media instanceof GramJs.MessageMediaWebPage && message.media.webpage instanceof GramJs.WebPage && message.media.webpage.document instanceof GramJs.Document) { + if (sizeType) { + return 'image/jpeg'; + } + return message.media.webpage.document.mimeType; }