Commit 7e8459ac authored by Killian Kemps's avatar Killian Kemps
Browse files

Fix message metadata when listening to new messages

parent eb3a0297
...@@ -96,6 +96,7 @@ function startFacebook(decoded, users, socket) { ...@@ -96,6 +96,7 @@ function startFacebook(decoded, users, socket) {
facebookMessengerService.getUserInfo(currentUser.fbApi, currentUser.ID).then( facebookMessengerService.getUserInfo(currentUser.fbApi, currentUser.ID).then(
function(data) { function(data) {
console.log(data); console.log(data);
currentUser.name = data.name;
socket.emit('chat message', 'Logged in as ' + data.name); socket.emit('chat message', 'Logged in as ' + data.name);
resolve(data); resolve(data);
}); });
...@@ -123,9 +124,11 @@ function startFacebook(decoded, users, socket) { ...@@ -123,9 +124,11 @@ function startFacebook(decoded, users, socket) {
msgToSend = { msgToSend = {
body: message.body, body: message.body,
conversationID: message.threadID, conversationID: message.threadID,
timestampDatetime: tsToTsDatetime(data.timestamp), timestampDatetime: tsToTsDatetime(message.timestamp),
attachments: data.attachments, attachments: message.attachments,
isSenderUser: data.senderID === 'fbid:' + currentUser.ID senderID: message.senderID,
senderName: data[0].name,
isSenderUser: message.senderID === currentUser.ID.toString()
} }
socket.emit('chat message', msgToSend); socket.emit('chat message', msgToSend);
if (Array.isArray(chatHistory[currentUser.ID])) { if (Array.isArray(chatHistory[currentUser.ID])) {
...@@ -205,16 +208,18 @@ function getFBThreadHistory(decoded, users, socket, threadID) { ...@@ -205,16 +208,18 @@ function getFBThreadHistory(decoded, users, socket, threadID) {
// Util function to convert timestamp to timestampDatetime // Util function to convert timestamp to timestampDatetime
function tsToTsDatetime (timestamp) { function tsToTsDatetime (timestamp) {
var date = new Date(timestamp); console.log('timestamp: ', timestamp);
var date = new Date(parseInt(timestamp));
function toDoubleDigit(time) { function toDoubleDigit(time) {
console.log('time: ', time);
if (time < 10) { if (time < 10) {
return '0' + time; return '0' + time.toString();
} }
else { else {
return time; return time.toString();
} }
} }
return toDoubleDigit(date.getHours()) + toDoubleDigit(date.getMinutes()); return toDoubleDigit(date.getHours()) + ':' + toDoubleDigit(date.getMinutes());
} }
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment