comparison src/conversation.c @ 13965:df0dba522147

[gaim-migrate @ 16521] Merges soc-2006-chat-speed into trunk. (r16371:r16435) Joining large chat rooms, like IRC rooms, is much quicker. Additional improvment should be seen when using >=GTK+-2.6. committer: Tailor Script <tailor@pidgin.im>
author Aaron Sheldon <aaronsheldon>
date Wed, 19 Jul 2006 20:14:58 +0000
parents 7d513e44201b
children 8934a27fed4b
comparison
equal deleted inserted replaced
13964:0a0d2a1fd2bc 13965:df0dba522147
36 static GList *conversations = NULL; 36 static GList *conversations = NULL;
37 static GList *ims = NULL; 37 static GList *ims = NULL;
38 static GList *chats = NULL; 38 static GList *chats = NULL;
39 static GaimConversationUiOps *default_ops = NULL; 39 static GaimConversationUiOps *default_ops = NULL;
40 40
41
42 void 41 void
43 gaim_conversations_set_ui_ops(GaimConversationUiOps *ops) 42 gaim_conversations_set_ui_ops(GaimConversationUiOps *ops)
44 { 43 {
45 default_ops = ops; 44 default_ops = ops;
46 } 45 }
1439 g_list_free(users); 1438 g_list_free(users);
1440 g_list_free(extra_msgs); 1439 g_list_free(extra_msgs);
1441 g_list_free(flags2); 1440 g_list_free(flags2);
1442 } 1441 }
1443 1442
1443 int
1444 gaim_conv_chat_cb_compare(GaimConvChatBuddy *a, GaimConvChatBuddy *b)
1445 {
1446 GaimConvChatBuddyFlags f1 = 0, f2 = 0;
1447 char *user1 = NULL, *user2 = NULL;
1448 gint ret = 0;
1449
1450
1451 if (a) {
1452 f1 = a->flags;
1453 if (a->alias_key)
1454 user1 = a->alias_key;
1455 else if (a->name)
1456 user1 = a->name;
1457 }
1458
1459 if (b) {
1460 f2 = b->flags;
1461 if (b->alias_key)
1462 user2 = b->alias_key;
1463 else if (b->name)
1464 user2 = b->name;
1465 }
1466
1467 if (user1 == NULL || user2 == NULL) {
1468 if (!(user1 == NULL && user2 == NULL))
1469 ret = (user1 == NULL) ? -1: 1;
1470 } else if (f1 != f2) {
1471 /* sort more important users first */
1472 ret = (f1 > f2) ? -1 : 1;
1473 } else if (a->buddy != b->buddy) {
1474 ret = a->buddy ? -1 : 1;
1475 } else {
1476 ret = strcasecmp(user1, user2);
1477 }
1478
1479 return ret;
1480 }
1481
1444 void 1482 void
1445 gaim_conv_chat_add_users(GaimConvChat *chat, GList *users, GList *extra_msgs, 1483 gaim_conv_chat_add_users(GaimConvChat *chat, GList *users, GList *extra_msgs,
1446 GList *flags, gboolean new_arrivals) 1484 GList *flags, gboolean new_arrivals)
1447 { 1485 {
1448 GaimConversation *conv; 1486 GaimConversation *conv;
1449 GaimConversationUiOps *ops; 1487 GaimConversationUiOps *ops;
1450 GaimConvChatBuddy *cb; 1488 GaimConvChatBuddy *cb;
1451 GaimConnection *gc; 1489 GaimConnection *gc;
1452 GaimPluginProtocolInfo *prpl_info; 1490 GaimPluginProtocolInfo *prpl_info;
1453 GList *ul, *fl; 1491 GList *ul, *fl;
1454 GList *aliases = NULL; 1492 GList *cbuddies = NULL;
1455 1493
1456 g_return_if_fail(chat != NULL); 1494 g_return_if_fail(chat != NULL);
1457 g_return_if_fail(users != NULL); 1495 g_return_if_fail(users != NULL);
1458 1496
1459 conv = gaim_conv_chat_get_conversation(chat); 1497 conv = gaim_conv_chat_get_conversation(chat);
1468 fl = flags; 1506 fl = flags;
1469 while ((ul != NULL) && (fl != NULL)) { 1507 while ((ul != NULL) && (fl != NULL)) {
1470 const char *user = (const char *)ul->data; 1508 const char *user = (const char *)ul->data;
1471 const char *alias = user; 1509 const char *alias = user;
1472 gboolean quiet; 1510 gboolean quiet;
1511 GaimConvChatBuddy *cbuddy;
1473 GaimConvChatBuddyFlags flags = GPOINTER_TO_INT(fl->data); 1512 GaimConvChatBuddyFlags flags = GPOINTER_TO_INT(fl->data);
1474 const char *extra_msg = (extra_msgs ? extra_msgs->data : NULL); 1513 const char *extra_msg = (extra_msgs ? extra_msgs->data : NULL);
1514
1515 cbuddy = gaim_conv_chat_cb_new(user, NULL, GPOINTER_TO_INT(fl->data));
1475 1516
1476 if (!strcmp(chat->nick, gaim_normalize(conv->account, user))) { 1517 if (!strcmp(chat->nick, gaim_normalize(conv->account, user))) {
1477 const char *alias2 = gaim_account_get_alias(conv->account); 1518 const char *alias2 = gaim_account_get_alias(conv->account);
1478 if (alias2 != NULL) 1519 if (alias2 != NULL)
1479 alias = alias2; 1520 alias = alias2;
1491 1532
1492 quiet = GPOINTER_TO_INT(gaim_signal_emit_return_1(gaim_conversations_get_handle(), 1533 quiet = GPOINTER_TO_INT(gaim_signal_emit_return_1(gaim_conversations_get_handle(),
1493 "chat-buddy-joining", conv, user, flags)) | 1534 "chat-buddy-joining", conv, user, flags)) |
1494 gaim_conv_chat_is_user_ignored(chat, user); 1535 gaim_conv_chat_is_user_ignored(chat, user);
1495 1536
1496 cb = gaim_conv_chat_cb_new(user, flags); 1537 cb = gaim_conv_chat_cb_new(user, NULL, flags);
1538 /* This seems dumb. Why should we set users thousands of times? */
1497 gaim_conv_chat_set_users(chat, 1539 gaim_conv_chat_set_users(chat,
1498 g_list_prepend(gaim_conv_chat_get_users(chat), cb)); 1540 g_list_prepend(gaim_conv_chat_get_users(chat), cb));
1499 /* We reverse this later to keep it in the same order as users. */ 1541
1500 aliases = g_list_prepend(aliases, (char *)alias); 1542 cbuddy->alias = strdup(alias); /* Should I be doing a strdup? */
1543 cbuddy->alias_key = g_utf8_collate_key(alias, strlen(alias));
1544 cbuddy->buddy = (gaim_find_buddy(conv->account, cbuddy->name) != NULL);
1545 cbuddies = g_list_prepend(cbuddies, cbuddy);
1501 1546
1502 if (!quiet && new_arrivals) { 1547 if (!quiet && new_arrivals) {
1503 char *escaped = g_markup_escape_text(alias, -1); 1548 char *escaped = g_markup_escape_text(alias, -1);
1504 char *tmp; 1549 char *tmp;
1505 1550
1523 fl = fl->next; 1568 fl = fl->next;
1524 if (extra_msgs != NULL) 1569 if (extra_msgs != NULL)
1525 extra_msgs = extra_msgs->next; 1570 extra_msgs = extra_msgs->next;
1526 } 1571 }
1527 1572
1528 /* This needs to be in the same order as users, but it's faster 1573 cbuddies = g_list_sort(cbuddies, (GCompareFunc)gaim_conv_chat_cb_compare);
1529 * to prepend, so we do that above. */ 1574
1530 aliases = g_list_reverse(aliases);
1531
1532 if (ops != NULL && ops->chat_add_users != NULL) 1575 if (ops != NULL && ops->chat_add_users != NULL)
1533 ops->chat_add_users(conv, users, flags, aliases, new_arrivals); 1576 ops->chat_add_users(conv, cbuddies, new_arrivals);
1534 1577
1535 g_list_free(aliases);
1536 } 1578 }
1537 1579
1538 void 1580 void
1539 gaim_conv_chat_rename_user(GaimConvChat *chat, const char *old_user, 1581 gaim_conv_chat_rename_user(GaimConvChat *chat, const char *old_user,
1540 const char *new_user) 1582 const char *new_user)
1560 g_return_if_fail(gc != NULL); 1602 g_return_if_fail(gc != NULL);
1561 prpl_info = GAIM_PLUGIN_PROTOCOL_INFO(gc->prpl); 1603 prpl_info = GAIM_PLUGIN_PROTOCOL_INFO(gc->prpl);
1562 g_return_if_fail(prpl_info != NULL); 1604 g_return_if_fail(prpl_info != NULL);
1563 1605
1564 flags = gaim_conv_chat_user_get_flags(chat, old_user); 1606 flags = gaim_conv_chat_user_get_flags(chat, old_user);
1565 cb = gaim_conv_chat_cb_new(new_user, flags); 1607 cb = gaim_conv_chat_cb_new(new_user, NULL, flags);
1566 gaim_conv_chat_set_users(chat, 1608 gaim_conv_chat_set_users(chat,
1567 g_list_prepend(gaim_conv_chat_get_users(chat), cb)); 1609 g_list_prepend(gaim_conv_chat_get_users(chat), cb));
1568 1610
1569 if (!strcmp(chat->nick, gaim_normalize(conv->account, old_user))) { 1611 if (!strcmp(chat->nick, gaim_normalize(conv->account, old_user))) {
1570 const char *alias; 1612 const char *alias;
1871 { 1913 {
1872 g_return_val_if_fail(chat != NULL, TRUE); 1914 g_return_val_if_fail(chat != NULL, TRUE);
1873 1915
1874 return chat->left; 1916 return chat->left;
1875 } 1917 }
1876
1877 GaimConvChatBuddy * 1918 GaimConvChatBuddy *
1878 gaim_conv_chat_cb_new(const char *name, GaimConvChatBuddyFlags flags) 1919 gaim_conv_chat_cb_new(const char *name, const char *alias, GaimConvChatBuddyFlags flags)
1879 { 1920 {
1880 GaimConvChatBuddy *cb; 1921 GaimConvChatBuddy *cb;
1881 1922
1882 g_return_val_if_fail(name != NULL, NULL); 1923 g_return_val_if_fail(name != NULL, NULL);
1883 1924
1884 cb = g_new0(GaimConvChatBuddy, 1); 1925 cb = g_new0(GaimConvChatBuddy, 1);
1885 cb->name = g_strdup(name); 1926 cb->name = g_strdup(name);
1886 cb->flags = flags; 1927 cb->flags = flags;
1928 if (alias)
1929 cb->alias = g_strdup(alias);
1930 else
1931 cb->alias = NULL;
1887 1932
1888 GAIM_DBUS_REGISTER_POINTER(cb, GaimConvChatBuddy); 1933 GAIM_DBUS_REGISTER_POINTER(cb, GaimConvChatBuddy);
1889 return cb; 1934 return cb;
1890 } 1935 }
1891 1936