Pārlūkot izejas kodu

Sort contacts by display name before storing them

Danilo Bargen 7 gadi atpakaļ
vecāks
revīzija
1a60b7a99e
1 mainītis faili ar 7 papildinājumiem un 0 dzēšanām
  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];