Przeglądaj źródła

[bugfix] Refs #55 slack uploads are now an array

isundil 6 lat temu
rodzic
commit
c478b223d9
1 zmienionych plików z 12 dodań i 10 usunięć
  1. 12 10
      srv/src/slackHistory.js

+ 12 - 10
srv/src/slackHistory.js

@@ -47,16 +47,18 @@ SlackHistory.prototype.prepareMessage = function(ev, targetId) {
 }
 
 SlackHistory.prototype.messageFactory = function(ev, ts) {
-    let img;
-    if (ev["file"] && ev["file"]["mimetype"].indexOf("image/") >= 0)
-        img = ev["file"]["thumb_360"] || ev["file"]["url_private"] || ev["file"]["permalink"] || undefined;
-    if (img) {
-        if (!ev["attachments"])
-            ev["attachments"] = [];
-        ev["attachments"].push({
-            "image_url": img
-        });
-    }
+    ev["files"] && ev["files"].forEach(f => {
+        if (f["mimetype"].indexOf("image/") >= 0) {
+            let imgUrl = f["thumb_360"] || f["url_private"] || f["permalink"];
+            if (imgUrl) {
+                if (!ev["attachments"])
+                    ev["attachments"] = [];
+                ev["attachments"].push({
+                    "image_url": imgUrl
+                });
+            }
+        }
+    });
     if (!ev["user"]) {
         if (ev["bot_id"])
             ev["user"] = ev["bot_id"];