diff -r 4f67d1f0418c -r c03fc85a391f libpurple/conversation.c --- a/libpurple/conversation.c Tue Jun 21 04:46:11 2011 +0000 +++ b/libpurple/conversation.c Wed Jun 22 02:48:46 2011 +0000 @@ -70,6 +70,23 @@ g_free(hc); } +static guint _purple_conversation_user_hash(gconstpointer data) +{ + const gchar *name = data; + gchar *collated; + guint hash; + + collated = g_utf8_collate_key(name, -1); + hash = g_str_hash(collated); + g_free(collated); + return hash; +} + +static gboolean _purple_conversation_user_equal(gconstpointer a, gconstpointer b) +{ + return !g_utf8_collate(a, b); +} + void purple_conversations_set_ui_ops(PurpleConversationUiOps *ops) { @@ -393,6 +410,8 @@ conv->u.chat = g_new0(PurpleConvChat, 1); conv->u.chat->conv = conv; + conv->u.chat->users = g_hash_table_new_full(_purple_conversation_user_hash, + _purple_conversation_user_equal, g_free, NULL); PURPLE_DBUS_REGISTER_POINTER(conv->u.chat, PurpleConvChat); chats = g_list_prepend(chats, conv); @@ -547,6 +566,8 @@ conv->u.im = NULL; } else if (conv->type == PURPLE_CONV_TYPE_CHAT) { + g_hash_table_destroy(conv->u.chat->users); + conv->u.chat->users = NULL; g_list_foreach(conv->u.chat->in_room, (GFunc)purple_conv_chat_cb_destroy, NULL); g_list_free(conv->u.chat->in_room); @@ -1677,9 +1698,9 @@ cbuddy = purple_conv_chat_cb_new(user, alias, flag); cbuddy->buddy = purple_find_buddy(conv->account, user) != NULL; - /* This seems dumb. Why should we set users thousands of times? */ - purple_conv_chat_set_users(chat, - g_list_prepend(chat->in_room, cbuddy)); + + chat->in_room = g_list_prepend(chat->in_room, cbuddy); + g_hash_table_replace(chat->users, g_strdup(cbuddy->name), cbuddy); cbuddies = g_list_prepend(cbuddies, cbuddy); @@ -1771,8 +1792,9 @@ flags = purple_conv_chat_user_get_flags(chat, old_user); cb = purple_conv_chat_cb_new(new_user, new_alias, flags); cb->buddy = purple_find_buddy(conv->account, new_user) != NULL; - purple_conv_chat_set_users(chat, - g_list_prepend(chat->in_room, cb)); + + chat->in_room = g_list_prepend(chat->in_room, cb); + g_hash_table_replace(chat->users, g_strdup(cb->name), cb); if (ops != NULL && ops->chat_rename_user != NULL) ops->chat_rename_user(conv, old_user, new_user, new_alias); @@ -1780,8 +1802,8 @@ cb = purple_conv_chat_cb_find(chat, old_user); if (cb) { - purple_conv_chat_set_users(chat, - g_list_remove(chat->in_room, cb)); + chat->in_room = g_list_remove(chat->in_room, cb); + g_hash_table_remove(chat->users, cb->name); purple_conv_chat_cb_destroy(cb); } @@ -1874,8 +1896,8 @@ cb = purple_conv_chat_cb_find(chat, user); if (cb) { - purple_conv_chat_set_users(chat, - g_list_remove(chat->in_room, cb)); + chat->in_room = g_list_remove(chat->in_room, cb); + g_hash_table_remove(chat->users, cb->name); purple_conv_chat_cb_destroy(cb); } @@ -1955,8 +1977,11 @@ purple_conv_chat_cb_destroy(cb); } + g_hash_table_remove_all(chat->users); + chat->users = NULL; + g_list_free(users); - purple_conv_chat_set_users(chat, NULL); + chat->in_room = NULL; } @@ -2146,19 +2171,10 @@ PurpleConvChatBuddy * purple_conv_chat_cb_find(PurpleConvChat *chat, const char *name) { - GList *l; - PurpleConvChatBuddy *cb = NULL; - g_return_val_if_fail(chat != NULL, NULL); g_return_val_if_fail(name != NULL, NULL); - for (l = purple_conv_chat_get_users(chat); l; l = l->next) { - cb = l->data; - if (!g_utf8_collate(cb->name, name)) - return cb; - } - - return NULL; + return g_hash_table_lookup(chat->users, name); } void @@ -2167,6 +2183,9 @@ if (cb == NULL) return; + purple_signal_emit(purple_conversations_get_handle(), + "deleting-chat-buddy", cb); + g_free(cb->alias); g_free(cb->alias_key); g_free(cb->name); @@ -2573,6 +2592,11 @@ purple_value_new(PURPLE_TYPE_STRING), purple_value_new(PURPLE_TYPE_STRING)); + purple_signal_register(handle, "deleting-chat-buddy", + purple_marshal_VOID__POINTER, NULL, 1, + purple_value_new(PURPLE_TYPE_SUBTYPE, + PURPLE_SUBTYPE_CHATBUDDY)); + purple_signal_register(handle, "chat-inviting-user", purple_marshal_VOID__POINTER_POINTER_POINTER, NULL, 3, purple_value_new(PURPLE_TYPE_SUBTYPE,