comparison libpurple/protocols/jabber/google.c @ 28742:63dc67b32577

jabber: Use the newly refactored code to simplify "Initiate Chat".
author Paul Aurich <paul@darkrain42.org>
date Mon, 12 Oct 2009 18:24:37 +0000
parents 51d507e6c8f3
children bd8a1dad7f1c 54755c2d6836 ecd2136ff818 093c79fa01c7
comparison
equal deleted inserted replaced
28741:724e77faee1a 28742:63dc67b32577
1430 void google_buddy_node_chat(PurpleBlistNode *node, gpointer data) 1430 void google_buddy_node_chat(PurpleBlistNode *node, gpointer data)
1431 { 1431 {
1432 PurpleBuddy *buddy; 1432 PurpleBuddy *buddy;
1433 PurpleConnection *gc; 1433 PurpleConnection *gc;
1434 JabberStream *js; 1434 JabberStream *js;
1435 JabberChat *jc; 1435 JabberChat *chat;
1436 GHashTable *chat_info;
1437 gchar *chat_name;
1438 gchar *uuid;
1439 gchar *room; 1436 gchar *room;
1440 guint32 tmp, a, b; 1437 guint32 tmp, a, b;
1441 1438
1442 g_return_if_fail(PURPLE_BLIST_NODE_IS_BUDDY(node)); 1439 g_return_if_fail(PURPLE_BLIST_NODE_IS_BUDDY(node));
1443 1440
1444 buddy = PURPLE_BUDDY(node); 1441 buddy = PURPLE_BUDDY(node);
1445 gc = purple_account_get_connection(purple_buddy_get_account(buddy)); 1442 gc = purple_account_get_connection(purple_buddy_get_account(buddy));
1443 g_return_if_fail(gc != NULL);
1446 js = purple_connection_get_protocol_data(gc); 1444 js = purple_connection_get_protocol_data(gc);
1447 1445
1446 /* Generate a version 4 UUID */
1448 tmp = g_random_int(); 1447 tmp = g_random_int();
1449 a = 0x4000 | (tmp & 0xFFF); /* 0x4000 to 0x4FFF */ 1448 a = 0x4000 | (tmp & 0xFFF); /* 0x4000 to 0x4FFF */
1450 tmp >>= 12; 1449 tmp >>= 12;
1451 b = ((1 << 3) << 12) | (tmp & 0x3FFF); /* 0x8000 to 0xBFFF */ 1450 b = ((1 << 3) << 12) | (tmp & 0x3FFF); /* 0x8000 to 0xBFFF */
1452 1451
1453 tmp = g_random_int(); 1452 tmp = g_random_int();
1454 uuid = g_strdup_printf("%08x-%04x-%04x-%04x-%04x%08x", 1453 room = g_strdup_printf("private-chat-%08x-%04x-%04x-%04x-%04x%08x",
1455 g_random_int(), 1454 g_random_int(),
1456 tmp & 0xFFFF, 1455 tmp & 0xFFFF,
1457 a, 1456 a,
1458 b, 1457 b,
1459 (tmp >> 16) & 0xFFFF, g_random_int()); 1458 (tmp >> 16) & 0xFFFF, g_random_int());
1460 1459
1461 room = g_strdup_printf("private-chat-%s", uuid); 1460 chat = jabber_join_chat(js, room, GOOGLE_GROUPCHAT_SERVER, js->user->node,
1462 chat_name = g_strdup_printf("%s@%s", room, GOOGLE_GROUPCHAT_SERVER); 1461 NULL, NULL);
1463 chat_info = jabber_chat_info_defaults(gc, chat_name); 1462 if (chat) {
1464 if (chat_info) { 1463 chat->muc = TRUE;
1465 jabber_chat_join(gc, chat_info); 1464 jabber_chat_invite(gc, chat->id, "", buddy->name);
1466 jc = jabber_chat_find(js, room, GOOGLE_GROUPCHAT_SERVER);
1467 if (jc)
1468 {
1469 jc->muc = TRUE;
1470 jabber_chat_invite(gc, jc->id, "", buddy->name);
1471 }
1472 g_hash_table_destroy(chat_info);
1473 } 1465 }
1474 1466
1475 g_free(room); 1467 g_free(room);
1476 g_free(uuid); 1468 }
1477 g_free(chat_name);
1478 }