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

Fix message metadata when listening to new messages

parent eb3a0297
......@@ -96,6 +96,7 @@ function startFacebook(decoded, users, socket) {
facebookMessengerService.getUserInfo(currentUser.fbApi, currentUser.ID).then(
function(data) {
console.log(data);
currentUser.name = data.name;
socket.emit('chat message', 'Logged in as ' + data.name);
resolve(data);
});
......@@ -123,9 +124,11 @@ function startFacebook(decoded, users, socket) {
msgToSend = {
body: message.body,
conversationID: message.threadID,
timestampDatetime: tsToTsDatetime(data.timestamp),
attachments: data.attachments,
isSenderUser: data.senderID === 'fbid:' + currentUser.ID
timestampDatetime: tsToTsDatetime(message.timestamp),
attachments: message.attachments,
senderID: message.senderID,
senderName: data[0].name,
isSenderUser: message.senderID === currentUser.ID.toString()
}
socket.emit('chat message', msgToSend);
if (Array.isArray(chatHistory[currentUser.ID])) {
......@@ -205,16 +208,18 @@ function getFBThreadHistory(decoded, users, socket, threadID) {
// Util function to convert timestamp to timestampDatetime
function tsToTsDatetime (timestamp) {
var date = new Date(timestamp);
console.log('timestamp: ', timestamp);
var date = new Date(parseInt(timestamp));
function toDoubleDigit(time) {
console.log('time: ', time);
if (time < 10) {
return '0' + time;
return '0' + time.toString();
}
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