 bootstrap = (callback) ->
 
     if argv.new or argv.n
-        Chat.prepareNew ->
+        Chat.prepareNew Chat.TYPE_PUBLIC, ->
             Chat.start callback
     else
-        Chat.prepareFromDatabase ->
+        Chat.prepareFromDatabase Chat.TYPE_PUBLIC, ->
             Chat.start callback
 
 Chat = 
     
-    tasks: {}
+    TYPE_PUBLIC:  'all'
+    TYPE_FACTION: 'faction'
+
+    tasks:  {}
     length: 0
 
-    createTasks: (timestampMin, callback) ->
+    createTasks: (type, timestampMin, callback) ->
 
         timestampMax = new Date().getTime()
 
         preparedTasks = []
 
         for TSmin in [timestampMin..timestampMax] by Config.Chat.SplitTimespanMS
-            
+
             TSmax = Math.min(timestampMax, TSmin + Config.Chat.SplitTimespanMS - 1)
             continue if TSmax is TSmin
 
             preparedTasks.push
+                type:  type
                 data:
                     desiredNumItems: Config.Chat.FetchItemCount
                     minLatE6:        Math.round(Config.Region.SouthWest.Lat * 1e6)

            delete Chat.tasks[taskId]
            Chat.length--

            Database.db.collection('Chat._queue').remove
                _id: new ObjectID(taskId)
            ,
                single: true


, Config.Database.MaxParallel

insertMessage = (type, id, timestamp, data, callback) ->

    async.series [

        (callback) ->

            if insertCount % 100 is 0
                
                Database.db.collection('Chat.' + type).count {}, (err, count) ->
                    messageCount = count
                    callback()

            else

                callback()
        
        , (callback) ->

            insertCount++

            data2 = data.plext

            # parse markup
            markup = {}
            count = {}

            for m in data.plext.markup
                count[m[0]] = 0 if not count[m[0]]?
                count[m[0]]++
                markup[m[0]+count[m[0]].toString()] = m[1]

            data2.markup = markup

            dbQueue.push (done) ->

                doc = data2
                doc._id = id
                doc.time = timestamp

                async.series [

                    (callback) ->
                    
                        Database.db.collection('Chat.' + type).insert doc, callback

                    , (callback) ->

                        # resove player names
                        if doc.markup.PLAYER1?

                            level = 0

                            if doc.markup.TEXT1.plain is ' deployed an '
                                level = parseInt doc.markup.TEXT2.plain.substr(1)

                            Agent.resolved doc.markup.PLAYER1.plain,
                                team:  Agent.strToTeam(doc.markup.PLAYER1.team)
                                level: level
                            , callback

                        else

                            callback()
                        
                ], ->

                    done()
                    callback()
    
    ], callback