1
1
mirror of https://github.com/profanity-im/profanity.git synced 2025-02-02 15:08:15 -05:00

Sort room participants on /who command

This commit is contained in:
James Booth 2013-05-30 22:05:52 +01:00
parent 1ca2147844
commit 378ed3139a

View File

@ -46,6 +46,7 @@ GHashTable *rooms = NULL;
Autocomplete invite_ac; Autocomplete invite_ac;
static void _free_room(ChatRoom *room); static void _free_room(ChatRoom *room);
static gint _compare_participants(PContact a, PContact b);
void void
muc_init(void) muc_init(void)
@ -335,7 +336,17 @@ muc_get_roster(const char * const room)
ChatRoom *chat_room = g_hash_table_lookup(rooms, room); ChatRoom *chat_room = g_hash_table_lookup(rooms, room);
if (chat_room != NULL) { 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 { } else {
return NULL; return NULL;
} }
@ -458,3 +469,20 @@ _free_room(ChatRoom *room)
} }
room = NULL; 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;
}