comparison libpurple/conversation.c @ 31702:47c604efed32

propagate from branch 'im.pidgin.pidgin.2.9.0' (head d3dccc0843de29ce8d5c7e2e017028396dc2b46b) to branch 'im.pidgin.pidgin' (head cfa2120bb1d7c408937f3075c018fb10c1e6eefa)
author Ethan Blanton <elb@pidgin.im>
date Fri, 24 Jun 2011 16:44:06 +0000
parents 5ffd5582f5fe
children
comparison
equal deleted inserted replaced
31684:6e5d46ea82f9 31702:47c604efed32
68 { 68 {
69 g_free(hc->name); 69 g_free(hc->name);
70 g_free(hc); 70 g_free(hc);
71 } 71 }
72 72
73 static guint _purple_conversation_user_hash(gconstpointer data)
74 {
75 const gchar *name = data;
76 gchar *collated;
77 guint hash;
78
79 collated = g_utf8_collate_key(name, -1);
80 hash = g_str_hash(collated);
81 g_free(collated);
82 return hash;
83 }
84
85 static gboolean _purple_conversation_user_equal(gconstpointer a, gconstpointer b)
86 {
87 return !g_utf8_collate(a, b);
88 }
89
73 void 90 void
74 purple_conversations_set_ui_ops(PurpleConversationUiOps *ops) 91 purple_conversations_set_ui_ops(PurpleConversationUiOps *ops)
75 { 92 {
76 default_ops = ops; 93 default_ops = ops;
77 } 94 }
391 { 408 {
392 const char *disp; 409 const char *disp;
393 410
394 conv->u.chat = g_new0(PurpleConvChat, 1); 411 conv->u.chat = g_new0(PurpleConvChat, 1);
395 conv->u.chat->conv = conv; 412 conv->u.chat->conv = conv;
413 conv->u.chat->users = g_hash_table_new_full(_purple_conversation_user_hash,
414 _purple_conversation_user_equal, g_free, NULL);
396 PURPLE_DBUS_REGISTER_POINTER(conv->u.chat, PurpleConvChat); 415 PURPLE_DBUS_REGISTER_POINTER(conv->u.chat, PurpleConvChat);
397 416
398 chats = g_list_prepend(chats, conv); 417 chats = g_list_prepend(chats, conv);
399 418
400 if ((disp = purple_connection_get_display_name(account->gc))) 419 if ((disp = purple_connection_get_display_name(account->gc)))
545 PURPLE_DBUS_UNREGISTER_POINTER(conv->u.im); 564 PURPLE_DBUS_UNREGISTER_POINTER(conv->u.im);
546 g_free(conv->u.im); 565 g_free(conv->u.im);
547 conv->u.im = NULL; 566 conv->u.im = NULL;
548 } 567 }
549 else if (conv->type == PURPLE_CONV_TYPE_CHAT) { 568 else if (conv->type == PURPLE_CONV_TYPE_CHAT) {
569 g_hash_table_destroy(conv->u.chat->users);
570 conv->u.chat->users = NULL;
550 571
551 g_list_foreach(conv->u.chat->in_room, (GFunc)purple_conv_chat_cb_destroy, NULL); 572 g_list_foreach(conv->u.chat->in_room, (GFunc)purple_conv_chat_cb_destroy, NULL);
552 g_list_free(conv->u.chat->in_room); 573 g_list_free(conv->u.chat->in_room);
553 574
554 g_list_foreach(conv->u.chat->ignored, (GFunc)g_free, NULL); 575 g_list_foreach(conv->u.chat->ignored, (GFunc)g_free, NULL);
1675 "chat-buddy-joining", conv, user, flag)) || 1696 "chat-buddy-joining", conv, user, flag)) ||
1676 purple_conv_chat_is_user_ignored(chat, user); 1697 purple_conv_chat_is_user_ignored(chat, user);
1677 1698
1678 cbuddy = purple_conv_chat_cb_new(user, alias, flag); 1699 cbuddy = purple_conv_chat_cb_new(user, alias, flag);
1679 cbuddy->buddy = purple_find_buddy(conv->account, user) != NULL; 1700 cbuddy->buddy = purple_find_buddy(conv->account, user) != NULL;
1680 /* This seems dumb. Why should we set users thousands of times? */ 1701
1681 purple_conv_chat_set_users(chat, 1702 chat->in_room = g_list_prepend(chat->in_room, cbuddy);
1682 g_list_prepend(chat->in_room, cbuddy)); 1703 g_hash_table_replace(chat->users, g_strdup(cbuddy->name), cbuddy);
1683 1704
1684 cbuddies = g_list_prepend(cbuddies, cbuddy); 1705 cbuddies = g_list_prepend(cbuddies, cbuddy);
1685 1706
1686 if (!quiet && new_arrivals) { 1707 if (!quiet && new_arrivals) {
1687 char *alias_esc = g_markup_escape_text(alias, -1); 1708 char *alias_esc = g_markup_escape_text(alias, -1);
1769 } 1790 }
1770 1791
1771 flags = purple_conv_chat_user_get_flags(chat, old_user); 1792 flags = purple_conv_chat_user_get_flags(chat, old_user);
1772 cb = purple_conv_chat_cb_new(new_user, new_alias, flags); 1793 cb = purple_conv_chat_cb_new(new_user, new_alias, flags);
1773 cb->buddy = purple_find_buddy(conv->account, new_user) != NULL; 1794 cb->buddy = purple_find_buddy(conv->account, new_user) != NULL;
1774 purple_conv_chat_set_users(chat, 1795
1775 g_list_prepend(chat->in_room, cb)); 1796 chat->in_room = g_list_prepend(chat->in_room, cb);
1797 g_hash_table_replace(chat->users, g_strdup(cb->name), cb);
1776 1798
1777 if (ops != NULL && ops->chat_rename_user != NULL) 1799 if (ops != NULL && ops->chat_rename_user != NULL)
1778 ops->chat_rename_user(conv, old_user, new_user, new_alias); 1800 ops->chat_rename_user(conv, old_user, new_user, new_alias);
1779 1801
1780 cb = purple_conv_chat_cb_find(chat, old_user); 1802 cb = purple_conv_chat_cb_find(chat, old_user);
1781 1803
1782 if (cb) { 1804 if (cb) {
1783 purple_conv_chat_set_users(chat, 1805 chat->in_room = g_list_remove(chat->in_room, cb);
1784 g_list_remove(chat->in_room, cb)); 1806 g_hash_table_remove(chat->users, cb->name);
1785 purple_conv_chat_cb_destroy(cb); 1807 purple_conv_chat_cb_destroy(cb);
1786 } 1808 }
1787 1809
1788 if (purple_conv_chat_is_user_ignored(chat, old_user)) { 1810 if (purple_conv_chat_is_user_ignored(chat, old_user)) {
1789 purple_conv_chat_unignore(chat, old_user); 1811 purple_conv_chat_unignore(chat, old_user);
1872 purple_conv_chat_is_user_ignored(chat, user); 1894 purple_conv_chat_is_user_ignored(chat, user);
1873 1895
1874 cb = purple_conv_chat_cb_find(chat, user); 1896 cb = purple_conv_chat_cb_find(chat, user);
1875 1897
1876 if (cb) { 1898 if (cb) {
1877 purple_conv_chat_set_users(chat, 1899 chat->in_room = g_list_remove(chat->in_room, cb);
1878 g_list_remove(chat->in_room, cb)); 1900 g_hash_table_remove(chat->users, cb->name);
1879 purple_conv_chat_cb_destroy(cb); 1901 purple_conv_chat_cb_destroy(cb);
1880 } 1902 }
1881 1903
1882 /* NOTE: Don't remove them from ignored in case they re-enter. */ 1904 /* NOTE: Don't remove them from ignored in case they re-enter. */
1883 1905
1953 "chat-buddy-left", conv, cb->name, NULL); 1975 "chat-buddy-left", conv, cb->name, NULL);
1954 1976
1955 purple_conv_chat_cb_destroy(cb); 1977 purple_conv_chat_cb_destroy(cb);
1956 } 1978 }
1957 1979
1980 g_hash_table_remove_all(chat->users);
1981 chat->users = NULL;
1982
1958 g_list_free(users); 1983 g_list_free(users);
1959 purple_conv_chat_set_users(chat, NULL); 1984 chat->in_room = NULL;
1960 } 1985 }
1961 1986
1962 1987
1963 gboolean 1988 gboolean
1964 purple_conv_chat_find_user(PurpleConvChat *chat, const char *user) 1989 purple_conv_chat_find_user(PurpleConvChat *chat, const char *user)
2144 } 2169 }
2145 2170
2146 PurpleConvChatBuddy * 2171 PurpleConvChatBuddy *
2147 purple_conv_chat_cb_find(PurpleConvChat *chat, const char *name) 2172 purple_conv_chat_cb_find(PurpleConvChat *chat, const char *name)
2148 { 2173 {
2149 GList *l;
2150 PurpleConvChatBuddy *cb = NULL;
2151
2152 g_return_val_if_fail(chat != NULL, NULL); 2174 g_return_val_if_fail(chat != NULL, NULL);
2153 g_return_val_if_fail(name != NULL, NULL); 2175 g_return_val_if_fail(name != NULL, NULL);
2154 2176
2155 for (l = purple_conv_chat_get_users(chat); l; l = l->next) { 2177 return g_hash_table_lookup(chat->users, name);
2156 cb = l->data;
2157 if (!g_utf8_collate(cb->name, name))
2158 return cb;
2159 }
2160
2161 return NULL;
2162 } 2178 }
2163 2179
2164 void 2180 void
2165 purple_conv_chat_cb_destroy(PurpleConvChatBuddy *cb) 2181 purple_conv_chat_cb_destroy(PurpleConvChatBuddy *cb)
2166 { 2182 {
2167 if (cb == NULL) 2183 if (cb == NULL)
2168 return; 2184 return;
2185
2186 purple_signal_emit(purple_conversations_get_handle(),
2187 "deleting-chat-buddy", cb);
2169 2188
2170 g_free(cb->alias); 2189 g_free(cb->alias);
2171 g_free(cb->alias_key); 2190 g_free(cb->alias_key);
2172 g_free(cb->name); 2191 g_free(cb->name);
2173 g_hash_table_destroy(cb->attributes); 2192 g_hash_table_destroy(cb->attributes);
2571 purple_value_new(PURPLE_TYPE_SUBTYPE, 2590 purple_value_new(PURPLE_TYPE_SUBTYPE,
2572 PURPLE_SUBTYPE_CONVERSATION), 2591 PURPLE_SUBTYPE_CONVERSATION),
2573 purple_value_new(PURPLE_TYPE_STRING), 2592 purple_value_new(PURPLE_TYPE_STRING),
2574 purple_value_new(PURPLE_TYPE_STRING)); 2593 purple_value_new(PURPLE_TYPE_STRING));
2575 2594
2595 purple_signal_register(handle, "deleting-chat-buddy",
2596 purple_marshal_VOID__POINTER, NULL, 1,
2597 purple_value_new(PURPLE_TYPE_SUBTYPE,
2598 PURPLE_SUBTYPE_CHATBUDDY));
2599
2576 purple_signal_register(handle, "chat-inviting-user", 2600 purple_signal_register(handle, "chat-inviting-user",
2577 purple_marshal_VOID__POINTER_POINTER_POINTER, NULL, 3, 2601 purple_marshal_VOID__POINTER_POINTER_POINTER, NULL, 3,
2578 purple_value_new(PURPLE_TYPE_SUBTYPE, 2602 purple_value_new(PURPLE_TYPE_SUBTYPE,
2579 PURPLE_SUBTYPE_CONVERSATION), 2603 PURPLE_SUBTYPE_CONVERSATION),
2580 purple_value_new(PURPLE_TYPE_STRING), 2604 purple_value_new(PURPLE_TYPE_STRING),