diff options
author | James Booth <boothj5@gmail.com> | 2013-05-30 22:05:52 +0100 |
---|---|---|
committer | James Booth <boothj5@gmail.com> | 2013-05-30 22:05:52 +0100 |
commit | 378ed3139a8c752292656b24fe8d0335356f03c6 (patch) | |
tree | 2f2163c7244f96218ece5026e4c96936eb294134 /src/muc.c | |
parent | 1ca2147844c4a72404d21389fa7716a9168a8fd9 (diff) | |
download | profani-tty-378ed3139a8c752292656b24fe8d0335356f03c6.tar.gz |
Sort room participants on /who command
Diffstat (limited to 'src/muc.c')
-rw-r--r-- | src/muc.c | 30 |
1 files changed, 29 insertions, 1 deletions
diff --git a/src/muc.c b/src/muc.c index 0e0a879d..464d3e1b 100644 --- a/src/muc.c +++ b/src/muc.c @@ -46,6 +46,7 @@ GHashTable *rooms = NULL; Autocomplete invite_ac; static void _free_room(ChatRoom *room); +static gint _compare_participants(PContact a, PContact b); void muc_init(void) @@ -335,7 +336,17 @@ muc_get_roster(const char * const room) ChatRoom *chat_room = g_hash_table_lookup(rooms, room); if (chat_room != NULL) { - return g_hash_table_get_values(chat_room->roster); + GList *result = NULL; + GHashTableIter iter; + gpointer key; + gpointer value; + + g_hash_table_iter_init(&iter, chat_room->roster); + while (g_hash_table_iter_next(&iter, &key, &value)) { + result = g_list_insert_sorted(result, value, (GCompareFunc)_compare_participants); + } + + return result; } else { return NULL; } @@ -458,3 +469,20 @@ _free_room(ChatRoom *room) } room = NULL; } + +static +gint _compare_participants(PContact a, PContact b) +{ + const char * utf8_str_a = p_contact_barejid(a); + const char * utf8_str_b = p_contact_barejid(b); + + gchar *key_a = g_utf8_collate_key(utf8_str_a, -1); + gchar *key_b = g_utf8_collate_key(utf8_str_b, -1); + + gint result = g_strcmp0(key_a, key_b); + + g_free(key_a); + g_free(key_b); + + return result; +} |