Sort the facebook contacts by name/alias in group chat. facebook-group-chat--sort-list

Wed, 21 Nov 2018 20:16:29 +0200

author
Shlomi Fish <shlomif@shlomifish.org>
date
Wed, 21 Nov 2018 20:16:29 +0200
branch
facebook-group-chat--sort-list
changeset 39336
f6f4427c055c
parent 39302
64aabebb476b
child 39337
8b53f4ffdc1b

Sort the facebook contacts by name/alias in group chat.

See https://developer.pidgin.im/ticket/17357 .


I hereby disclaim any implicit or explicit ownership of my changes in this
changeset, and put them under a multiple licence consisting of your choice of
one of more of:

- The CC0 / Public Domain - https://creativecommons.org/choose/zero/ .

- The MIT / Expat license - https://en.wikipedia.org/wiki/MIT_License

- The default licence of your project

- The https://en.wikipedia.org/wiki/GNU_Lesser_General_Public_License - version
2.1 or higher

- The https://en.wikipedia.org/wiki/GNU_General_Public_License - version 2 or
higher

- Any licence in the 2018-Aug-27 popular licenses list of
https://opensource.org/licenses

- The https://en.wikipedia.org/wiki/Apache_License version 2.0 or later

- The https://en.wikipedia.org/wiki/Artistic_License version 2.0 or later

- The https://en.wikipedia.org/wiki/ISC_license

- The https://opensource.org/licenses/BSD-2-Clause

Crediting me will be nice, but not mandatory, and you can change the licence
of the project without needing my permission.

libpurple/protocols/facebook/util.c file | annotate | diff | comparison | revisions
--- a/libpurple/protocols/facebook/util.c	Thu Nov 15 14:32:09 2018 -0600
+++ b/libpurple/protocols/facebook/util.c	Wed Nov 21 20:16:29 2018 +0200
@@ -342,6 +342,28 @@
 	g_free(mata);
 }
 
+static gint
+fb_buddy_cmp(gconstpointer a, gconstpointer b)
+{
+    gint alias_verdict, name_verdict;
+    gchar *astr, *bstr;
+
+    astr = g_utf8_casefold(purple_buddy_get_alias(a), -1);
+    bstr = g_utf8_casefold(purple_buddy_get_alias(b), -1);
+    alias_verdict = g_utf8_collate(astr, bstr);
+    g_free(astr);
+    g_free(bstr);
+    if (alias_verdict) {
+        return alias_verdict;
+    }
+    astr = g_utf8_casefold(purple_buddy_get_name(a), -1);
+    bstr = g_utf8_casefold(purple_buddy_get_name(b), -1);
+    name_verdict = g_utf8_collate(astr, bstr);
+    g_free(astr);
+    g_free(bstr);
+    return name_verdict;
+}
+
 gpointer
 fb_util_request_buddy(PurpleConnection *gc, const gchar *title,
                       const gchar *primary, const gchar *secondary,
@@ -368,7 +390,7 @@
 
 	acct = purple_connection_get_account(gc);
 	buddies = purple_blist_find_buddies(acct, NULL);
-	buddies = g_slist_sort(buddies, (GCompareFunc) g_ascii_strcasecmp);
+	buddies = g_slist_sort(buddies, fb_buddy_cmp);
 
 	fields = purple_request_fields_new();
 	group = purple_request_field_group_new(NULL);

mercurial