           initImageInternal images[id].file, id
           checkImageInternal images[id].file
 , 250
-
-initImage = (id) ->
-  if id not of images
-    images[id] =
-      count: 0
-      file: null
-    updateFileQuery()
-
-initImageInternal = (id, image = null) ->
-  #console.log "initImageInternal #{id}, #{image}"
-  if id not of imagesInternal
-    imagesInternal[id] =
-      count: 0
-      image: image
-  else if image?
-    imagesInternal[id].image = image
-
-checkImage = (id) ->
-  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
-  ## No longer care about this image if it's not referenced and doesn't have
-  ## a rendered template.
-  if images[id].count == 0 and id not of id2dom
-    delete images[id]
-    updateFileQuery()
-
-checkImageInternal = (id) ->
-  image = imagesInternal[id].image
-  #console.log "#{id} corresponds to #{image}"
-  checkImage image if image?
 
 messageOnDragStart = (message) -> (e) ->
   #url = "coauthor:#{message._id}"

    if scrollToLater == message._id
      scrollToLater = null
      scrollToMessage message._id
    ## Maintain id2dom mapping, and seed images map
    id2dom[message._id] = ref.current
    initImage message._id
    ## initImage calls updateFileQuery which will do this:
    #images[message._id].file = message.file
    #initImageInternal message.file if message.file?
    ->
      delete id2dom[message._id]
      checkImage message._id
  , [message._id]

  ## Fold naturally folded (minimized and deleted) messages by default on

threadAuthors = {}
threadMentions = {}

imageRefCount = new ReactiveDict
imageInternalRefCount = new ReactiveDict
id2dom = {}
scrollToLater = null
fileQuery = null
