comparison libpurple/protocols/msn/msn.c @ 27488:3698c7f4d803

On MSN, pop up an "invite message" request similar to oscar, and send that in the add request. We really should try and move this into the add buddy dialog instead of an extra prompt. Fixes #8503.
author Elliott Sales de Andrade <qulogic@pidgin.im>
date Mon, 13 Jul 2009 05:01:42 +0000
parents 8accf7a2264c
children a12574d982a1
comparison
equal deleted inserted replaced
27487:7a2891487a00 27488:3698c7f4d803
89 typedef struct 89 typedef struct
90 { 90 {
91 char *smile; 91 char *smile;
92 MsnObject *obj; 92 MsnObject *obj;
93 } MsnEmoticon; 93 } MsnEmoticon;
94
95 typedef struct
96 {
97 PurpleConnection *pc;
98 PurpleBuddy *buddy;
99 PurpleGroup *group;
100 } MsnAddReqData;
94 101
95 static const char * 102 static const char *
96 msn_normalize(const PurpleAccount *account, const char *str) 103 msn_normalize(const PurpleAccount *account, const char *str)
97 { 104 {
98 static char buf[BUF_LEN]; 105 static char buf[BUF_LEN];
1427 } 1434 }
1428 g_free(group); 1435 g_free(group);
1429 } 1436 }
1430 1437
1431 static void 1438 static void
1432 msn_add_buddy(PurpleConnection *gc, PurpleBuddy *buddy, PurpleGroup *group) 1439 finish_auth_request(MsnAddReqData *data, char *msg)
1433 { 1440 {
1441 PurpleConnection *pc;
1442 PurpleBuddy *buddy;
1443 PurpleGroup *group;
1434 PurpleAccount *account; 1444 PurpleAccount *account;
1435 MsnSession *session; 1445 MsnSession *session;
1436 MsnUserList *userlist; 1446 MsnUserList *userlist;
1437 const char *bname, *who, *gname; 1447 const char *who, *gname;
1438 MsnUser *user; 1448 MsnUser *user;
1439 1449
1440 account = purple_connection_get_account(gc); 1450 pc = data->pc;
1441 session = gc->proto_data; 1451 buddy = data->buddy;
1452 group = data->group;
1453 g_free(data);
1454
1455 account = purple_connection_get_account(pc);
1456 session = pc->proto_data;
1442 userlist = session->userlist; 1457 userlist = session->userlist;
1443 bname = purple_buddy_get_name(buddy); 1458
1444 1459 who = msn_normalize(account, purple_buddy_get_name(buddy));
1445 if (!purple_email_is_valid(bname)) {
1446 gchar *buf;
1447 buf = g_strdup_printf(_("Unable to add the buddy %s because the username is invalid. Usernames must be a valid email address."), bname);
1448 if (!purple_conv_present_error(bname, account, buf))
1449 purple_notify_error(gc, NULL, _("Unable to Add"), buf);
1450 g_free(buf);
1451
1452 /* Remove from local list */
1453 purple_blist_remove_buddy(buddy);
1454
1455 return;
1456 }
1457
1458 who = msn_normalize(account, bname);
1459 gname = group ? purple_group_get_name(group) : NULL; 1460 gname = group ? purple_group_get_name(group) : NULL;
1460 purple_debug_info("msn", "Add user:%s to group:%s\n", who, gname ? gname : "(null)"); 1461 purple_debug_info("msn", "Add user:%s to group:%s\n", who, gname ? gname : "(null)");
1461 if (!session->logged_in) 1462 if (!session->logged_in)
1462 { 1463 {
1463 purple_debug_error("msn", "msn_add_buddy called before connected\n"); 1464 purple_debug_error("msn", "msn_add_buddy called before connected\n");
1470 * internal. */ 1471 * internal. */
1471 user = msn_userlist_find_user(userlist, who); 1472 user = msn_userlist_find_user(userlist, who);
1472 if ((user != NULL) && (user->networkid != MSN_NETWORK_UNKNOWN)) { 1473 if ((user != NULL) && (user->networkid != MSN_NETWORK_UNKNOWN)) {
1473 /* We already know this buddy and their network. This function knows 1474 /* We already know this buddy and their network. This function knows
1474 what to do with users already in the list and stuff... */ 1475 what to do with users already in the list and stuff... */
1476 msn_user_set_invite_message(user, msg);
1475 msn_userlist_add_buddy(userlist, who, gname); 1477 msn_userlist_add_buddy(userlist, who, gname);
1476 } else { 1478 } else {
1477 char **tokens; 1479 char **tokens;
1478 char *fqy; 1480 char *fqy;
1479 /* We need to check the network for this buddy first */ 1481 /* We need to check the network for this buddy first */
1480 user = msn_user_new(userlist, who, NULL); 1482 user = msn_user_new(userlist, who, NULL);
1483 msn_user_set_invite_message(user, msg);
1481 msn_user_set_pending_group(user, gname); 1484 msn_user_set_pending_group(user, gname);
1482 msn_user_set_network(user, MSN_NETWORK_UNKNOWN); 1485 msn_user_set_network(user, MSN_NETWORK_UNKNOWN);
1483 tokens = g_strsplit(who, "@", 2); 1486 tokens = g_strsplit(who, "@", 2);
1484 fqy = g_strdup_printf("<ml><d n=\"%s\"><c n=\"%s\"/></d></ml>", 1487 fqy = g_strdup_printf("<ml><d n=\"%s\"><c n=\"%s\"/></d></ml>",
1485 tokens[1], 1488 tokens[1],
1487 msn_notification_send_fqy(session, fqy, strlen(fqy), 1490 msn_notification_send_fqy(session, fqy, strlen(fqy),
1488 (MsnFqyCb)add_pending_buddy, user); 1491 (MsnFqyCb)add_pending_buddy, user);
1489 g_free(fqy); 1492 g_free(fqy);
1490 g_strfreev(tokens); 1493 g_strfreev(tokens);
1491 } 1494 }
1495 }
1496
1497 static void
1498 cancel_auth_request(MsnAddReqData *data, char *msg)
1499 {
1500 /* Remove from local list */
1501 purple_blist_remove_buddy(data->buddy);
1502
1503 g_free(data);
1504 }
1505
1506 static void
1507 msn_add_buddy(PurpleConnection *gc, PurpleBuddy *buddy, PurpleGroup *group)
1508 {
1509 const char *bname;
1510 MsnAddReqData *data;
1511
1512 bname = purple_buddy_get_name(buddy);
1513
1514 if (!purple_email_is_valid(bname)) {
1515 gchar *buf;
1516 buf = g_strdup_printf(_("Unable to add the buddy %s because the username is invalid. Usernames must be a valid email address."), bname);
1517 if (!purple_conv_present_error(bname, purple_connection_get_account(gc), buf))
1518 purple_notify_error(gc, NULL, _("Unable to Add"), buf);
1519 g_free(buf);
1520
1521 /* Remove from local list */
1522 purple_blist_remove_buddy(buddy);
1523
1524 return;
1525 }
1526
1527 data = g_new0(MsnAddReqData, 1);
1528 data->pc = gc;
1529 data->buddy = buddy;
1530 data->group = group;
1531
1532 purple_request_input(gc, NULL, _("Authorization Request Message:"),
1533 NULL, _("Please authorize me!"), TRUE, FALSE, NULL,
1534 _("_OK"), G_CALLBACK(finish_auth_request),
1535 _("_Cancel"), G_CALLBACK(cancel_auth_request),
1536 purple_connection_get_account(gc), bname, NULL,
1537 data);
1492 } 1538 }
1493 1539
1494 static void 1540 static void
1495 msn_rem_buddy(PurpleConnection *gc, PurpleBuddy *buddy, PurpleGroup *group) 1541 msn_rem_buddy(PurpleConnection *gc, PurpleBuddy *buddy, PurpleGroup *group)
1496 { 1542 {