Reuse media content/info types from the js-sdk (#12308)

This commit is contained in:
Michael Telatynski 2024-03-11 09:30:00 +00:00 committed by GitHub
parent 89eb884821
commit 431ae32304
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
19 changed files with 74 additions and 258 deletions

View file

@ -15,12 +15,12 @@ limitations under the License.
*/
import { MatrixEvent, EventType, MsgType } from "matrix-js-sdk/src/matrix";
import { FileContent, ImageContent, MediaEventContent } from "matrix-js-sdk/src/types";
import { logger } from "matrix-js-sdk/src/logger";
import { LazyValue } from "./LazyValue";
import { Media, mediaFromContent } from "../customisations/Media";
import { decryptFile } from "./DecryptFile";
import { FileContent, ImageContent, IMediaEventContent } from "../customisations/models/IMediaEventContent";
import { IDestroyable } from "./IDestroyable";
// TODO: We should consider caching the blobs. https://github.com/vector-im/element-web/issues/17192
@ -48,7 +48,7 @@ export class MediaEventHelper implements IDestroyable {
public get fileName(): string {
return (
this.event.getContent<FileContent>().filename ||
this.event.getContent<IMediaEventContent>().body ||
this.event.getContent<MediaEventContent>().body ||
"download"
);
}
@ -81,7 +81,7 @@ export class MediaEventHelper implements IDestroyable {
private fetchSource = (): Promise<Blob> => {
if (this.media.isEncrypted) {
const content = this.event.getContent<IMediaEventContent>();
const content = this.event.getContent<MediaEventContent>();
return decryptFile(content.file!, content.info);
}
return this.media.downloadSource().then((r) => r.blob());