Improve handling of animated images, add support for AVIF animations (#30932)
* Only set MSC4230 is_animated flag if we are able to tell if the media is animated Signed-off-by: Michael Telatynski <7t3chguy@gmail.com> * Set blob type correctly to not need to weave the mimetype around Signed-off-by: Michael Telatynski <7t3chguy@gmail.com> * Use ImageDecoder to determine whether media is animated or not, adding support for AVIF and other formats Signed-off-by: Michael Telatynski <7t3chguy@gmail.com> * Fix test Signed-off-by: Michael Telatynski <7t3chguy@gmail.com> * Iterate Signed-off-by: Michael Telatynski <7t3chguy@gmail.com> * Add test Signed-off-by: Michael Telatynski <7t3chguy@gmail.com> * Fix test Signed-off-by: Michael Telatynski <7t3chguy@gmail.com> --------- Signed-off-by: Michael Telatynski <7t3chguy@gmail.com>
This commit is contained in:
@@ -72,18 +72,25 @@ 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())
|
||||
// Set the mime type from the event info on the blob
|
||||
.then((blob) => blob.slice(0, blob.size, content.info?.mimetype ?? blob.type))
|
||||
);
|
||||
};
|
||||
|
||||
private fetchThumbnail = (): Promise<Blob | null> => {
|
||||
if (!this.media.hasThumbnail) return Promise.resolve(null);
|
||||
|
||||
const content = this.event.getContent<ImageContent>();
|
||||
if (this.media.isEncrypted) {
|
||||
const content = this.event.getContent<ImageContent>();
|
||||
if (content.info?.thumbnail_file) {
|
||||
return decryptFile(content.info.thumbnail_file, content.info.thumbnail_info);
|
||||
} else {
|
||||
@@ -96,7 +103,12 @@ export class MediaEventHelper implements IDestroyable {
|
||||
const thumbnailHttp = this.media.thumbnailHttp;
|
||||
if (!thumbnailHttp) return Promise.resolve(null);
|
||||
|
||||
return fetch(thumbnailHttp).then((r) => r.blob());
|
||||
return (
|
||||
fetch(thumbnailHttp)
|
||||
.then((r) => r.blob())
|
||||
// Set the mime type from the event info on the blob
|
||||
.then((blob) => blob.slice(0, blob.size, content.info?.thumbnail_info?.mimetype ?? blob.type))
|
||||
);
|
||||
};
|
||||
|
||||
public static isEligible(event: MatrixEvent): boolean {
|
||||
|
||||
Reference in New Issue
Block a user