| 46 /* |
46 /* |
| 47 * Data specific to Chats. |
47 * Data specific to Chats. |
| 48 */ |
48 */ |
| 49 struct _PurpleChatConversationPrivate |
49 struct _PurpleChatConversationPrivate |
| 50 { |
50 { |
| 51 GList *in_room; /* The users in the room. |
|
| 52 Deprecated: Will be removed in 3.0.0 TODO */ |
|
| 53 GList *ignored; /* Ignored users. */ |
51 GList *ignored; /* Ignored users. */ |
| 54 char *who; /* The person who set the topic. */ |
52 char *who; /* The person who set the topic. */ |
| 55 char *topic; /* The topic. */ |
53 char *topic; /* The topic. */ |
| 56 int id; /* The chat ID. */ |
54 int id; /* The chat ID. */ |
| 57 char *nick; /* Your nick in this chat. */ |
55 char *nick; /* Your nick in this chat. */ |
| 923 "chat-user-joining", chat, user, flag)) || |
921 "chat-user-joining", chat, user, flag)) || |
| 924 purple_chat_conversation_is_ignored_user(chat, user); |
922 purple_chat_conversation_is_ignored_user(chat, user); |
| 925 |
923 |
| 926 chatuser = purple_chat_user_new(chat, user, alias, flag); |
924 chatuser = purple_chat_user_new(chat, user, alias, flag); |
| 927 |
925 |
| 928 priv->in_room = g_list_prepend(priv->in_room, chatuser); |
|
| 929 g_hash_table_replace(priv->users, |
926 g_hash_table_replace(priv->users, |
| 930 g_strdup(purple_chat_user_get_name(chatuser)), chatuser); |
927 g_strdup(purple_chat_user_get_name(chatuser)), |
| |
928 chatuser); |
| 931 |
929 |
| 932 cbuddies = g_list_prepend(cbuddies, chatuser); |
930 cbuddies = g_list_prepend(cbuddies, chatuser); |
| 933 |
931 |
| 934 if (!quiet && new_arrivals) { |
932 if (!quiet && new_arrivals) { |
| 935 char *alias_esc = g_markup_escape_text(alias, -1); |
933 char *alias_esc = g_markup_escape_text(alias, -1); |
| 1022 } |
1020 } |
| 1023 |
1021 |
| 1024 flags = purple_chat_user_get_flags(purple_chat_conversation_find_user(chat, old_user)); |
1022 flags = purple_chat_user_get_flags(purple_chat_conversation_find_user(chat, old_user)); |
| 1025 cb = purple_chat_user_new(chat, new_user, new_alias, flags); |
1023 cb = purple_chat_user_new(chat, new_user, new_alias, flags); |
| 1026 |
1024 |
| 1027 priv->in_room = g_list_prepend(priv->in_room, cb); |
|
| 1028 g_hash_table_replace(priv->users, |
1025 g_hash_table_replace(priv->users, |
| 1029 g_strdup(purple_chat_user_get_name(cb)), cb); |
1026 g_strdup(purple_chat_user_get_name(cb)), cb); |
| 1030 |
1027 |
| 1031 if (ops != NULL && ops->chat_rename_user != NULL) |
1028 if (ops != NULL && ops->chat_rename_user != NULL) |
| 1032 ops->chat_rename_user(chat, old_user, new_user, new_alias); |
1029 ops->chat_rename_user(chat, old_user, new_user, new_alias); |
| 1033 |
1030 |
| 1034 cb = purple_chat_conversation_find_user(chat, old_user); |
1031 cb = purple_chat_conversation_find_user(chat, old_user); |
| 1035 |
1032 |
| 1036 if (cb) { |
1033 if (cb) |
| 1037 priv->in_room = g_list_remove(priv->in_room, cb); |
|
| 1038 g_hash_table_remove(priv->users, purple_chat_user_get_name(cb)); |
1034 g_hash_table_remove(priv->users, purple_chat_user_get_name(cb)); |
| 1039 g_object_unref(cb); |
|
| 1040 } |
|
| 1041 |
1035 |
| 1042 if (purple_chat_conversation_is_ignored_user(chat, old_user)) { |
1036 if (purple_chat_conversation_is_ignored_user(chat, old_user)) { |
| 1043 purple_chat_conversation_unignore(chat, old_user); |
1037 purple_chat_conversation_unignore(chat, old_user); |
| 1044 purple_chat_conversation_ignore(chat, new_user); |
1038 purple_chat_conversation_ignore(chat, new_user); |
| 1045 } |
1039 } |
| 1129 purple_chat_conversation_is_ignored_user(chat, user); |
1123 purple_chat_conversation_is_ignored_user(chat, user); |
| 1130 |
1124 |
| 1131 cb = purple_chat_conversation_find_user(chat, user); |
1125 cb = purple_chat_conversation_find_user(chat, user); |
| 1132 |
1126 |
| 1133 if (cb) { |
1127 if (cb) { |
| 1134 priv->in_room = g_list_remove(priv->in_room, cb); |
1128 g_hash_table_remove(priv->users, |
| 1135 g_hash_table_remove(priv->users, purple_chat_user_get_name(cb)); |
1129 purple_chat_user_get_name(cb)); |
| 1136 g_object_unref(cb); |
|
| 1137 } |
1130 } |
| 1138 |
1131 |
| 1139 /* NOTE: Don't remove them from ignored in case they re-enter. */ |
1132 /* NOTE: Don't remove them from ignored in case they re-enter. */ |
| 1140 |
1133 |
| 1141 if (!quiet) { |
1134 if (!quiet) { |
| 1178 |
1171 |
| 1179 void |
1172 void |
| 1180 purple_chat_conversation_clear_users(PurpleChatConversation *chat) |
1173 purple_chat_conversation_clear_users(PurpleChatConversation *chat) |
| 1181 { |
1174 { |
| 1182 PurpleConversationUiOps *ops; |
1175 PurpleConversationUiOps *ops; |
| 1183 GList *users; |
1176 GHashTableIter it; |
| 1184 GList *l; |
|
| 1185 GList *names = NULL; |
|
| 1186 PurpleChatConversationPrivate *priv = PURPLE_CHAT_CONVERSATION_GET_PRIVATE(chat); |
1177 PurpleChatConversationPrivate *priv = PURPLE_CHAT_CONVERSATION_GET_PRIVATE(chat); |
| |
1178 gchar *name; |
| 1187 |
1179 |
| 1188 g_return_if_fail(priv != NULL); |
1180 g_return_if_fail(priv != NULL); |
| 1189 |
1181 |
| 1190 ops = purple_conversation_get_ui_ops(PURPLE_CONVERSATION(chat)); |
1182 ops = purple_conversation_get_ui_ops(PURPLE_CONVERSATION(chat)); |
| 1191 users = priv->in_room; |
|
| 1192 |
1183 |
| 1193 if (ops != NULL && ops->chat_remove_users != NULL) { |
1184 if (ops != NULL && ops->chat_remove_users != NULL) { |
| 1194 for (l = users; l; l = l->next) { |
1185 GList *names = NULL; |
| 1195 PurpleChatUser *cb = l->data; |
1186 |
| 1196 names = g_list_prepend(names, |
1187 g_hash_table_iter_init(&it, priv->users); |
| 1197 (gchar *) purple_chat_user_get_name(cb)); |
1188 while (g_hash_table_iter_next(&it, (gpointer*)&name, NULL)) |
| 1198 } |
1189 names = g_list_prepend(names, name); |
| |
1190 |
| 1199 ops->chat_remove_users(chat, names); |
1191 ops->chat_remove_users(chat, names); |
| 1200 g_list_free(names); |
1192 g_list_free(names); |
| 1201 } |
1193 } |
| 1202 |
1194 |
| 1203 for (l = users; l; l = l->next) |
1195 g_hash_table_iter_init(&it, priv->users); |
| 1204 { |
1196 while (g_hash_table_iter_next(&it, (gpointer*)&name, NULL)) { |
| 1205 PurpleChatUser *cb = l->data; |
|
| 1206 const char *name = purple_chat_user_get_name(cb); |
|
| 1207 |
|
| 1208 purple_signal_emit(purple_conversations_get_handle(), |
1197 purple_signal_emit(purple_conversations_get_handle(), |
| 1209 "chat-user-leaving", chat, name, NULL); |
1198 "chat-user-leaving", chat, name, NULL); |
| 1210 purple_signal_emit(purple_conversations_get_handle(), |
1199 purple_signal_emit(purple_conversations_get_handle(), |
| 1211 "chat-user-left", chat, name, NULL); |
1200 "chat-user-left", chat, name, NULL); |
| 1212 |
|
| 1213 g_object_unref(cb); |
|
| 1214 } |
1201 } |
| 1215 |
1202 |
| 1216 g_hash_table_remove_all(priv->users); |
1203 g_hash_table_remove_all(priv->users); |
| 1217 |
|
| 1218 g_list_free(users); |
|
| 1219 priv->in_room = NULL; |
|
| 1220 } |
1204 } |
| 1221 |
1205 |
| 1222 void purple_chat_conversation_set_nick(PurpleChatConversation *chat, const char *nick) { |
1206 void purple_chat_conversation_set_nick(PurpleChatConversation *chat, const char *nick) { |
| 1223 PurpleChatConversationPrivate *priv = PURPLE_CHAT_CONVERSATION_GET_PRIVATE(chat); |
1207 PurpleChatConversationPrivate *priv = PURPLE_CHAT_CONVERSATION_GET_PRIVATE(chat); |
| 1224 |
1208 |
| 1441 |
1425 |
| 1442 PURPLE_DBUS_REGISTER_POINTER(PURPLE_CHAT_CONVERSATION(instance), |
1426 PURPLE_DBUS_REGISTER_POINTER(PURPLE_CHAT_CONVERSATION(instance), |
| 1443 PurpleChatConversation); |
1427 PurpleChatConversation); |
| 1444 |
1428 |
| 1445 priv->users = g_hash_table_new_full(_purple_conversation_user_hash, |
1429 priv->users = g_hash_table_new_full(_purple_conversation_user_hash, |
| 1446 _purple_conversation_user_equal, g_free, NULL); |
1430 _purple_conversation_user_equal, g_free, g_object_unref); |
| 1447 } |
1431 } |
| 1448 |
1432 |
| 1449 /* Called when done constructing */ |
1433 /* Called when done constructing */ |
| 1450 static void |
1434 static void |
| 1451 purple_chat_conversation_constructed(GObject *object) |
1435 purple_chat_conversation_constructed(GObject *object) |
| 1475 purple_chat_conversation_dispose(GObject *object) |
1459 purple_chat_conversation_dispose(GObject *object) |
| 1476 { |
1460 { |
| 1477 PurpleChatConversationPrivate *priv = |
1461 PurpleChatConversationPrivate *priv = |
| 1478 PURPLE_CHAT_CONVERSATION_GET_PRIVATE(object); |
1462 PURPLE_CHAT_CONVERSATION_GET_PRIVATE(object); |
| 1479 |
1463 |
| 1480 if (priv->in_room) { |
1464 g_hash_table_remove_all(priv->users); |
| 1481 g_list_foreach(priv->in_room, (GFunc)g_object_unref, NULL); |
|
| 1482 g_list_free(priv->in_room); |
|
| 1483 priv->in_room = NULL; |
|
| 1484 } |
|
| 1485 |
1465 |
| 1486 G_OBJECT_CLASS(parent_class)->dispose(object); |
1466 G_OBJECT_CLASS(parent_class)->dispose(object); |
| 1487 } |
1467 } |
| 1488 |
1468 |
| 1489 /* GObject finalize function */ |
1469 /* GObject finalize function */ |