mirror of
https://github.com/signalapp/Signal-Desktop.git
synced 2026-05-08 08:58:38 +01:00
Nicer timestamps with momentjs
This dependency may be a little heavy for our current use case, but we can roll with it for now and find something slimmer if it turns out yagni. Closes #77 Closes #40
This commit is contained in:
@@ -22,7 +22,7 @@ var Whisper = Whisper || {};
|
||||
this.$el.html(
|
||||
Mustache.render(this.template, {
|
||||
message: this.model.get('body'),
|
||||
date: this.formatTimestamp(),
|
||||
timestamp: moment(this.model.get('timestamp')).fromNow(),
|
||||
attachments: this.model.get('attachments'),
|
||||
bubble_class: this.model.get('type') === 'outgoing' ? 'sent' : 'incoming',
|
||||
sender: this.model.thread().get('type') === 'group' ? this.model.get('person') : ''
|
||||
@@ -30,21 +30,8 @@ var Whisper = Whisper || {};
|
||||
);
|
||||
|
||||
return this;
|
||||
},
|
||||
|
||||
formatTimestamp: function() {
|
||||
var timestamp = this.model.get('timestamp');
|
||||
var now = new Date().getTime();
|
||||
var date = new Date();
|
||||
date.setTime(timestamp*1000);
|
||||
if (now - timestamp > 60*60*24*7) {
|
||||
return date.toLocaleDateString('en-US',{month: 'short', day: 'numeric'});
|
||||
}
|
||||
if (now - timestamp > 60*60*24) {
|
||||
return date.toLocaleDateString('en-US',{weekday: 'short'});
|
||||
}
|
||||
return date.toTimeString();
|
||||
}
|
||||
|
||||
});
|
||||
|
||||
})();
|
||||
|
||||
Reference in New Issue
Block a user