let r = require('rethinkdbdash')();
let readline = require('readline');

let rl = readline.createInterface({
  input: process.stdin,
  output: process.stdout
});


// Display stuff from the chat
r.table('Message').run({cursor: true}).then((cursor) => {
  cursor.each((err, message) => {
    if (message) {
      console.log(message.content);
    }
  });
});

// Typing stuff in should create a new message
rl.on('line', (content) => {
  console.log('inserting ' + content);
  r.table('Message').insert({content}).run().done();
});

// TODO: sort by time, make the display stuff listen for liveness

@@ -207,16 +207,32 @@
 ssage').
+orderBy('time').
 run(%7Bcur
@@ -344,24 +344,38 @@
 sage.content
+, message.time
 );%0A    %7D%0A  %7D
@@ -458,16 +458,41 @@
 t) =%3E %7B%0A
+  let time = new Date();%0A
   consol
@@ -558,16 +558,22 @@
 %7Bcontent
+, time
 %7D).run()
@@ -599,61 +599,29 @@
 DO: 
-sort by time, make the display stuff listen for liveness
+make live-listening work
 %0A

add timestamps. in PDT. yuck