comparison src/conversation.c @ 8271:5c9cd9c97727

[gaim-migrate @ 8995] Conversation placement by account now works correctly with both chats and IMs, and takes the Combine Chats and IMs option into consideration. committer: Tailor Script <tailor@pidgin.im>
author Christian Hammond <chipx86@chipx86.com>
date Mon, 16 Feb 2004 23:22:45 +0000
parents 1d86096ae0f4
children f24172f53650
comparison
equal deleted inserted replaced
8270:27a713139d60 8271:5c9cd9c97727
776 g_return_val_if_fail(account != NULL, NULL); 776 g_return_val_if_fail(account != NULL, NULL);
777 g_return_val_if_fail(name != NULL, NULL); 777 g_return_val_if_fail(name != NULL, NULL);
778 778
779 /* Check if this conversation already exists. */ 779 /* Check if this conversation already exists. */
780 if (((conv = gaim_find_conversation_with_account(name, account)) != NULL) && 780 if (((conv = gaim_find_conversation_with_account(name, account)) != NULL) &&
781 (gaim_conversation_get_type(conv) == type)) { 781 (gaim_conversation_get_type(conv) == type))
782 782 {
783 if (gaim_conversation_get_type(conv) != GAIM_CONV_CHAT || 783 if (gaim_conversation_get_type(conv) != GAIM_CONV_CHAT ||
784 gaim_conv_chat_has_left(GAIM_CONV_CHAT(conv))) { 784 gaim_conv_chat_has_left(GAIM_CONV_CHAT(conv)))
785 {
785 if (gaim_conversation_get_type(conv) == GAIM_CONV_CHAT) 786 if (gaim_conversation_get_type(conv) == GAIM_CONV_CHAT)
786 gaim_conversation_chat_cleanup_for_rejoin(conv); 787 gaim_conversation_chat_cleanup_for_rejoin(conv);
787 788
788 return conv; 789 return conv;
789 } 790 }
798 conv->send_history = g_list_append(NULL, NULL); 799 conv->send_history = g_list_append(NULL, NULL);
799 conv->history = g_string_new(""); 800 conv->history = g_string_new("");
800 conv->data = g_hash_table_new_full(g_str_hash, g_str_equal, 801 conv->data = g_hash_table_new_full(g_str_hash, g_str_equal,
801 g_free, NULL); 802 g_free, NULL);
802 conv->log = gaim_log_new(type == GAIM_CONV_IM ? GAIM_LOG_IM : 803 conv->log = gaim_log_new(type == GAIM_CONV_IM ? GAIM_LOG_IM :
803 type == GAIM_CONV_CHAT ? GAIM_LOG_CHAT : GAIM_LOG_IM, name, account, time(NULL)); 804 type == GAIM_CONV_CHAT ? GAIM_LOG_CHAT :
805 GAIM_LOG_IM, name, account, time(NULL));
804 806
805 807
806 if (type == GAIM_CONV_IM) 808 if (type == GAIM_CONV_IM)
807 { 809 {
808 conv->u.im = g_new0(GaimConvIm, 1); 810 conv->u.im = g_new0(GaimConvIm, 1);
819 821
820 conv->u.chat = g_new0(GaimConvChat, 1); 822 conv->u.chat = g_new0(GaimConvChat, 1);
821 conv->u.chat->conv = conv; 823 conv->u.chat->conv = conv;
822 824
823 chats = g_list_append(chats, conv); 825 chats = g_list_append(chats, conv);
824 if((disp = gaim_connection_get_display_name(account->gc))) { 826
827 if ((disp = gaim_connection_get_display_name(account->gc)))
825 gaim_conv_chat_set_nick(conv->u.chat, disp); 828 gaim_conv_chat_set_nick(conv->u.chat, disp);
826 } else { 829 else
827 gaim_conv_chat_set_nick(conv->u.chat, gaim_account_get_username(account)); 830 gaim_conv_chat_set_nick(conv->u.chat,
828 } 831 gaim_account_get_username(account));
829 832
830 gaim_conversation_set_logging(conv, 833 gaim_conversation_set_logging(conv,
831 gaim_prefs_get_bool("/core/logging/log_chats")); 834 gaim_prefs_get_bool("/core/logging/log_chats"));
832 } 835 }
833 836
897 900
898 if (gc && prpl_info->convo_closed != NULL) 901 if (gc && prpl_info->convo_closed != NULL)
899 prpl_info->convo_closed(gc, name); 902 prpl_info->convo_closed(gc, name);
900 } 903 }
901 else if (gaim_conversation_get_type(conv) == GAIM_CONV_CHAT) { 904 else if (gaim_conversation_get_type(conv) == GAIM_CONV_CHAT) {
902 #if 0 905 #if 0
903 /* 906 /*
904 * This is unfortunately necessary, because calling 907 * This is unfortunately necessary, because calling
905 * serv_chat_leave() calls this gaim_conversation_destroy(), 908 * serv_chat_leave() calls this gaim_conversation_destroy(),
906 * which leads to two calls here.. We can't just return after 909 * which leads to two calls here.. We can't just return after
907 * this, because then it'll return on the next pass. So, since 910 * this, because then it'll return on the next pass. So, since
921 if (gc && g_slist_find(gc->buddy_chats, conv) != NULL) { 924 if (gc && g_slist_find(gc->buddy_chats, conv) != NULL) {
922 serv_chat_leave(gc, gaim_conv_chat_get_id(GAIM_CONV_CHAT(conv))); 925 serv_chat_leave(gc, gaim_conv_chat_get_id(GAIM_CONV_CHAT(conv)));
923 926
924 return; 927 return;
925 } 928 }
926 #endif 929 #endif
927 /* 930 /*
928 * Instead of all of that, lets just close the window when the user tells 931 * Instead of all of that, lets just close the window when the user tells
929 * us to, and let the prpl deal with the internals on it's own time. 932 * us to, and let the prpl deal with the internals on it's own time.
930 */ 933 */
931 serv_chat_leave(gc, gaim_conv_chat_get_id(GAIM_CONV_CHAT(conv))); 934 serv_chat_leave(gc, gaim_conv_chat_get_id(GAIM_CONV_CHAT(conv)));
2269 gaim_conv_window_add_conversation(win, conv); 2272 gaim_conv_window_add_conversation(win, conv);
2270 2273
2271 gaim_conv_window_show(win); 2274 gaim_conv_window_show(win);
2272 } 2275 }
2273 2276
2277 static GaimGroup *
2278 conv_get_group(GaimConversation *conv)
2279 {
2280 GaimGroup *group = NULL;
2281
2282 if (gaim_conversation_get_type(conv) == GAIM_CONV_IM)
2283 {
2284 GaimBuddy *buddy;
2285
2286 buddy = gaim_find_buddy(gaim_conversation_get_account(conv),
2287 gaim_conversation_get_name(conv));
2288
2289 if (buddy != NULL)
2290 group = gaim_find_buddys_group(buddy);
2291
2292 }
2293 else if (gaim_conversation_get_type(conv) == GAIM_CONV_CHAT)
2294 {
2295 GaimChat *chat;
2296
2297 chat = gaim_blist_find_chat(gaim_conversation_get_account(conv),
2298 gaim_conversation_get_name(conv));
2299
2300 if (chat != NULL)
2301 group = gaim_chat_get_group(chat);
2302 }
2303
2304 return group;
2305 }
2306
2274 /* 2307 /*
2275 * This groups things by, well, group. Buddies from groups will always be 2308 * This groups things by, well, group. Buddies from groups will always be
2276 * grouped together, and a buddy from a group not belonging to any currently 2309 * grouped together, and a buddy from a group not belonging to any currently
2277 * open windows will get a new window. 2310 * open windows will get a new window.
2278 */ 2311 */
2279 static void 2312 static void
2280 conv_placement_by_group(GaimConversation *conv) 2313 conv_placement_by_group(GaimConversation *conv)
2281 { 2314 {
2282 GaimConvWindow *win;
2283 GaimConversationType type; 2315 GaimConversationType type;
2316 GaimGroup *group = NULL;
2317 GList *wl, *cl;
2284 2318
2285 type = gaim_conversation_get_type(conv); 2319 type = gaim_conversation_get_type(conv);
2286 2320
2287 if (type == GAIM_CONV_IM) { 2321 group = conv_get_group(conv);
2288 GaimBuddy *b; 2322
2289 GaimGroup *grp = NULL; 2323 /* Go through the list of IMs and find one with this group. */
2290 GList *wins, *convs; 2324 for (wl = gaim_get_windows(); wl != NULL; wl = wl->next)
2291 2325 {
2292 b = gaim_find_buddy(gaim_conversation_get_account(conv), 2326 GaimConvWindow *win2;
2293 gaim_conversation_get_name(conv)); 2327 GaimConversation *conv2;
2294 2328 GaimGroup *group2 = NULL;
2295 if (b != NULL) 2329
2296 grp = gaim_find_buddys_group(b); 2330 win2 = (GaimConvWindow *)wl->data;
2297 2331
2298 /* Go through the list of IMs and find one with this group. */ 2332 for (cl = gaim_conv_window_get_conversations(win2);
2299 for (wins = gaim_get_windows(); wins != NULL; wins = wins->next) { 2333 cl != NULL;
2300 GaimConvWindow *win2; 2334 cl = cl->next)
2301 GaimConversation *conv2; 2335 {
2302 GaimBuddy *b2; 2336 conv2 = (GaimConversation *)cl->data;
2303 GaimGroup *g2 = NULL; 2337
2304 2338 group2 = conv_get_group(conv2);
2305 win2 = (GaimConvWindow *)wins->data; 2339
2306 2340 if ((gaim_prefs_get_bool("/core/conversations/combine_chat_im") ||
2307 for (convs = gaim_conv_window_get_conversations(win2); 2341 type == gaim_conversation_get_type(conv2)) &&
2308 convs != NULL; 2342 group == group2)
2309 convs = convs->next) { 2343 {
2310 2344 gaim_conv_window_add_conversation(win2, conv);
2311 conv2 = (GaimConversation *)convs->data; 2345
2312 2346 return;
2313 b2 = gaim_find_buddy(gaim_conversation_get_account(conv2),
2314 gaim_conversation_get_name(conv2));
2315
2316 if (b2 != NULL)
2317 g2 = gaim_find_buddys_group(b2);
2318
2319 if (grp == g2) {
2320 gaim_conv_window_add_conversation(win2, conv);
2321
2322 return;
2323 }
2324 } 2347 }
2325 } 2348 }
2326 2349 }
2327 /* Make a new window. */ 2350
2328 conv_placement_new_window(conv); 2351 /* Make a new window. */
2329 } 2352 conv_placement_new_window(conv);
2330 else if (type == GAIM_CONV_CHAT) {
2331 GaimChat *chat;
2332 GaimGroup *group = NULL;
2333 GList *wins, *convs;
2334
2335 chat = gaim_blist_find_chat(gaim_conversation_get_account(conv),
2336 gaim_conversation_get_name(conv));
2337
2338 if (chat != NULL)
2339 group = gaim_chat_get_group(chat);
2340
2341 /* Go through the list of chats and find one with this group. */
2342 for (wins = gaim_get_windows(); wins != NULL; wins = wins->next) {
2343 GaimConvWindow *win2;
2344 GaimConversation *conv2;
2345 GaimChat *chat2;
2346 GaimGroup *group2 = NULL;
2347
2348 win2 = (GaimConvWindow *)wins->data;
2349
2350 for (convs = gaim_conv_window_get_conversations(win2);
2351 convs != NULL;
2352 convs = convs->next) {
2353
2354 conv2 = (GaimConversation *)convs->data;
2355
2356 chat2 = gaim_blist_find_chat(
2357 gaim_conversation_get_account(conv2),
2358 gaim_conversation_get_name(conv2));
2359
2360 if (chat2 != NULL)
2361 group2 = gaim_chat_get_group(chat2);
2362
2363 if (group == group2) {
2364 gaim_conv_window_add_conversation(win2, conv);
2365
2366 return;
2367 }
2368 }
2369 }
2370
2371 /* Make a new window. */
2372 conv_placement_new_window(conv);
2373 }
2374 else {
2375 win = gaim_get_last_window_with_type(type);
2376
2377 if (win == NULL)
2378 conv_placement_new_window(conv);
2379 else
2380 gaim_conv_window_add_conversation(win, conv);
2381 }
2382 } 2353 }
2383 2354
2384 /* This groups things by account. Otherwise, the same semantics as above */ 2355 /* This groups things by account. Otherwise, the same semantics as above */
2385 static void 2356 static void
2386 conv_placement_by_account(GaimConversation *conv) 2357 conv_placement_by_account(GaimConversation *conv)
2390 GaimAccount *account; 2361 GaimAccount *account;
2391 2362
2392 account = gaim_conversation_get_account(conv); 2363 account = gaim_conversation_get_account(conv);
2393 type = gaim_conversation_get_type(conv); 2364 type = gaim_conversation_get_type(conv);
2394 2365
2395
2396 /* Go through the list of IMs and find one with this group. */ 2366 /* Go through the list of IMs and find one with this group. */
2397 for (wins = gaim_get_windows(); wins != NULL; wins = wins->next) { 2367 for (wins = gaim_get_windows(); wins != NULL; wins = wins->next)
2368 {
2398 GaimConvWindow *win2; 2369 GaimConvWindow *win2;
2399 GaimConversation *conv2; 2370 GaimConversation *conv2;
2400 2371
2401 win2 = (GaimConvWindow *)wins->data; 2372 win2 = (GaimConvWindow *)wins->data;
2402 2373
2403 for (convs = gaim_conv_window_get_conversations(win2); 2374 for (convs = gaim_conv_window_get_conversations(win2);
2404 convs != NULL; 2375 convs != NULL;
2405 convs = convs->next) { 2376 convs = convs->next)
2406 2377 {
2407 conv2 = (GaimConversation *)convs->data; 2378 conv2 = (GaimConversation *)convs->data;
2408 2379
2409 if ((gaim_prefs_get_bool("/core/conversations/combine_chat_im") || 2380 if ((gaim_prefs_get_bool("/core/conversations/combine_chat_im") ||
2410 type == gaim_conversation_get_type(conv2)) && 2381 type == gaim_conversation_get_type(conv2)) &&
2411 account == gaim_conversation_get_account(conv2)) { 2382 account == gaim_conversation_get_account(conv2))
2412 2383 {
2413 gaim_conv_window_add_conversation(win2, conv); 2384 gaim_conv_window_add_conversation(win2, conv);
2414 return; 2385 return;
2415 } 2386 }
2416
2417 } 2387 }
2418 } 2388 }
2419 2389
2420 /* Make a new window. */ 2390 /* Make a new window. */
2421 conv_placement_new_window(conv); 2391 conv_placement_new_window(conv);