浏览代码

Sort contacts by display name before storing them

Danilo Bargen 7 年之前
父节点
当前提交
1a60b7a99e
共有 1 个文件被更改,包括 7 次插入0 次删除
  1. 7 0
      src/threema/container.ts

+ 7 - 0
src/threema/container.ts

@@ -120,6 +120,13 @@ class Receivers implements threema.Container.Receivers {
      * Set contacts.
      */
     public setContacts(data: threema.ContactReceiver[]): void {
+        data.sort((a: threema.Receiver, b: threema.Receiver) => {
+            if (a.id.startsWith('*') && !b.id.startsWith('*')) { return 1; }
+            if (!a.id.startsWith('*') && b.id.startsWith('*')) { return -1; }
+            if (a.displayName < b.displayName) { return -1; }
+            if (a.displayName > b.displayName) { return 1; }
+            return 0;
+        });
         this.contacts = new Map(data.map((c) => {
             c.type = 'contact';
             return [c.id, c];