[gnome-contacts] Contact: clean up persona store sorting function.
- From: Niels De Graef <nielsdg src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gnome-contacts] Contact: clean up persona store sorting function.
- Date: Sat, 17 Feb 2018 14:33:13 +0000 (UTC)
commit 68f466abea553e25d38092d8cb835678e9dc1189
Author: Niels De Graef <nielsdegraef gmail com>
Date: Sat Feb 17 15:31:50 2018 +0100
Contact: clean up persona store sorting function.
src/contacts-contact.vala | 54 +++++++++++++++++++----------------------------
1 file changed, 22 insertions(+), 32 deletions(-)
---
diff --git a/src/contacts-contact.vala b/src/contacts-contact.vala
index f88cf39..20a2df2 100644
--- a/src/contacts-contact.vala
+++ b/src/contacts-contact.vala
@@ -370,41 +370,31 @@ public class Contacts.Contact : GLib.Object {
}
public Gee.List<Persona> get_personas_for_display () {
- CompareDataFunc<Persona> compare_persona_by_store = (a, b) =>
- {
- Persona persona_a = (Persona *)a;
- Persona persona_b = (Persona *)b;
- var store_a = persona_a.store;
- var store_b = persona_b.store;
-
- if (store_a == store_b) {
- if (persona_is_google (persona_a)) {
- /* Non-other google personas rank before others */
- if (persona_is_google_other (persona_a) && !persona_is_google_other (persona_b))
- return 1;
- if (!persona_is_google_other (persona_a) && persona_is_google_other (persona_b))
- return -1;
- }
-
- return 0;
- }
+ CompareDataFunc<Persona> compare_persona_by_store = (a, b) => {
+ var store_a = a.store;
+ var store_b = b.store;
+
+ // In the same store, sort Google 'other' contacts last
+ if (store_a == store_b) {
+ if (!persona_is_google (a))
+ return 0;
+
+ var a_is_other = persona_is_google_other (a);
+ if (a_is_other != persona_is_google_other (b))
+ return a_is_other? 1 : -1;
+ }
- if (store_a.is_primary_store && store_b.is_primary_store)
- return 0;
- if (store_a.is_primary_store)
- return -1;
- if (store_b.is_primary_store)
- return 1;
+ // Sort primary stores before others
+ if (store_a.is_primary_store != store_b.is_primary_store)
+ return (store_a.is_primary_store)? -1 : 1;
- if (store_a.type_id == "eds" && store_b.type_id == "eds")
- return strcmp (store_a.id, store_b.id);
- if (store_a.type_id == "eds")
- return -1;
- if (store_b.type_id == "eds")
- return 1;
+ // E-D-S stores get prioritized
+ if ((store_a.type_id == "eds") != (store_b.type_id == "eds"))
+ return (store_a.type_id == "eds")? -1 : 1;
- return strcmp (store_a.id, store_b.id);
- };
+ // Normal case: use alphabetical sorting
+ return strcmp (store_a.id, store_b.id);
+ };
var persona_list = new ArrayList<Persona>();
int i = 0;
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]