 threadMentions = {}
 
 Template.submessage.onCreated ->
-  @count = submessageCount++
-  @editing = new ReactiveVar null
-  @editTitle = new ReactiveVar null
-  @editBody = new ReactiveVar null
-  @lastTitle = null
-  @savedTitles = []
-
-  @autorun =>
-    data = Template.currentData()
-    return unless data?
-    #@myid = data._id
-    if editingMessage data
-      ## Maintain @editing == this message's ID when message is being edited.
-      ## Also initialize title and body only when we start editing.
-      if data._id != @editing.get()
-        @editing.set data._id
-        @editTitle.set data.title
-        @editBody.set data.body
-      ## Update input's value when title changes on server
-      if data.title != @lastTitle
-        @lastTitle = data.title
-        ## Ignore an update that matches a title we sent to the server,
-        ## to avoid weird reversion while live typing with network delays.
-        ## (In steady state, we expect our saves to match later updates,
-        ## so this should acquiesce with an empty savedTitles.)
-        if data.title in @savedTitles
-          while @savedTitles.pop() != data.title
-            continue
-        else
-          ## Received new title: update input text, forget past saves,
-          ## and cancel any pending save.
-          @editTitle.set data.title
-          @savedTitles = []
-          Meteor.clearTimeout @timer
-    else
-      @editing.set null
-
-    threadAuthors[author] -= 1 for author in @authors if @authors?
-    threadMentions[author] -= 1 for author in @mentions if @mentions?
-    @authors = (unescapeUser author for author of data.authors)
-    for author in @authors
-      threadAuthors[author] ?= 0
-      threadAuthors[author] += 1
-    Session.set 'threadAuthors', threadAuthors
-    @mentions = atMentions data
-    for author in @mentions
-      threadMentions[author] ?= 0
-      threadMentions[author] += 1
-    Session.set 'threadMentions', threadMentions
-
-    #console.log 'automathjax'
-    automathjax()
-
   ## Fold naturally folded (minimized and deleted) messages by default on
   ## initial load.  But only if not previously manually overridden.
   oldDefault = defaultFolded.get @data._id

import React, {useEffect, useMemo, useRef, useState} from 'react'
import {useTracker} from 'meteor/react-meteor-data'

import {ErrorBoundary} from './ErrorBoundary'

        setEditStopping true
    else
      Meteor.call 'messageEditStart', message._id
  onChangeTitle = (e) ->
    newTitle = e.target.value
    setEditTitle newTitle
    Meteor.clearTimeout timer.current
    messageID = message._id
    timer.current = Meteor.setTimeout ->
      savedTitles.current.push newTitle
      Meteor.call 'messageUpdate', messageID,
        title: newTitle
    , idle

  return null unless visible or here
  <div className="panel message #{messagePanelClass message, editing}" data-message={message._id} id={message._id} ref={ref}>
    <div className="panel-heading clearfix">
      {if editing and not history?
        <input className="push-down form-control title" type="text" placeholder="Title" value={editTitle} onChange={onChangeTitle} tabIndex={tabindex0+18}/>
      else
        <span className="message-title">
          <span className="message-left-buttons push-down btn-group btn-group-xs">
