# HG changeset patch
# Node ID 35a6dbae67854a07f2fa6212481b7602c3a70481
# Parent  4e61e9b15844155ac9eaee7e20101f9e563f5035
diff --git a/libpurple/purpleaddcontactrequest.c b/libpurple/purpleaddcontactrequest.c
--- a/libpurple/purpleaddcontactrequest.c
+++ b/libpurple/purpleaddcontactrequest.c
@@ -25,10 +25,7 @@
 struct _PurpleAddContactRequest {
 	GObject parent;
 
-	PurpleAccount *account;
-
-	char *username;
-	char *alias;
+	PurpleContact *contact;
 	char *message;
 
 	/* This tracks whether add has been called. */
@@ -43,9 +40,7 @@
 
 enum {
 	PROP_0,
-	PROP_ACCOUNT,
-	PROP_USERNAME,
-	PROP_ALIAS,
+	PROP_CONTACT,
 	PROP_MESSAGE,
 	N_PROPERTIES,
 };
@@ -55,25 +50,13 @@
  * Helpers
  *****************************************************************************/
 static void
-purple_add_contact_request_set_account(PurpleAddContactRequest *request,
-                                       PurpleAccount *account)
-{
-	g_return_if_fail(PURPLE_IS_ADD_CONTACT_REQUEST(request));
-	g_return_if_fail(PURPLE_IS_ACCOUNT(account));
-
-	if(g_set_object(&request->account, account)) {
-		g_object_notify_by_pspec(G_OBJECT(request), properties[PROP_ACCOUNT]);
-	}
-}
-
-static void
-purple_add_contact_request_set_username(PurpleAddContactRequest *request,
-                                        const char *username)
+purple_add_contact_request_set_contact(PurpleAddContactRequest *request,
+                                       PurpleContact *contact)
 {
 	g_return_if_fail(PURPLE_IS_ADD_CONTACT_REQUEST(request));
 
-	if(g_set_str(&request->username, username)) {
-		g_object_notify_by_pspec(G_OBJECT(request), properties[PROP_USERNAME]);
+	if(g_set_object(&request->contact, contact)) {
+		g_object_notify_by_pspec(G_OBJECT(request), properties[PROP_CONTACT]);
 	}
 }
 
@@ -90,17 +73,9 @@
 	PurpleAddContactRequest *request = PURPLE_ADD_CONTACT_REQUEST(obj);
 
 	switch(param_id) {
-	case PROP_ACCOUNT:
+	case PROP_CONTACT:
 		g_value_set_object(value,
-		                   purple_add_contact_request_get_account(request));
-		break;
-	case PROP_USERNAME:
-		g_value_set_string(value,
-		                   purple_add_contact_request_get_username(request));
-		break;
-	case PROP_ALIAS:
-		g_value_set_string(value,
-		                   purple_add_contact_request_get_alias(request));
+		                   purple_add_contact_request_get_contact(request));
 		break;
 	case PROP_MESSAGE:
 		g_value_set_string(value,
@@ -120,18 +95,10 @@
 	PurpleAddContactRequest *request = PURPLE_ADD_CONTACT_REQUEST(obj);
 
 	switch(param_id) {
-	case PROP_ACCOUNT:
-		purple_add_contact_request_set_account(request,
+	case PROP_CONTACT:
+		purple_add_contact_request_set_contact(request,
 		                                       g_value_get_object(value));
 		break;
-	case PROP_USERNAME:
-		purple_add_contact_request_set_username(request,
-		                                        g_value_get_string(value));
-		break;
-	case PROP_ALIAS:
-		purple_add_contact_request_set_alias(request,
-		                                     g_value_get_string(value));
-		break;
 	case PROP_MESSAGE:
 		purple_add_contact_request_set_message(request,
 		                                       g_value_get_string(value));
@@ -146,7 +113,7 @@
 purple_add_contact_request_dispose(GObject *obj) {
 	PurpleAddContactRequest *request = PURPLE_ADD_CONTACT_REQUEST(obj);
 
-	g_clear_object(&request->account);
+	g_clear_object(&request->contact);
 
 	G_OBJECT_CLASS(purple_add_contact_request_parent_class)->dispose(obj);
 }
@@ -155,8 +122,6 @@
 purple_add_contact_request_finalize(GObject *obj) {
 	PurpleAddContactRequest *request = PURPLE_ADD_CONTACT_REQUEST(obj);
 
-	g_clear_pointer(&request->username, g_free);
-	g_clear_pointer(&request->alias, g_free);
 	g_clear_pointer(&request->message, g_free);
 
 	G_OBJECT_CLASS(purple_add_contact_request_parent_class)->finalize(obj);
@@ -178,42 +143,18 @@
 	obj_class->finalize = purple_add_contact_request_finalize;
 
 	/**
-	 * PurpleAddContactRequest:account:
+	 * PurpleAddContactRequest:contact:
 	 *
-	 * The account that this add contact request is for.
+	 * The contact that this request is for.
 	 *
 	 * Since: 3.0
 	 */
-	properties[PROP_ACCOUNT] = g_param_spec_object(
-		"account", NULL, NULL,
-		PURPLE_TYPE_ACCOUNT,
+	properties[PROP_CONTACT] = g_param_spec_object(
+		"contact", NULL, NULL,
+		PURPLE_TYPE_CONTACT,
 		G_PARAM_READWRITE | G_PARAM_CONSTRUCT_ONLY | G_PARAM_STATIC_STRINGS);
 
 	/**
-	 * PurpleAddContactRequest:username:
-	 *
-	 * The username of the remote user to be added.
-	 *
-	 * Since: 3.0
-	 */
-	properties[PROP_USERNAME] = g_param_spec_string(
-		"username", NULL, NULL,
-		NULL,
-		G_PARAM_READWRITE | G_PARAM_CONSTRUCT_ONLY | G_PARAM_STATIC_STRINGS);
-
-	/**
-	 * PurpleAddContactRequest:alias:
-	 *
-	 * The alias of the remote user to be added.
-	 *
-	 * Since: 3.0
-	 */
-	properties[PROP_ALIAS] = g_param_spec_string(
-		"alias", NULL, NULL,
-		NULL,
-		G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS);
-
-	/**
 	 * PurpleAddContactRequest:message:
 	 *
 	 * The optional message sent from the remote user.
@@ -253,47 +194,20 @@
  * Public API
  *****************************************************************************/
 PurpleAddContactRequest *
-purple_add_contact_request_new(PurpleAccount *account, const char *username) {
-	g_return_val_if_fail(PURPLE_IS_ACCOUNT(account), NULL);
-	g_return_val_if_fail(username != NULL, NULL);
+purple_add_contact_request_new(PurpleContact *contact) {
+	g_return_val_if_fail(PURPLE_IS_CONTACT(contact), NULL);
 
 	return g_object_new(
 		PURPLE_TYPE_ADD_CONTACT_REQUEST,
-		"account", account,
-		"username", username,
+		"contact", contact,
 		NULL);
 }
 
-PurpleAccount *
-purple_add_contact_request_get_account(PurpleAddContactRequest *request) {
-	g_return_val_if_fail(PURPLE_IS_ADD_CONTACT_REQUEST(request), NULL);
-
-	return request->account;
-}
-
-const char *
-purple_add_contact_request_get_username(PurpleAddContactRequest *request) {
+PurpleContact *
+purple_add_contact_request_get_contact(PurpleAddContactRequest *request) {
 	g_return_val_if_fail(PURPLE_IS_ADD_CONTACT_REQUEST(request), NULL);
 
-	return request->username;
-}
-
-void
-purple_add_contact_request_set_alias(PurpleAddContactRequest *request,
-                                     const char *alias)
-{
-	g_return_if_fail(PURPLE_IS_ADD_CONTACT_REQUEST(request));
-
-	if(g_set_str(&request->alias, alias)) {
-		g_object_notify_by_pspec(G_OBJECT(request), properties[PROP_ALIAS]);
-	}
-}
-
-const char *
-purple_add_contact_request_get_alias(PurpleAddContactRequest *request) {
-	g_return_val_if_fail(PURPLE_IS_ADD_CONTACT_REQUEST(request), NULL);
-
-	return request->alias;
+	return request->contact;
 }
 
 void
diff --git a/libpurple/purpleaddcontactrequest.h b/libpurple/purpleaddcontactrequest.h
--- a/libpurple/purpleaddcontactrequest.h
+++ b/libpurple/purpleaddcontactrequest.h
@@ -30,7 +30,7 @@
 #include <glib.h>
 #include <glib-object.h>
 
-#include "purpleaccount.h"
+#include "purplecontact.h"
 #include "purpleversion.h"
 
 G_BEGIN_DECLS
@@ -53,71 +53,29 @@
 
 /**
  * purple_add_contact_request_new:
- * @account: The account that this request is for.
- * @username: The username of the user requesting authorization.
- *
- * Creates a new [class@Purple.AddContactRequest] for @username on @account.
- *
- * This is typically only used by libpurple itself.
- *
- * Returns: The new instance.
+ * @contact: The contact that is requesting to be added.
  *
- * Since: 3.0
- */
-PURPLE_AVAILABLE_IN_3_0
-PurpleAddContactRequest *purple_add_contact_request_new(PurpleAccount *account, const char *username);
-
-/**
- * purple_add_contact_request_get_account:
- * @request: The instance.
+ * Creates a new [class@Purple.AddContactRequest] for @contact.
  *
- * Gets the [class@Account] for @request.
- *
- * Returns: (transfer none): The account.
+ * Returns: (transfer full): The new instance.
  *
  * Since: 3.0
  */
 PURPLE_AVAILABLE_IN_3_0
-PurpleAccount *purple_add_contact_request_get_account(PurpleAddContactRequest *request);
+PurpleAddContactRequest *purple_add_contact_request_new(PurpleContact *contact);
 
 /**
- * purple_add_contact_request_get_username:
+ * purple_add_contact_request_get_contact:
  * @request: The instance.
  *
- * Gets the username for the user to be added.
+ * Gets the [class@Contact] that @request was created with.
  *
- * Returns: The username of the remote user.
+ * Returns: The contact.
  *
  * Since: 3.0
  */
 PURPLE_AVAILABLE_IN_3_0
-const char *purple_add_contact_request_get_username(PurpleAddContactRequest *request);
-
-/**
- * purple_add_contact_request_set_alias:
- * @request: The instance.
- * @alias: (nullable): The alias of the remote user.
- *
- * Sets the alias of the remote user to @alias. User interfaces can use this
- * when presenting the authorization request to the end user.
- *
- * Since: 3.0
- */
-PURPLE_AVAILABLE_IN_3_0
-void purple_add_contact_request_set_alias(PurpleAddContactRequest *request, const char *alias);
-
-/**
- * purple_add_contact_request_get_alias:
- * @request: The instance.
- *
- * Gets the alias of the remote user if one was set.
- *
- * Returns: (nullable): The alias if one was set.
- *
- * Since: 3.0
- */
-PURPLE_AVAILABLE_IN_3_0
-const char *purple_add_contact_request_get_alias(PurpleAddContactRequest *request);
+PurpleContact *purple_add_contact_request_get_contact(PurpleAddContactRequest *request);
 
 /**
  * purple_add_contact_request_set_message:
diff --git a/libpurple/purplenotification.c b/libpurple/purplenotification.c
--- a/libpurple/purplenotification.c
+++ b/libpurple/purplenotification.c
@@ -505,30 +505,23 @@
 purple_notification_new_from_add_contact_request(PurpleAddContactRequest *request)
 {
 	PurpleAccount *account = NULL;
+	PurpleContact *remote = NULL;
+	PurpleContactInfo *info = NULL;
 	PurpleNotification *notification = NULL;
 	char *title = NULL;
-	const char *alias = NULL;
-	const char *username = NULL;
 
 	g_return_val_if_fail(PURPLE_IS_ADD_CONTACT_REQUEST(request), NULL);
 
-	account = purple_add_contact_request_get_account(request);
+	remote = purple_add_contact_request_get_contact(request);
+	account = purple_contact_get_account(remote);
+	info = purple_account_get_contact_info(account);
+
 	notification = purple_notification_new(PURPLE_NOTIFICATION_TYPE_ADD_CONTACT,
 	                                       account, request, g_object_unref);
 
-	username = purple_add_contact_request_get_username(request);
-	alias = purple_add_contact_request_get_alias(request);
-
-	if(alias != NULL && *alias != '\0') {
-		title = g_strdup_printf(_("%s (%s) added %s to their contact list"),
-		                        alias, username,
-		                        purple_account_get_username(account));
-	} else {
-		title = g_strdup_printf(_("%s added %s to their contact list"),
-		                        username,
-		                        purple_account_get_username(account));
-	}
-
+	title = g_strdup_printf(_("%s added %s to their contact_list"),
+	                        purple_contact_info_get_name_for_display(PURPLE_CONTACT_INFO(remote)),
+	                        purple_contact_info_get_name_for_display(info));
 	purple_notification_set_title(notification, title);
 	g_free(title);
 
diff --git a/pidgin/pidginnotificationaddcontact.c b/pidgin/pidginnotificationaddcontact.c
--- a/pidgin/pidginnotificationaddcontact.c
+++ b/pidgin/pidginnotificationaddcontact.c
@@ -158,28 +158,11 @@
 {
 	PidginNotificationAddContact *pidgin_request = data;
 	PurpleAddContactRequest *request = NULL;
-	PurpleAccount *account = NULL;
 	PurpleContact *contact = NULL;
-	PurpleContactManager *manager = NULL;
 	PurpleConversation *conversation = NULL;
-	const char *username = NULL;
 
 	request = purple_notification_get_data(pidgin_request->notification);
-
-	account = purple_add_contact_request_get_account(request);
-	username = purple_add_contact_request_get_username(request);
-
-	manager = purple_contact_manager_get_default();
-	contact = purple_contact_manager_find_with_username(manager, account,
-	                                                    username);
-
-	if(!PURPLE_IS_CONTACT(contact)) {
-		g_warning("failed to find a user named '%s' on account %s",
-		          username,
-		          purple_account_get_username(account));
-
-		return;
-	}
+	contact = purple_add_contact_request_get_contact(request);
 
 	conversation = purple_contact_find_dm(contact);
 	if(PURPLE_IS_CONVERSATION(conversation)) {
diff --git a/protocols/demo/purpledemoprotocolactions.c b/protocols/demo/purpledemoprotocolactions.c
--- a/protocols/demo/purpledemoprotocolactions.c
+++ b/protocols/demo/purpledemoprotocolactions.c
@@ -429,7 +429,7 @@
 /******************************************************************************
  * Contact action implementations
  *****************************************************************************/
-static const gchar *contacts[] = {"Alice", "Bob", "Carlos", "Erin" };
+static const gchar *contact_ids[] = {"alice", "bob", "carlos", "erin" };
 
 static void
 purple_demo_protocol_remote_add(G_GNUC_UNUSED GSimpleAction *action,
@@ -439,6 +439,8 @@
 	PurpleAccount *account = NULL;
 	PurpleAccountManager *account_manager = NULL;
 	PurpleAddContactRequest *request = NULL;
+	PurpleContact *contact = NULL;
+	PurpleContactManager *contact_manager = NULL;
 	PurpleNotification *notification = NULL;
 	PurpleNotificationManager *notification_manager = NULL;
 	const gchar *account_id = NULL;
@@ -448,14 +450,18 @@
 	account_manager = purple_account_manager_get_default();
 	account = purple_account_manager_find_by_id(account_manager, account_id);
 
-	request = purple_add_contact_request_new(account, contacts[counter]);
+	contact_manager = purple_contact_manager_get_default();
+	contact = purple_contact_manager_find_with_id(contact_manager, account,
+	                                              contact_ids[counter]);
+
+	request = purple_add_contact_request_new(contact);
 	notification = purple_notification_new_from_add_contact_request(request);
 
 	notification_manager = purple_notification_manager_get_default();
 	purple_notification_manager_add(notification_manager, notification);
 
 	counter++;
-	if(counter >= G_N_ELEMENTS(contacts)) {
+	if(counter >= G_N_ELEMENTS(contact_ids)) {
 		counter = 0;
 	}
 
