# HG changeset patch
# Node ID c2b59adc4c1b
# Parent  99d6a7231f6d
diff --git a/libpurple/account.c b/libpurple/account.c
--- a/libpurple/account.c
+++ b/libpurple/account.c
@@ -164,8 +164,10 @@
 	connection = purple_protocol_create_connection(protocol, account, password,
 	                                               &error);
 	if(error != NULL) {
+		PurpleContactInfo *info = PURPLE_CONTACT_INFO(account);
+
 		purple_debug_warning("failed to create connection for %s: %s",
-		                     purple_account_get_username(account),
+		                     purple_contact_info_get_username(info),
 		                     error->message);
 		g_clear_error(&error);
 
@@ -208,7 +210,8 @@
 	g_object_set_data(G_OBJECT(account), "_tmp_password", NULL);
 
 	if(!purple_credential_manager_write_password_finish(manager, res, &error)) {
-		const gchar *name = purple_account_get_name_for_display(account);
+		PurpleContactInfo *info = PURPLE_CONTACT_INFO(account);
+		const gchar *name = purple_contact_info_get_name_for_display(info);
 
 		/* we can't error an account without a connection, so we just drop a
 		 * debug message for now and continue to connect the account.
@@ -555,6 +558,7 @@
 PurpleXmlNode *
 _purple_account_to_xmlnode(PurpleAccount *account)
 {
+	PurpleContactInfo *info = PURPLE_CONTACT_INFO(account);
 	PurpleXmlNode *node, *child;
 	gchar *data = NULL;
 	const char *tmp;
@@ -562,17 +566,19 @@
 
 	node = purple_xmlnode_new("account");
 
-	tmp = purple_contact_info_get_id(PURPLE_CONTACT_INFO(account));
+	tmp = purple_contact_info_get_id(info);
 	if(tmp != NULL) {
 		child = purple_xmlnode_new_child(node, "id");
 		purple_xmlnode_insert_data(child, tmp, -1);
 	}
 
 	child = purple_xmlnode_new_child(node, "protocol");
-	purple_xmlnode_insert_data(child, purple_account_get_protocol_id(account), -1);
+	purple_xmlnode_insert_data(child, purple_account_get_protocol_id(account),
+	                           -1);
 
 	child = purple_xmlnode_new_child(node, "name");
-	purple_xmlnode_insert_data(child, purple_account_get_username(account), -1);
+	purple_xmlnode_insert_data(child, purple_contact_info_get_username(info),
+	                           -1);
 
 	child = purple_xmlnode_new_child(node, "require_password");
 	data = g_strdup_printf("%d", account->require_password);
@@ -584,7 +590,7 @@
 	purple_xmlnode_insert_data(child, data, -1);
 	g_clear_pointer(&data, g_free);
 
-	tmp = purple_contact_info_get_alias(PURPLE_CONTACT_INFO(account));
+	tmp = purple_contact_info_get_alias(info);
 	if(tmp != NULL) {
 		child = purple_xmlnode_new_child(node, "alias");
 		purple_xmlnode_insert_data(child, tmp, -1);
@@ -988,7 +994,7 @@
 
 	purple_account_clear_current_error(account);
 
-	username = purple_account_get_username(account);
+	username = purple_contact_info_get_username(PURPLE_CONTACT_INFO(account));
 
 	if (!purple_account_get_enabled(account)) {
 		purple_debug_info("account",
@@ -1037,7 +1043,7 @@
 	g_return_if_fail(!purple_account_is_disconnecting(account));
 	g_return_if_fail(!purple_account_is_disconnected(account));
 
-	username = purple_account_get_username(account);
+	username = purple_contact_info_get_username(PURPLE_CONTACT_INFO(account));
 	purple_debug_info("account", "Disconnecting account %s (%p)\n",
 	                  username ? username : "(null)", account);
 
@@ -1045,7 +1051,7 @@
 
 	if(!purple_connection_disconnect(account->gc, &error)) {
 		g_warning("error while disconnecting account %s (%s): %s",
-		          purple_account_get_username(account),
+		          username,
 		          purple_account_get_protocol_id(account),
 		          (error != NULL) ? error->message : "unknown error");
 		g_clear_error(&error);
@@ -1087,7 +1093,7 @@
 	/* Close any previous password request windows */
 	purple_request_close_with_handle(account);
 
-	username = purple_account_get_username(account);
+	username = purple_contact_info_get_username(PURPLE_CONTACT_INFO(account));
 	primary = g_strdup_printf(_("Enter password for %s (%s)"), username,
 								  purple_account_get_protocol_name(account));
 
@@ -1155,7 +1161,7 @@
 	purple_request_field_group_add_field(group, field);
 
 	g_snprintf(primary, sizeof(primary), _("Change password for %s"),
-			   purple_account_get_username(account));
+			   purple_contact_info_get_username(PURPLE_CONTACT_INFO(account)));
 
 	/* I'm sticking this somewhere in the code: bologna */
 
@@ -1179,7 +1185,7 @@
 
 	g_snprintf(primary, sizeof(primary),
 			   _("Change user information for %s"),
-			   purple_account_get_username(account));
+			   purple_contact_info_get_username(PURPLE_CONTACT_INFO(account)));
 
 	purple_request_input(gc, _("Set User Info"), primary, NULL,
 					   purple_account_get_user_info(account),
@@ -1359,12 +1365,15 @@
 	g_return_if_fail(status_id != NULL);
 
 	status = purple_account_get_status(account, status_id);
-	if (status == NULL)
-	{
+	if(status == NULL) {
+		PurpleContactInfo *info = PURPLE_CONTACT_INFO(account);
+
 		purple_debug_error("account",
-				   "Invalid status ID '%s' for account %s (%s)\n",
-				   status_id, purple_account_get_username(account),
-				   purple_account_get_protocol_id(account));
+		                   "Invalid status ID '%s' for account %s (%s)\n",
+		                   status_id,
+		                   purple_contact_info_get_username(info),
+		                   purple_account_get_protocol_id(account));
+
 		return;
 	}
 
@@ -1910,7 +1919,7 @@
 
 		g_critical("purple_account_settings_thaw_notify called for account %s "
 		           "(%s) when not frozen",
-		           purple_account_get_username(account),
+		           purple_contact_info_get_username(PURPLE_CONTACT_INFO(account)),
 		           purple_account_get_protocol_id(account));
 
 		return;
diff --git a/libpurple/accounts.c b/libpurple/accounts.c
--- a/libpurple/accounts.c
+++ b/libpurple/accounts.c
@@ -209,9 +209,10 @@
 			purple_proxy_info_set_proxy_type(proxy_info, PURPLE_PROXY_TYPE_USE_ENVVAR);
 		else
 		{
+			PurpleContactInfo *info = PURPLE_CONTACT_INFO(account);
 			purple_debug_error("accounts", "Invalid proxy type found when "
-							 "loading account information for %s\n",
-							 purple_account_get_username(account));
+			                   "loading account information for %s\n",
+			                   purple_contact_info_get_username(info));
 		}
 		g_free(data);
 	}
@@ -278,12 +279,14 @@
 	type = atoi(type_str);
 	g_free(type_str);
 
-	if (type > PURPLE_CONNECTION_ERROR_OTHER_ERROR)
-	{
+	if(type > PURPLE_CONNECTION_ERROR_OTHER_ERROR) {
+		PurpleContactInfo *info = PURPLE_CONTACT_INFO(account);
+
 		purple_debug_error("accounts",
-			"Invalid PurpleConnectionError value %d found when "
-			"loading account information for %s\n",
-			type, purple_account_get_username(account));
+		                   "Invalid PurpleConnectionError value %d found when "
+		                   "loading account information for %s\n",
+		                   type,
+		                   purple_contact_info_get_username(info));
 		type = PURPLE_CONNECTION_ERROR_OTHER_ERROR;
 	}
 
@@ -368,8 +371,9 @@
 	child = purple_xmlnode_get_child(node, "alias");
 	if ((child != NULL) && ((data = purple_xmlnode_get_data(child)) != NULL))
 	{
-		if (*data != '\0')
-			purple_account_set_private_alias(ret, data);
+		if (*data != '\0') {
+			purple_contact_info_set_alias(PURPLE_CONTACT_INFO(ret), data);
+		}
 		g_free(data);
 	}
 
@@ -461,9 +465,11 @@
 
 	r = purple_credential_manager_clear_password_finish(manager, res, &error);
 	if(r != TRUE) {
+		PurpleContactInfo *info = PURPLE_CONTACT_INFO(account);
+
 		purple_debug_warning("accounts",
 		                     "Failed to remove password for account %s: %s",
-		                     purple_account_get_name_for_display(account),
+		                     purple_contact_info_get_name_for_display(info),
 		                     (error != NULL) ? error->message : "Unknown error");
 
 		g_clear_error(&error);
diff --git a/libpurple/buddy.c b/libpurple/buddy.c
--- a/libpurple/buddy.c
+++ b/libpurple/buddy.c
@@ -173,13 +173,14 @@
 		/* If there is no id for the user, generate a SHA256 based on the
 		 * account_id and the username.
 		 */
+		PurpleContactInfo *info = PURPLE_CONTACT_INFO(priv->account);
 		GChecksum *sum = g_checksum_new(G_CHECKSUM_SHA256);
 		const guchar *data = NULL;
 
 		data = (const guchar *)purple_account_get_protocol_id(priv->account);
 		g_checksum_update(sum, data, -1);
 
-		data = (const guchar *)purple_account_get_username(priv->account);
+		data = (const guchar *)purple_contact_info_get_username(info);
 		g_checksum_update(sum, data, -1);
 
 		data = (const guchar *)priv->name;
diff --git a/libpurple/buddylist.c b/libpurple/buddylist.c
--- a/libpurple/buddylist.c
+++ b/libpurple/buddylist.c
@@ -225,10 +225,12 @@
 {
 	PurpleXmlNode *node, *child;
 	PurpleAccount *account = purple_buddy_get_account(buddy);
+	PurpleContactInfo *info = PURPLE_CONTACT_INFO(account);
 	const char *alias = purple_buddy_get_local_alias(buddy);
 
 	node = purple_xmlnode_new("buddy");
-	purple_xmlnode_set_attrib(node, "account", purple_account_get_username(account));
+	purple_xmlnode_set_attrib(node, "account",
+	                          purple_contact_info_get_username(info));
 	purple_xmlnode_set_attrib(node, "proto", purple_account_get_protocol_id(account));
 
 	child = purple_xmlnode_new_child(node, "name");
@@ -287,13 +289,16 @@
 {
 	PurpleXmlNode *node, *child;
 	PurpleAccount *account = purple_chat_get_account(chat);
+	PurpleContactInfo *info = PURPLE_CONTACT_INFO(account);
 	gchar *alias;
 
 	g_object_get(chat, "alias", &alias, NULL);
 
 	node = purple_xmlnode_new("chat");
-	purple_xmlnode_set_attrib(node, "proto", purple_account_get_protocol_id(account));
-	purple_xmlnode_set_attrib(node, "account", purple_account_get_username(account));
+	purple_xmlnode_set_attrib(node, "proto",
+	                          purple_account_get_protocol_id(account));
+	purple_xmlnode_set_attrib(node, "account",
+	                          purple_contact_info_get_username(info));
 
 	if (alias != NULL)
 	{
diff --git a/libpurple/connection.c b/libpurple/connection.c
--- a/libpurple/connection.c
+++ b/libpurple/connection.c
@@ -920,15 +920,18 @@
 purple_connection_connect(PurpleConnection *connection, GError **error) {
 	PurpleConnectionClass *klass = NULL;
 	PurpleConnectionPrivate *priv = NULL;
+	PurpleContactInfo *info = NULL;
 
 	g_return_val_if_fail(PURPLE_IS_CONNECTION(connection), FALSE);
 
 	priv = purple_connection_get_instance_private(connection);
 
+	info = PURPLE_CONTACT_INFO(priv->account);
+
 	if(!purple_account_is_disconnected(priv->account)) {
 		g_set_error(error, PURPLE_CONNECTION_ERROR, 0,
 		            "account %s is not disconnected",
-		            purple_account_get_username(priv->account));
+		            purple_contact_info_get_username(info));
 
 		return TRUE;
 	}
@@ -939,7 +942,7 @@
 	{
 		g_set_error(error, PURPLE_CONNECTION_ERROR, 0,
 		            "Cannot connect to account %s without a password.",
-		            purple_account_get_username(priv->account));
+		            purple_contact_info_get_username(info));
 
 		return FALSE;
 	}
@@ -954,7 +957,7 @@
 
 	g_set_error(error, PURPLE_CONNECTION_ERROR, 0,
 	            "The connection for %s did not implement the connect method",
-	            purple_account_get_username(priv->account));
+	            purple_contact_info_get_username(info));
 
 	return FALSE;
 }
diff --git a/libpurple/idle.c b/libpurple/idle.c
--- a/libpurple/idle.c
+++ b/libpurple/idle.c
@@ -59,16 +59,19 @@
 static void
 set_account_idle(PurpleAccount *account, int time_idle)
 {
+	PurpleContactInfo *info = PURPLE_CONTACT_INFO(account);
 	PurplePresence *presence;
 
 	presence = purple_account_get_presence(account);
 
-	if (purple_presence_is_idle(presence))
+	if(purple_presence_is_idle(presence)) {
 		/* This account is already idle! */
 		return;
+	}
 
 	purple_debug_info("idle", "Setting %s idle %d seconds\n",
-			   purple_account_get_username(account), time_idle);
+	                  purple_contact_info_get_username(info),
+	                  time_idle);
 	purple_presence_set_idle(presence, TRUE, time(NULL) - time_idle);
 	idled_accts = g_list_prepend(idled_accts, account);
 }
@@ -76,18 +79,20 @@
 static void
 set_account_unidle(PurpleAccount *account)
 {
+	PurpleContactInfo *info = PURPLE_CONTACT_INFO(account);
 	PurplePresence *presence;
 
 	presence = purple_account_get_presence(account);
 
 	idled_accts = g_list_remove(idled_accts, account);
 
-	if (!purple_presence_is_idle(presence))
+	if(!purple_presence_is_idle(presence)) {
 		/* This account is already unidle! */
 		return;
+	}
 
 	purple_debug_info("idle", "Setting %s unidle\n",
-			   purple_account_get_username(account));
+	                  purple_contact_info_get_username(info));
 	purple_presence_set_idle(presence, FALSE, 0);
 }
 
diff --git a/libpurple/purpleaccountmanager.c b/libpurple/purpleaccountmanager.c
--- a/libpurple/purpleaccountmanager.c
+++ b/libpurple/purpleaccountmanager.c
@@ -401,8 +401,11 @@
 			new_index--;
 		}
 	} else {
+		PurpleContactInfo *info = PURPLE_CONTACT_INFO(account);
+
 		g_critical("Unregistered account (%s) found during reorder!",
-		           purple_account_get_username(account));
+		           purple_contact_info_get_username(info));
+
 		return;
 	}
 
@@ -422,8 +425,9 @@
 
 	for(guint index = 0; index < manager->accounts->len; index++) {
 		PurpleAccount *account = g_ptr_array_index(manager->accounts, index);
+		PurpleContactInfo *info = PURPLE_CONTACT_INFO(account);
 
-		if(purple_strequal(purple_account_get_id(account), id)) {
+		if(purple_strequal(purple_contact_info_get_id(info), id)) {
 			return account;
 		}
 	}
@@ -441,6 +445,7 @@
 
 	for(guint index = 0; index < manager->accounts->len; index++) {
 		PurpleAccount *account = g_ptr_array_index(manager->accounts, index);
+		PurpleContactInfo *info = PURPLE_CONTACT_INFO(account);
 		gchar *normalized = NULL;
 		const gchar *existing_protocol_id = NULL;
 		const gchar *existing_username = NULL;
@@ -453,7 +458,7 @@
 		}
 
 		/* Finally verify the username. */
-		existing_username = purple_account_get_username(account);
+		existing_username = purple_contact_info_get_username(info);
 		normalized = g_strdup(purple_normalize(account, username));
 		existing_normalized = purple_normalize(account, existing_username);
 
diff --git a/libpurple/purplechatconversation.c b/libpurple/purplechatconversation.c
--- a/libpurple/purplechatconversation.c
+++ b/libpurple/purplechatconversation.c
@@ -206,7 +206,8 @@
 	if(display_name != NULL) {
 		purple_chat_conversation_set_nick(chat, display_name);
 	} else {
-		const gchar *username = purple_account_get_username(account);
+		PurpleContactInfo *info = PURPLE_CONTACT_INFO(account);
+		const gchar *username = purple_contact_info_get_username(info);
 
 		purple_chat_conversation_set_nick(chat, username);
 	}
@@ -415,18 +416,19 @@
 
 	connection = purple_account_get_connection(account);
 	if(!PURPLE_IS_CONNECTION(connection)) {
+		PurpleContactInfo *info = PURPLE_CONTACT_INFO(account);
 		purple_debug_warning("chat-conversation", "Refusing to create chat "
 		                     "for disconnected account %s",
-		                     purple_account_get_username(account));
+		                     purple_contact_info_get_username(info));
 		return NULL;
 	}
 
-	return PURPLE_CONVERSATION(g_object_new(
+	return g_object_new(
 		PURPLE_TYPE_CHAT_CONVERSATION,
 		"account", account,
 		"name", name,
 		"title", name,
-		NULL));
+		NULL);
 }
 
 GList *
diff --git a/libpurple/purpleconversation.c b/libpurple/purpleconversation.c
--- a/libpurple/purpleconversation.c
+++ b/libpurple/purpleconversation.c
@@ -92,7 +92,7 @@
 	gc = purple_account_get_connection(account);
 	g_return_if_fail(PURPLE_IS_CONNECTION(gc));
 
-	me = purple_account_get_name_for_display(account);
+	me = purple_contact_info_get_name_for_display(PURPLE_CONTACT_INFO(account));
 
 	/* Always linkify the text for display, unless we're explicitly asked to do
 	 * otherwise. */
@@ -644,22 +644,10 @@
 		   !(purple_protocol_get_options(protocol) & OPT_PROTO_UNIQUE_CHATNAME))
 		{
 			if(purple_message_get_flags(pmsg) & PURPLE_MESSAGE_SEND) {
+				PurpleContactInfo *info = PURPLE_CONTACT_INFO(account);
 				const gchar *alias;
 
-				b = purple_blist_find_buddy(account,
-				                            purple_account_get_username(account));
-
-				if(purple_account_get_private_alias(account) != NULL) {
-					alias = purple_account_get_private_alias(account);
-				} else if (b != NULL && !purple_strequal(purple_buddy_get_name(b),
-					purple_buddy_get_contact_alias(b)))
-				{
-					alias = purple_buddy_get_contact_alias(b);
-				} else if (purple_connection_get_display_name(gc) != NULL) {
-					alias = purple_connection_get_display_name(gc);
-				} else {
-					alias = purple_account_get_username(account);
-				}
+				alias = purple_contact_info_get_name_for_display(info);
 
 				purple_message_set_author_alias(pmsg, alias);
 			} else if (purple_message_get_flags(pmsg) & PURPLE_MESSAGE_RECV) {
diff --git a/libpurple/purplecredentialmanager.c b/libpurple/purplecredentialmanager.c
--- a/libpurple/purplecredentialmanager.c
+++ b/libpurple/purplecredentialmanager.c
@@ -522,7 +522,9 @@
 	task = g_task_new(manager, cancellable, callback, data);
 
 	if(!purple_account_get_remember_password(account)) {
-		const gchar *name = purple_account_get_username(account);
+		const gchar *name = NULL;
+
+		name = purple_contact_info_get_username(PURPLE_CONTACT_INFO(account));
 
 		g_task_return_new_error(task, PURPLE_CREDENTIAL_MANAGER_DOMAIN, 0,
 		                        _("account \"%s\" is not marked to be stored"),
diff --git a/libpurple/purplenotification.c b/libpurple/purplenotification.c
--- a/libpurple/purplenotification.c
+++ b/libpurple/purplenotification.c
@@ -444,6 +444,7 @@
 purple_notification_new_from_add_contact_request(PurpleAddContactRequest *request)
 {
 	PurpleAccount *account = NULL;
+	PurpleContactInfo *info = NULL;
 	PurpleNotification *notification = NULL;
 	gchar *title = NULL;
 	const gchar *alias = NULL, *username = NULL;
@@ -451,6 +452,7 @@
 	g_return_val_if_fail(PURPLE_IS_ADD_CONTACT_REQUEST(request), NULL);
 
 	account = purple_add_contact_request_get_account(request);
+	info = PURPLE_CONTACT_INFO(account);
 	notification = purple_notification_new(PURPLE_NOTIFICATION_TYPE_ADD_CONTACT,
 	                                       account, request, g_object_unref);
 
@@ -460,10 +462,11 @@
 	if(alias != NULL && *alias != '\0') {
 		title = g_strdup_printf(_("%s (%s) added %s to their contact list"),
 		                        alias, username,
-		                        purple_account_get_username(account));
+		                        purple_contact_info_get_username(info));
 	} else {
 		title = g_strdup_printf(_("%s added %s to their contact list"),
-		                        username, purple_account_get_username(account));
+		                        username,
+		                        purple_contact_info_get_username(info));
 	}
 
 	purple_notification_set_title(notification, title);
@@ -476,6 +479,7 @@
 purple_notification_new_from_authorization_request(PurpleAuthorizationRequest *authorization_request)
 {
 	PurpleAccount *account = NULL;
+	PurpleContactInfo *info = NULL;
 	PurpleNotification *notification = NULL;
 	gchar *title = NULL;
 	const gchar *alias = NULL, *username = NULL;
@@ -484,6 +488,7 @@
 	                     NULL);
 
 	account = purple_authorization_request_get_account(authorization_request);
+	info = PURPLE_CONTACT_INFO(account);
 	notification = purple_notification_new(PURPLE_NOTIFICATION_TYPE_AUTHORIZATION_REQUEST,
 	                                       account, authorization_request,
 	                                       g_object_unref);
@@ -495,11 +500,12 @@
 		title = g_strdup_printf(_("%s (%s) would like to add %s to their"
 		                          " contact list"),
 		                        alias, username,
-		                        purple_account_get_username(account));
+		                        purple_contact_info_get_username(info));
 	} else {
 		title = g_strdup_printf(_("%s would like to add %s to their contact"
 		                          " list"),
-		                        username, purple_account_get_username(account));
+		                        username,
+		                        purple_contact_info_get_username(info));
 	}
 
 	purple_notification_set_title(notification, title);
@@ -524,7 +530,7 @@
 	                                       account, info, NULL);
 
 	/* Set the title of the notification. */
-	username = purple_account_get_username(account);
+	username = purple_contact_info_get_username(PURPLE_CONTACT_INFO(account));
 	if(purple_account_get_enabled(account)) {
 		title = g_strdup_printf(_("%s disconnected"), username);
 	} else {
diff --git a/libpurple/purplesqlitehistoryadapter.c b/libpurple/purplesqlitehistoryadapter.c
--- a/libpurple/purplesqlitehistoryadapter.c
+++ b/libpurple/purplesqlitehistoryadapter.c
@@ -425,6 +425,7 @@
                                     PurpleMessage *message, GError **error)
 {
 	PurpleAccount *account = NULL;
+	PurpleContactInfo *info = NULL;
 	PurpleSqliteHistoryAdapter *sqlite_adapter = NULL;
 	sqlite3_stmt *prepared_statement = NULL;
 	gchar *timestamp = NULL;
@@ -457,12 +458,13 @@
 	}
 
 	account = purple_conversation_get_account(conversation);
+	info = PURPLE_CONTACT_INFO(account);
 
 	sqlite3_bind_text(prepared_statement,
 	                  1, purple_account_get_protocol_name(account), -1,
 	                  SQLITE_STATIC);
 	sqlite3_bind_text(prepared_statement,
-	                  2, purple_account_get_username(account), -1,
+	                  2, purple_contact_info_get_username(info), -1,
 	                  SQLITE_STATIC);
 	sqlite3_bind_text(prepared_statement,
 	                  3, purple_conversation_get_name(conversation), -1,
diff --git a/libpurple/savedstatuses.c b/libpurple/savedstatuses.c
--- a/libpurple/savedstatuses.c
+++ b/libpurple/savedstatuses.c
@@ -228,15 +228,21 @@
 static PurpleXmlNode *
 substatus_to_xmlnode(PurpleSavedStatusSub *substatus)
 {
+	PurpleContactInfo *info = NULL;
 	PurpleXmlNode *node, *child;
+	const char *name = NULL;
+
+	info = PURPLE_CONTACT_INFO(substatus->account);
 
 	node = purple_xmlnode_new("substatus");
 
 	child = purple_xmlnode_new_child(node, "account");
 	purple_xmlnode_set_attrib(child, "protocol", purple_account_get_protocol_id(substatus->account));
-	purple_xmlnode_insert_data(child,
-			purple_normalize(substatus->account,
-				purple_account_get_username(substatus->account)), -1);
+
+	name = purple_normalize(substatus->account,
+	                        purple_contact_info_get_username(info));
+
+	purple_xmlnode_insert_data(child, name, -1);
 
 	child = purple_xmlnode_new_child(node, "state");
 	purple_xmlnode_insert_data(child, purple_status_type_get_id(substatus->type), -1);
diff --git a/libpurple/server.c b/libpurple/server.c
--- a/libpurple/server.c
+++ b/libpurple/server.c
@@ -482,6 +482,7 @@
 						  const char *who, const char *message, GHashTable *data)
 {
 	PurpleAccount *account;
+	PurpleContactInfo *info = NULL;
 	struct chat_invite_data *cid;
 	int plugin_return;
 
@@ -489,6 +490,7 @@
 	g_return_if_fail(who != NULL);
 
 	account = purple_connection_get_account(gc);
+	info = PURPLE_CONTACT_INFO(account);
 	cid = g_new0(struct chat_invite_data, 1);
 
 	plugin_return = GPOINTER_TO_INT(purple_signal_emit_return_1(
@@ -502,17 +504,18 @@
 	{
 		char *buf2;
 
-		if (message != NULL)
-		{
-			buf2 = g_strdup_printf(
-				   _("%s has invited %s to the chat room %s:\n%s"),
-				   who, purple_account_get_username(account), name, message);
+		if(message != NULL) {
+			buf2 = g_strdup_printf(_("%s has invited %s to the chat room "
+			                         "%s:\n%s"),
+			                       who,
+			                       purple_contact_info_get_username(info),
+			                       name, message);
+		} else {
+			buf2 = g_strdup_printf(_("%s has invited %s to the chat room %s\n"),
+			                       who,
+			                       purple_contact_info_get_username(info),
+			                       name);
 		}
-		else
-			buf2 = g_strdup_printf(
-				   _("%s has invited %s to the chat room %s\n"),
-				   who, purple_account_get_username(account), name);
-
 
 		purple_request_accept_cancel(gc, NULL,
 			_("Accept chat invitation?"), buf2,
@@ -653,8 +656,9 @@
 		pmsg = purple_message_new_incoming(who, message, flags, mtime);
 	} else {
 		PurpleAccount *account = purple_connection_get_account(g);
+		PurpleContactInfo *info = PURPLE_CONTACT_INFO(account);
 		GDateTime *dt = g_date_time_new_from_unix_local((gint64)mtime);
-		const gchar *me = purple_account_get_name_for_display(account);
+		const gchar *me = purple_contact_info_get_name_for_display(info);
 
 		pmsg = purple_message_new_outgoing(me, who, message, flags);
 		purple_message_set_timestamp(pmsg, dt);
diff --git a/libpurple/tests/test_account_manager.c b/libpurple/tests/test_account_manager.c
--- a/libpurple/tests/test_account_manager.c
+++ b/libpurple/tests/test_account_manager.c
@@ -100,6 +100,7 @@
 static gboolean
 test_purple_account_manager_find_func(gconstpointer a, gconstpointer b) {
 	PurpleAccount *account = PURPLE_ACCOUNT((gpointer)a);
+	PurpleContactInfo *info = PURPLE_CONTACT_INFO(account);
 	const gchar *desired_username = b;
 	const gchar *protocol_id = NULL;
 	const gchar *username = NULL;
@@ -111,7 +112,7 @@
 	}
 
 	/* Finally verify the username. */
-	username = purple_account_get_username(account);
+	username = purple_contact_info_get_username(info);
 	if(!purple_strequal(username, desired_username)) {
 		return FALSE;
 	}
