Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion src/ContentMessages.ts
Original file line number Diff line number Diff line change
Expand Up @@ -158,7 +158,7 @@ async function infoForImageFile(matrixClient: MatrixClient, roomId: string, imag
}

// We don't await this immediately so it can happen in the background
const isAnimatedPromise = blobIsAnimated(imageFile.type, imageFile);
const isAnimatedPromise = blobIsAnimated(imageFile);

const imageElement = await loadImageElement(imageFile);

Expand Down
5 changes: 1 addition & 4 deletions src/components/views/messages/MImageBody.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -311,10 +311,7 @@ export class MImageBodyInner extends React.Component<IProps, IState> {
// then we need to check if the image is animated by downloading it.
if (
content.info?.["org.matrix.msc4230.is_animated"] === false ||
!(await blobIsAnimated(
content.info?.mimetype,
await this.props.mediaEventHelper!.sourceBlob.value,
))
(await blobIsAnimated(await this.props.mediaEventHelper!.sourceBlob.value)) === false
) {
isAnimated = false;
}
Expand Down
4 changes: 2 additions & 2 deletions src/utils/Image.ts
Original file line number Diff line number Diff line change
Expand Up @@ -31,8 +31,8 @@ function arrayBufferReadStr(arr: ArrayBuffer, start: number, len: number): strin
* @param blob The Blob to check.
* @returns True if the image is animated, false if not, or undefined if it could not be determined.
*/
export async function blobIsAnimated(mimeType: string | undefined, blob: Blob): Promise<boolean | undefined> {
switch (mimeType) {
export async function blobIsAnimated(blob: Blob): Promise<boolean | undefined> {
switch (blob.type) {
case "image/webp": {
// Only extended file format WEBP images support animation, so grab the expected data range and verify header.
// Based on https://developers.google.com/speed/webp/docs/riff_container#extended_file_format
Expand Down
8 changes: 6 additions & 2 deletions src/utils/MediaEventHelper.ts
Original file line number Diff line number Diff line change
Expand Up @@ -72,11 +72,15 @@ export class MediaEventHelper implements IDestroyable {
};

private fetchSource = (): Promise<Blob> => {
const content = this.event.getContent<MediaEventContent>();
if (this.media.isEncrypted) {
const content = this.event.getContent<MediaEventContent>();
return decryptFile(content.file!, content.info);
}
return this.media.downloadSource().then((r) => r.blob());

return this.media
.downloadSource()
.then((r) => r.blob())
.then((blob) => blob.slice(0, blob.size, content.info?.mimetype ?? blob.type));
};

private fetchThumbnail = (): Promise<Blob | null> => {
Expand Down