FIX: move lightbox decorator to after-cooked

FIX: move lightbox decorator to after-cooked

diff --git a/assets/javascripts/discourse/initializers/hook-decrypt-post.js.es6 b/assets/javascripts/discourse/initializers/hook-decrypt-post.js.es6
index 6b12778..d52090d 100644
--- a/assets/javascripts/discourse/initializers/hook-decrypt-post.js.es6
+++ b/assets/javascripts/discourse/initializers/hook-decrypt-post.js.es6
@@ -228,23 +228,6 @@ function postProcessPost(siteSettings, topicId, $post) {
     );
   }
 
-  $post
-    .find(".cooked img")
-    .not($(".d-lazyload-hidden"))
-    .each(function() {
-      if (
-        this.naturalWidth > siteSettings.max_image_width ||
-        this.naturalHeight > siteSettings.max_image_height
-      ) {
-        $(this).wrap(
-          '<div class="lightbox-wrapper"><a class="lightbox" href="' +
-            $(this).attr("src") +
-            '"</a></div>'
-        );
-      }
-    });
-  lightbox($post[0], siteSettings);
-
   try {
     const { linkSeenHashtags, fetchUnseenHashtags } = require.call(
       null,
@@ -320,6 +303,28 @@ export default {
 
       api.includePostAttributes("encrypted_raw");
 
+      api.decorateWidget("post-contents:after-cooked", dec => {
+        const siteSettings = dec.widget.siteSettings;
+        $(".cooked img")
+          .not($(".d-lazyload-hidden"))
+          .not($("a.lightbox img"))
+          .each(function() {
+            const src = $(this).attr("src");
+            if (
+              (this.naturalWidth > siteSettings.max_image_width ||
+                this.naturalHeight > siteSettings.max_image_height) &&
+              src.startsWith("blob:")
+            ) {
+              $(this).wrap(
+                '<div class="lightbox-wrapper"><a class="lightbox" href="' +
+                  src +
+                  '"</a></div>'
+              );
+              lightbox($(this).parents(".cooked")[0], siteSettings);
+            }
+          });
+      });
+
       api.decorateWidget("post-meta-data:after", helper => {
         const result = verified[helper.attrs.id];
         if (result === undefined) {

GitHub sha: fc157eba