Convert incoming timestamps into numbers

Fixes #59

protip: don't use << for anything over 2^32. The operands of all bitwise
operators are converted to signed 32-bit integers
This commit is contained in:
lilia 2014-10-16 01:19:10 -07:00
parent 7a6c15bb32
commit 6db3eeb52e

View file

@ -35,18 +35,20 @@ var Whisper = Whisper || {};
attachments[i] = "data:" + decrypted.message.attachments[i].contentType + ";base64," + btoa(getString(decrypted.message.attachments[i].decrypted)); attachments[i] = "data:" + decrypted.message.attachments[i].contentType + ";base64," + btoa(getString(decrypted.message.attachments[i].decrypted));
var thread = Whisper.Threads.findOrCreateForIncomingMessage(decrypted); var thread = Whisper.Threads.findOrCreateForIncomingMessage(decrypted);
var timestamp = Math.pow(2,32) * decrypted.pushMessage.timestamp.high
+ decrypted.pushMessage.timestamp.low;
var m = thread.messages().add({ var m = thread.messages().add({
person: decrypted.pushMessage.source, person: decrypted.pushMessage.source,
threadId: thread.id, threadId: thread.id,
body: decrypted.message.body, body: decrypted.message.body,
attachments: attachments, attachments: attachments,
type: 'incoming', type: 'incoming',
timestamp: decrypted.pushMessage.timestamp timestamp: timestamp
}); });
m.save(); m.save();
if (decrypted.message.timestamp > thread.get('timestamp')) { if (timestamp > thread.get('timestamp')) {
thread.set('timestamp', decrypted.message.timestamp); thread.set('timestamp', timestamp);
} }
thread.save({unreadCount: thread.get('unreadCount') + 1, active: true}); thread.save({unreadCount: thread.get('unreadCount') + 1, active: true});
return m; return m;