From 28eccc027d84baf931085e6be573e569753d9974 Mon Sep 17 00:00:00 2001
From: Sorunome <mail@sorunome.de>
Date: Sat, 22 Dec 2018 15:03:56 +0100
Subject: [PATCH] D->M proper file handling

---
 src/bot.ts | 24 +++++++++++++++++++-----
 1 file changed, 19 insertions(+), 5 deletions(-)

diff --git a/src/bot.ts b/src/bot.ts
index c76df58..d2393a0 100644
--- a/src/bot.ts
+++ b/src/bot.ts
@@ -45,6 +45,14 @@ interface IThirdPartyLookup {
     protocol: string;
 }
 
+interface IMatrixMediaInfo {
+    w?: number;
+    h?: number;
+    mimetype: string;
+    size: number;
+    duration?: number;
+}
+
 export class DiscordBot {
     private config: DiscordBridgeConfig;
     private clientFactory: DiscordClientFactory;
@@ -629,14 +637,20 @@ export class DiscordBot {
             await Util.AsyncForEach(msg.attachments.array(), async (attachment) => {
                 const content = await Util.UploadContentFromUrl(attachment.url, intent, attachment.filename);
                 const fileMime = mime.lookup(attachment.filename);
-                const msgtype = attachment.height ? "m.image" : "m.file";
+                const type = fileMime.split("/")[0];
+                let msgtype = {
+                    audio: "m.audio",
+                    image: "m.image",
+                    video: "m.video",
+                }[type];
+                if (!msgtype) {
+                    msgtype = "m.file";
+                }
                 const info = {
-                    h: null,
                     mimetype: fileMime,
                     size: attachment.filesize,
-                    w: null,
-                };
-                if (msgtype === "m.image") {
+                } as IMatrixMediaInfo;
+                if (msgtype === "m.image" || msgtype === "m.video") {
                     info.w = attachment.width;
                     info.h = attachment.height;
                 }
-- 
GitLab