diff libpurple/protocols/myspace/myspace.c @ 22302:0e2207b46080

In msimprpl, if the user signs in without any username set (this will happen the first time they login to MySpaceIM if they haven't set a short URL), have them pick a username and use it. Patch from Jaywalker. Closes #2844.
author Jeffrey Connelly <jaconnel@calpoly.edu>
date Sat, 16 Feb 2008 20:20:12 +0000
parents 5aabf4e24188
children 1097406c8f6c
line wrap: on
line diff
--- a/libpurple/protocols/myspace/myspace.c	Sat Feb 16 20:02:36 2008 +0000
+++ b/libpurple/protocols/myspace/myspace.c	Sat Feb 16 20:20:12 2008 +0000
@@ -73,7 +73,7 @@
 static gboolean msim_check_alive(gpointer data);
 #endif
 
-static gboolean msim_we_are_logged_on(MsimSession *session, MsimMessage *msg);
+static gboolean msim_is_username_set(MsimSession *session, MsimMessage *msg);
 
 static gboolean msim_process(MsimSession *session, MsimMessage *msg);
 
@@ -1548,9 +1548,8 @@
 
 /** Called when the session key arrives. */
 static gboolean
-msim_we_are_logged_on(MsimSession *session, MsimMessage *msg)
-{
-	MsimMessage *body;
+msim_is_username_set(MsimSession *session, MsimMessage *msg) {
+	/*MsimMessage *body;*/
 
 	g_return_val_if_fail(MSIM_SESSION_VALID(session), FALSE);
 	g_return_val_if_fail(msg != NULL, FALSE);
@@ -1581,26 +1580,39 @@
 	/* Set display name to username (otherwise will show email address) */
 	purple_connection_set_display_name(session->gc, session->username);
 
-	/* The session is now set up, ready to be connected. This emits the
-	 * signedOn signal, so clients can now do anything with msimprpl, and
-	 * we're ready for it (session key, userid, username all setup). */
-	purple_connection_update_progress(session->gc, _("Connected"), 3, 4);
-	purple_connection_set_state(session->gc, PURPLE_CONNECTED);
-
 
 	/* Additional post-connect operations */
 
 
 	if (msim_msg_get_integer(msg, "uniquenick") == session->userid) {
 		purple_debug_info("msim_we_are_logged_on", "TODO: pick username\n");
-		/* No username is set. */
-		purple_notify_error(session->account, 
-				_("No username set"),
-				_("Please go to http://editprofile.myspace.com/index.cfm?fuseaction=profile.username and choose a username and try to login again."), NULL);
-		purple_connection_error_reason (session->gc,
-			PURPLE_CONNECTION_ERROR_AUTHENTICATION_FAILED, _("No username set"));
+		g_return_val_if_fail(session->gc != NULL, FALSE);
+		purple_request_yes_no(session->gc,
+			_("MySpaceIM - No Username Set"),
+			_("You appear to have no MySpace username."),
+			_("Would you like to set one now? (Note: THIS CANNOT BE CHANGED!)"),
+			0,
+			session->account,
+			NULL,
+			NULL,
+			session->gc, G_CALLBACK(msim_set_username_cb), G_CALLBACK(msim_do_not_set_username_cb));
+			purple_debug_info("msim","Username Not Set Alert Prompted\n");
 		return FALSE;
 	}
+	return TRUE;
+}
+
+/** Called after username is set. */
+gboolean msim_we_are_logged_on(MsimSession *session) {
+	MsimMessage *body;
+
+	g_return_val_if_fail(MSIM_SESSION_VALID(session), FALSE);
+
+	/* The session is now set up, ready to be connected. This emits the
+	 * signedOn signal, so clients can now do anything with msimprpl, and
+	 * we're ready for it (session key, userid, username all setup). */
+	purple_connection_update_progress(session->gc, _("Connected"), 3, 4);
+	purple_connection_set_state(session->gc, PURPLE_CONNECTED);
 
 	body = msim_msg_new(
 			"UserID", MSIM_TYPE_INTEGER, session->userid,
@@ -1687,7 +1699,14 @@
 	if (msim_msg_get_integer(msg, "lc") == 1) {
 		return msim_login_challenge(session, msg);
 	} else if (msim_msg_get_integer(msg, "lc") == 2) {
-		return msim_we_are_logged_on(session, msg);
+		/* return msim_we_are_logged_on(session, msg); */
+		if (msim_is_username_set(session, msg)) {
+			return msim_we_are_logged_on(session);
+		} else {
+			/* No username is set... We'll wait for the callbacks to do their work */
+			/* When they're all done, the last one will call msim_we_are_logged_on() and pick up where we left off */
+			return FALSE;
+		}
 	} else if (msim_msg_get(msg, "bm"))  {
 		return msim_incoming_bm(session, msg);
 	} else if (msim_msg_get(msg, "rid")) {