Sticker: Fix video sticker preview (#5153)
This commit is contained in:
parent
5bd3219e8c
commit
de3f791b10
@ -95,6 +95,12 @@ export function buildApiPhoto(photo: GramJs.Photo, isSpoiler?: boolean): ApiPhot
|
||||
};
|
||||
}
|
||||
|
||||
export function buildApiPhotoPreviewSizes(sizes: GramJs.TypePhotoSize[]): ApiPhotoSize[] {
|
||||
return sizes.filter((s): s is GramJs.PhotoSize => (
|
||||
s instanceof GramJs.PhotoSize || s instanceof GramJs.PhotoSizeProgressive
|
||||
)).map(buildApiPhotoSize);
|
||||
}
|
||||
|
||||
export function buildApiVideoSize(videoSize: GramJs.TypeVideoSize): ApiVideoSize | undefined {
|
||||
if (!(videoSize instanceof GramJs.VideoSize)) return undefined;
|
||||
|
||||
|
||||
@ -36,6 +36,7 @@ import {
|
||||
buildApiFormattedText,
|
||||
buildApiMessageEntity,
|
||||
buildApiPhoto,
|
||||
buildApiPhotoPreviewSizes,
|
||||
buildApiPhotoSize,
|
||||
buildApiThumbnailFromPath,
|
||||
buildApiThumbnailFromStripped,
|
||||
@ -205,6 +206,7 @@ export function buildVideoFromDocument(document: GramJs.Document, isSpoiler?: bo
|
||||
.find((a): a is GramJs.DocumentAttributeAnimated => a instanceof GramJs.DocumentAttributeAnimated);
|
||||
|
||||
const hasVideoPreview = videoThumbs?.some((thumb) => thumb instanceof GramJs.VideoSize && thumb.type === 'v');
|
||||
const previewPhotoSizes = thumbs && buildApiPhotoPreviewSizes(thumbs);
|
||||
|
||||
const {
|
||||
duration,
|
||||
@ -230,6 +232,7 @@ export function buildVideoFromDocument(document: GramJs.Document, isSpoiler?: bo
|
||||
size: size.toJSNumber(),
|
||||
isSpoiler,
|
||||
hasVideoPreview,
|
||||
previewPhotoSizes,
|
||||
...(nosound && { noSound: true }),
|
||||
};
|
||||
}
|
||||
@ -389,14 +392,15 @@ export function buildApiDocument(document: GramJs.TypeDocument): ApiDocument | u
|
||||
id, size, mimeType, date, thumbs, attributes,
|
||||
} = document;
|
||||
|
||||
const photoSize = thumbs && thumbs.find((s: any): s is GramJs.PhotoSize => s instanceof GramJs.PhotoSize);
|
||||
const photoSize = thumbs && thumbs.find((s): s is GramJs.PhotoSize => s instanceof GramJs.PhotoSize);
|
||||
let thumbnail = thumbs && buildApiThumbnailFromStripped(thumbs);
|
||||
if (!thumbnail && thumbs && photoSize) {
|
||||
const photoPath = thumbs.find((s: any): s is GramJs.PhotoPathSize => s instanceof GramJs.PhotoPathSize);
|
||||
const photoPath = thumbs.find((s): s is GramJs.PhotoPathSize => s instanceof GramJs.PhotoPathSize);
|
||||
if (photoPath) {
|
||||
thumbnail = buildApiThumbnailFromPath(photoPath, photoSize);
|
||||
}
|
||||
}
|
||||
const previewPhotoSizes = thumbs && buildApiPhotoPreviewSizes(thumbs);
|
||||
|
||||
let innerMediaType: ApiDocument['innerMediaType'] | undefined;
|
||||
let mediaSize: ApiDocument['mediaSize'] | undefined;
|
||||
@ -410,7 +414,7 @@ export function buildApiDocument(document: GramJs.TypeDocument): ApiDocument | u
|
||||
innerMediaType = 'photo';
|
||||
|
||||
const imageAttribute = attributes
|
||||
.find((a: any): a is GramJs.DocumentAttributeImageSize => a instanceof GramJs.DocumentAttributeImageSize);
|
||||
.find((a): a is GramJs.DocumentAttributeImageSize => a instanceof GramJs.DocumentAttributeImageSize);
|
||||
|
||||
if (imageAttribute) {
|
||||
const { w: width, h: height } = imageAttribute;
|
||||
@ -444,6 +448,7 @@ export function buildApiDocument(document: GramJs.TypeDocument): ApiDocument | u
|
||||
thumbnail,
|
||||
innerMediaType,
|
||||
mediaSize,
|
||||
previewPhotoSizes,
|
||||
};
|
||||
}
|
||||
|
||||
|
||||
@ -7,7 +7,7 @@ import type {
|
||||
import { LOTTIE_STICKER_MIME_TYPE, VIDEO_STICKER_MIME_TYPE } from '../../../config';
|
||||
import { compact } from '../../../util/iteratees';
|
||||
import localDb from '../localDb';
|
||||
import { buildApiThumbnailFromCached, buildApiThumbnailFromPath } from './common';
|
||||
import { buildApiPhotoPreviewSizes, buildApiThumbnailFromCached, buildApiThumbnailFromPath } from './common';
|
||||
|
||||
export function buildStickerFromDocument(document: GramJs.TypeDocument,
|
||||
isNoPremium?: boolean, isPremium?: boolean): ApiSticker | undefined {
|
||||
@ -73,6 +73,7 @@ export function buildStickerFromDocument(document: GramJs.TypeDocument,
|
||||
) : pathThumb && sizeAttribute ? (
|
||||
buildApiThumbnailFromPath(pathThumb, sizeAttribute)
|
||||
) : undefined;
|
||||
const previewPhotoSizes = document.thumbs && buildApiPhotoPreviewSizes(document.thumbs);
|
||||
|
||||
const { w: width, h: height } = cachedThumb as GramJs.PhotoCachedSize || sizeAttribute || {};
|
||||
|
||||
@ -94,6 +95,7 @@ export function buildStickerFromDocument(document: GramJs.TypeDocument,
|
||||
hasEffect,
|
||||
isFree,
|
||||
shouldUseTextColor,
|
||||
previewPhotoSizes,
|
||||
};
|
||||
}
|
||||
|
||||
|
||||
@ -56,6 +56,7 @@ export interface ApiSticker {
|
||||
width?: number;
|
||||
height?: number;
|
||||
thumbnail?: ApiThumbnail;
|
||||
previewPhotoSizes?: ApiPhotoSize[];
|
||||
isPreloadedGlobally?: boolean;
|
||||
hasEffect?: boolean;
|
||||
isFree?: boolean;
|
||||
@ -110,6 +111,7 @@ export interface ApiVideo {
|
||||
hasVideoPreview?: boolean;
|
||||
isSpoiler?: boolean;
|
||||
thumbnail?: ApiThumbnail;
|
||||
previewPhotoSizes?: ApiPhotoSize[];
|
||||
blobUrl?: string;
|
||||
previewBlobUrl?: string;
|
||||
size: number;
|
||||
@ -144,6 +146,7 @@ export interface ApiDocument {
|
||||
timestamp?: number;
|
||||
mimeType: string;
|
||||
thumbnail?: ApiThumbnail;
|
||||
previewPhotoSizes?: ApiPhotoSize[];
|
||||
previewBlobUrl?: string;
|
||||
innerMediaType?: 'photo' | 'video';
|
||||
mediaSize?: ApiDimensions;
|
||||
|
||||
@ -384,6 +384,9 @@ export function getStickerMediaHash(sticker: ApiSticker, target: Target) {
|
||||
switch (target) {
|
||||
case 'micro':
|
||||
case 'pictogram':
|
||||
if (!sticker.previewPhotoSizes?.some((size) => size.type === 's')) {
|
||||
return getStickerMediaHash(sticker, 'preview');
|
||||
}
|
||||
return `${base}?size=s`;
|
||||
case 'preview':
|
||||
return `${base}?size=m`;
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user