       initImageInternal id
       imagesInternal[id].count += 1
       checkImageInternal id
+    checkImage message._id
     ->
       for id of messageImages
         images[id].count -= 1

      video source[src^="#{internalFileUrlPrefix}"],
      video source[src^="#{internalFileAbsoluteUrlPrefix}"]
    """
      src = elt.getAttribute 'src'
      if 0 <= src.indexOf 'gridfs'
        messageImagesInternal[url2internalFile src] = true

  return unless id of images
  ## Image gets unnaturally folded if it's referenced at least once
  ## and doesn't have any children (don't want to hide children, and this
  ## can also lead to infinite loop if children has the image reference)
  ## and doesn't refer to any other images (which can also lead to bad loops).
  newDefault = images[id].naturallyFolded or
    (not images[id].children and
     not images[id].images and
     (images[id].count > 0 or
      (imagesInternal[images[id].file]? and
       imagesInternal[images[id].file].count > 0)))
  console.log id, defaultFolded.get(id), newDefault
  if newDefault != defaultFolded.get id
    defaultFolded.set id, newDefault
    messageFolded.set id, newDefault
