changeset 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 7a2891487a00
children f85dc4ca31e2
files libpurple/protocols/msn/contact.c libpurple/protocols/msn/contact.h libpurple/protocols/msn/msn.c
diffstat 3 files changed, 97 insertions(+), 22 deletions(-) [+]
line wrap: on
line diff
--- a/libpurple/protocols/msn/contact.c	Sun Jul 12 22:40:54 2009 +0000
+++ b/libpurple/protocols/msn/contact.c	Mon Jul 13 05:01:42 2009 +0000
@@ -1159,7 +1159,7 @@
 {
 	MsnUserList *userlist;
 	MsnUser *user;
-	gchar *body = NULL, *contact_xml;
+	gchar *body = NULL, *contact_xml, *invite;
 
 	g_return_if_fail(passport != NULL);
 	g_return_if_fail(groupId != NULL);
@@ -1207,7 +1207,23 @@
 		contact_xml = g_strdup_printf(MSN_CONTACT_XML, passport);
 	}
 
-	body = g_strdup_printf(MSN_ADD_CONTACT_GROUP_TEMPLATE, groupId, contact_xml);
+	if (user->invite_message) {
+		char *tmp;
+		body = g_markup_escape_text(user->invite_message, -1);
+		tmp = g_markup_escape_text(purple_connection_get_display_name(session->account->gc), -1);
+		invite = g_strdup_printf(MSN_CONTACT_INVITE_MESSAGE_XML, body, tmp);
+		g_free(body);
+		g_free(tmp);
+
+		/* We can free this now */
+		g_free(user->invite_message);
+		user->invite_message = NULL;
+
+	} else {
+		invite = g_strdup("");
+	}
+
+	body = g_strdup_printf(MSN_ADD_CONTACT_GROUP_TEMPLATE, groupId, contact_xml, invite);
 
 	state->body = xmlnode_from_str(body, -1);
 	state->post_action = MSN_ADD_CONTACT_GROUP_SOAP_ACTION;
@@ -1215,6 +1231,7 @@
 	state->cb = msn_add_contact_to_group_read_cb;
 	msn_contact_request(state);
 
+	g_free(invite);
 	g_free(contact_xml);
 	g_free(body);
 }
--- a/libpurple/protocols/msn/contact.h	Sun Jul 12 22:40:54 2009 +0000
+++ b/libpurple/protocols/msn/contact.h	Mon Jul 13 05:01:42 2009 +0000
@@ -232,6 +232,17 @@
 		"</contactInfo>"\
 	"</Contact>"
 
+#define MSN_CONTACT_INVITE_MESSAGE_XML \
+	"<MessengerMemberInfo>"\
+		"<PendingAnnotations>"\
+			"<Annotation>"\
+				"<Name>MSN.IM.InviteMessage</Name>"\
+				"<Value>%s</Value>"\
+			"</Annotation>"\
+		"</PendingAnnotations>"\
+		"<DisplayName>%s</DisplayName>"\
+	"</MessengerMemberInfo>"
+
 #define MSN_ADD_CONTACT_TEMPLATE	"<?xml version=\"1.0\" encoding=\"utf-8\"?>"\
 "<soap:Envelope xmlns:soap=\"http://schemas.xmlsoap.org/soap/envelope/\""\
 	" xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\""\
@@ -290,6 +301,7 @@
 				"<fGenerateMissingQuickName>true</fGenerateMissingQuickName>"\
 				"<EnableAllowListManagement>true</EnableAllowListManagement>"\
 			"</groupContactAddOptions>"\
+			"%s"\
 		"</ABGroupContactAdd>"\
 	"</soap:Body>"\
 "</soap:Envelope>"
--- a/libpurple/protocols/msn/msn.c	Sun Jul 12 22:40:54 2009 +0000
+++ b/libpurple/protocols/msn/msn.c	Mon Jul 13 05:01:42 2009 +0000
@@ -92,6 +92,13 @@
 	MsnObject *obj;
 } MsnEmoticon;
 
+typedef struct
+{
+	PurpleConnection *pc;
+	PurpleBuddy *buddy;
+	PurpleGroup *group;
+} MsnAddReqData;
+
 static const char *
 msn_normalize(const PurpleAccount *account, const char *str)
 {
@@ -1429,33 +1436,27 @@
 }
 
 static void
-msn_add_buddy(PurpleConnection *gc, PurpleBuddy *buddy, PurpleGroup *group)
+finish_auth_request(MsnAddReqData *data, char *msg)
 {
+	PurpleConnection *pc;
+	PurpleBuddy *buddy;
+	PurpleGroup *group;
 	PurpleAccount *account;
 	MsnSession *session;
 	MsnUserList *userlist;
-	const char *bname, *who, *gname;
+	const char *who, *gname;
 	MsnUser *user;
 
-	account = purple_connection_get_account(gc);
-	session = gc->proto_data;
+	pc = data->pc;
+	buddy = data->buddy;
+	group = data->group;
+	g_free(data);
+
+	account = purple_connection_get_account(pc);
+	session = pc->proto_data;
 	userlist = session->userlist;
-	bname = purple_buddy_get_name(buddy);
-
-	if (!purple_email_is_valid(bname)) {
-		gchar *buf;
-		buf = g_strdup_printf(_("Unable to add the buddy %s because the username is invalid.  Usernames must be a valid email address."), bname);
-		if (!purple_conv_present_error(bname, account, buf))
-			purple_notify_error(gc, NULL, _("Unable to Add"), buf);
-		g_free(buf);
-
-		/* Remove from local list */
-		purple_blist_remove_buddy(buddy);
-
-		return;
-	}
-
-	who = msn_normalize(account, bname);
+
+	who = msn_normalize(account, purple_buddy_get_name(buddy));
 	gname = group ? purple_group_get_name(group) : NULL;
 	purple_debug_info("msn", "Add user:%s to group:%s\n", who, gname ? gname : "(null)");
 	if (!session->logged_in)
@@ -1472,12 +1473,14 @@
 	if ((user != NULL) && (user->networkid != MSN_NETWORK_UNKNOWN)) {
 		/* We already know this buddy and their network. This function knows
 		   what to do with users already in the list and stuff... */
+		msn_user_set_invite_message(user, msg);
 		msn_userlist_add_buddy(userlist, who, gname);
 	} else {
 		char **tokens;
 		char *fqy;
 		/* We need to check the network for this buddy first */
 		user = msn_user_new(userlist, who, NULL);
+		msn_user_set_invite_message(user, msg);
 		msn_user_set_pending_group(user, gname);
 		msn_user_set_network(user, MSN_NETWORK_UNKNOWN);
 		tokens = g_strsplit(who, "@", 2);
@@ -1492,6 +1495,49 @@
 }
 
 static void
+cancel_auth_request(MsnAddReqData *data, char *msg)
+{
+	/* Remove from local list */
+	purple_blist_remove_buddy(data->buddy);
+	
+	g_free(data);
+}
+
+static void
+msn_add_buddy(PurpleConnection *gc, PurpleBuddy *buddy, PurpleGroup *group)
+{
+	const char *bname;
+	MsnAddReqData *data;
+
+	bname = purple_buddy_get_name(buddy);
+
+	if (!purple_email_is_valid(bname)) {
+		gchar *buf;
+		buf = g_strdup_printf(_("Unable to add the buddy %s because the username is invalid.  Usernames must be a valid email address."), bname);
+		if (!purple_conv_present_error(bname, purple_connection_get_account(gc), buf))
+			purple_notify_error(gc, NULL, _("Unable to Add"), buf);
+		g_free(buf);
+
+		/* Remove from local list */
+		purple_blist_remove_buddy(buddy);
+
+		return;
+	}
+
+	data = g_new0(MsnAddReqData, 1);
+	data->pc = gc;
+	data->buddy = buddy;
+	data->group = group;
+
+	purple_request_input(gc, NULL, _("Authorization Request Message:"),
+	                     NULL, _("Please authorize me!"), TRUE, FALSE, NULL,
+	                     _("_OK"), G_CALLBACK(finish_auth_request),
+	                     _("_Cancel"), G_CALLBACK(cancel_auth_request),
+	                     purple_connection_get_account(gc), bname, NULL,
+	                     data);
+}
+
+static void
 msn_rem_buddy(PurpleConnection *gc, PurpleBuddy *buddy, PurpleGroup *group)
 {
 	MsnSession *session;