             return cb @errorBuilder.makeError 'notAllowed'
           cb()
 
+
+# Implements user to user messaging with permissions checking.
+# @private
+class DirectMessaging
+
+  extend @, DirectMessagingHelpers
+
+  # @param server [object] ChatService object
+  # @param name [string] User name
+  constructor : (@server, @username) ->
+    @errorBuilder = @server.errorBuilder
+    state = @server.chatState.directMessagingState
+    @directMessagingState = new state @server, @username
+
+  # Resets user direct messaging state according to the object.
+  # @param state [object]
+  # @param cb [callback]
+  initState : (state, cb) ->
+    @directMessagingState.initState state, cb
+
   # @private
   message : (author, msg, cb) ->
     @checkAcess author, cb

      @directMessagingState.whitelistOnlySet m, cb


# Implements socket.io messages to function calls association.
class User extends DirectMessaging

  # @param server [object] ChatService object
  # @param name [string] User name
  constructor : (@server, @username) ->
    super @server, @username
    @chatState = @server.chatState
    @enableUserlistUpdates = @server.enableUserlistUpdates
    @enableRoomsManagement = @server.enableRoomsManagement
    @enableDirectMessages = @server.enableDirectMessages
    state = @server.chatState.userState
    @userState = new state @server, @username

  # Resets user direct messaging state according to the object.
  # @param state [object]
  # @param cb [callback]
  initState : (state, cb) ->
    super state, cb

  # @private
  registerSocket : (socket, cb) ->
    @userState.socketAdd socket.id, withEH cb, =>
      for cmd of userCommands
        @bindCommand socket, cmd, @[cmd]
      cb null, @

  # @private
  wrapCommand : (name, fn) ->

        @getModeChangedCurrentAccess whitelistOnly, cb


# @private
# @mixin
DirectMessagingHelpers =

  # @private
  checkUser : (author, cb) ->
