pidgin: b6ffa17b: On MSN, pop up an "invite message" reque...

qulogic at pidgin.im qulogic at pidgin.im
Mon Jul 13 02:01:21 EDT 2009


-----------------------------------------------------------------
Revision: b6ffa17b3b16e6e75766fce685e06baf366878d6
Ancestor: b4ae5998272a5b0f78bfd9f44b00db06b936f4d1
Author: qulogic at pidgin.im
Date: 2009-07-13T05:01:42
Branch: im.pidgin.pidgin
URL: http://d.pidgin.im/viewmtn/revision/info/b6ffa17b3b16e6e75766fce685e06baf366878d6

Modified files:
        libpurple/protocols/msn/contact.c
        libpurple/protocols/msn/contact.h
        libpurple/protocols/msn/msn.c

ChangeLog: 

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.

-------------- next part --------------
============================================================
--- libpurple/protocols/msn/contact.c	54e6b6b3ca50b0144b741d3a98bc238e88860071
+++ libpurple/protocols/msn/contact.c	2415c3c78be3fa2d14ed69e0a523082510217e39
@@ -1159,7 +1159,7 @@ msn_add_contact_to_group(MsnSession *ses
 {
 	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,14 +1207,31 @@ msn_add_contact_to_group(MsnSession *ses
 		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;
 	state->post_url = MSN_ADDRESS_BOOK_POST_URL;
 	state->cb = msn_add_contact_to_group_read_cb;
 	msn_contact_request(state);
 
+	g_free(invite);
 	g_free(contact_xml);
 	g_free(body);
 }
============================================================
--- libpurple/protocols/msn/contact.h	7ca6d016c5474b5285f0e09719cd19665bee9bc7
+++ libpurple/protocols/msn/contact.h	6a4460b5b9f3c0bc989799a2e6334b9686e14ca4
@@ -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>"
============================================================
--- libpurple/protocols/msn/msn.c	141cb6b20bfce197acf36b433fe9068fe2140217
+++ libpurple/protocols/msn/msn.c	559ca6cd34abb0174b65e5a986c2fe2173effa6e
@@ -92,6 +92,13 @@ typedef struct
 	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
 }
 
 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;
-	userlist = session->userlist;
-	bname = purple_buddy_get_name(buddy);
+	pc = data->pc;
+	buddy = data->buddy;
+	group = data->group;
+	g_free(data);
 
-	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);
+	account = purple_connection_get_account(pc);
+	session = pc->proto_data;
+	userlist = session->userlist;
 
-		/* 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 @@ msn_add_buddy(PurpleConnection *gc, Purp
 	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
 }
 
 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;


More information about the Commits mailing list