- /* Two groups. The 'Ungrouped' fake group is display at the bottom of the
- * contact list and the 'Favorites' at the top. */
- if (fake_group_a && !tp_strdiff (name_a, EMPATHY_CONTACT_LIST_STORE_UNGROUPED))
- return 1;
- else if (fake_group_b && !tp_strdiff (name_b, EMPATHY_CONTACT_LIST_STORE_UNGROUPED))
- return -1;
- else if (fake_group_a && !tp_strdiff (name_a, EMPATHY_CONTACT_LIST_STORE_FAVORITE))
+ gboolean a_in_top, b_in_top, a_in_bottom, b_in_bottom;
+
+ a_in_top = fake_group_a &&
+ tp_strv_contains (top_groups, name_a);
+ b_in_top = fake_group_b &&
+ tp_strv_contains (top_groups, name_b);
+ a_in_bottom = fake_group_b &&
+ tp_strv_contains (bottom_groups, name_a);
+ b_in_bottom = fake_group_b &&
+ tp_strv_contains (bottom_groups, name_b);
+
+ if (a_in_top && b_in_top) {
+ /* compare positions */
+ return CLAMP (get_position (top_groups, name_a) -
+ get_position (top_groups, name_b),
+ -1, 1);
+ } else if (a_in_bottom && b_in_bottom) {
+ /* compare positions */
+ return CLAMP (get_position (bottom_groups, name_a) -
+ get_position (bottom_groups, name_b),
+ -1, 1);
+ } else if (a_in_top || b_in_bottom) {