   Meteor.userId()? and
   groupRoleCheck group, 'post'
 
-@canEdit = (message) ->
+@canEdit = (msg) ->
   ## Can edit message if an "author" (the creator or edited in the past),
   ## or if we have global edit privileges in this group.
-  msg = Messages.findOne message
+  msg = findMessage msg
   return false unless msg?
   escapeUser(Meteor.user()?.username) of (msg.authors ? {}) or
   groupRoleCheck msg.group, 'edit'

  canSuper message2group message

@amAuthor = (message, user = Meteor.user()) ->
  message = Messages.findOne message unless message._id?
  return false unless user?.username
  escapeUser(user.username) of (message.authors ? {}) or
  0 <= message.body.search ///@#{user.username}\b///

@canPrivate = (message) ->
  message = Messages.findOne message unless message._id?
  if canSuper message.group
    ## Superuser can always change private flag
    true


@findMessageRoot = (message) ->
  return message unless message?
  message = findMessage message
  if message.root?
    Messages.findOne message.root
  else
    message

@messageEmpty = (message) ->
  message = findMessage message
  message.title.trim().length == 0 and
  message.body.trim().length == 0 and
  not message.file
