Skip to content

Commit

Permalink
messages being saved to DB now has timestamp
Browse files Browse the repository at this point in the history
  • Loading branch information
jhonatancruz committed Apr 14, 2019
1 parent 9aae82a commit e59600a
Showing 1 changed file with 2 additions and 20 deletions.
22 changes: 2 additions & 20 deletions routes/chat.js
Original file line number Diff line number Diff line change
Expand Up @@ -52,40 +52,22 @@ router.post('/newMessage', function(req,res){
});





router.post('/messages/getInfo', (req, res) => {
console.log(req.body.threadId);
chatData.find({_id: req.body.threadId})
.then(function(doc) {
console.log(doc);
res.io.emit('allMessages', doc);
// res.render('chat', { title: 'DrewUse', currentSession: req.session, messages:doc});
});

});

// chatData.find({_id: req.body.threadId})
// .then(function(doc) {
// res.render('chat', { title: 'DrewUse', currentSession: req.session, chatMessages:doc});
// })


// router.get('/messages/getInfo', (req, res) => {
// var threadId= res.get('threadId')
// console.log(threadId);
// chatData.find({_id:"5cad5ab604972513ad33d371"})
// .then(function(doc) {
// res.send(doc);
// });
// });


router.post('/messages',async (req, res) => {
var current_timestamp = Long.fromNumber(current_millies);
console.log("post messages route");
console.log(req.body);
chatData.update({ _id: req.body.threadId}, {$push:{messages:[{message:req.body.message, byWho:req.body.senderName}]}}).exec();
chatData.update({ _id: req.body.threadId}, {$push:{messages:[{message:req.body.message, byWho:req.body.senderName, timestamp: current_timestamp}]}}).exec();
res.io.emit('message', req.body);

})
Expand Down

0 comments on commit e59600a

Please sign in to comment.