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