Introduce intl-friendly sort order for contact lists (#1900)

This commit is contained in:
Scott Nonnenberg 2017-12-14 16:30:11 -08:00 committed by GitHub
parent 5cf320e429
commit f0aaa7a1c5
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
5 changed files with 78 additions and 16 deletions

View file

@ -20,30 +20,25 @@
_.debounce(this.updateUnreadCount.bind(this), 1000)
);
this.startPruning();
this.collator = new Intl.Collator();
},
comparator: function(m1, m2) {
var timestamp1 = m1.get('timestamp');
var timestamp2 = m2.get('timestamp');
if (timestamp1 && timestamp2) {
if (timestamp1 && !timestamp2) {
return -1;
}
if (timestamp2 && !timestamp1) {
return 1;
}
if (timestamp1 && timestamp2 && timestamp1 !== timestamp2) {
return timestamp2 - timestamp1;
}
if (timestamp1) {
return -1;
}
if (timestamp2) {
return 1;
}
var title1 = m1.getTitle().toLowerCase();
var title2 = m2.getTitle().toLowerCase();
if (title1 === title2) {
return 0;
}
if (title1 < title2) {
return -1;
}
if (title1 > title2) {
return 1;
}
return this.collator.compare(title1, title2);
},
addActive: function(model) {
if (model.get('active_at')) {