--- a/libpurple/purplecontact.c Thu Sep 29 01:08:59 2022 -0500
+++ b/libpurple/purplecontact.c Thu Sep 29 03:48:09 2022 -0500
@@ -343,13 +343,12 @@
*****************************************************************************/
-purple_contact_new(PurpleAccount *account, const gchar *username) {
+purple_contact_new(PurpleAccount *account, const gchar *id) { g_return_val_if_fail(PURPLE_IS_ACCOUNT(account), NULL);
- g_return_val_if_fail(username != NULL, NULL);
return g_object_new(PURPLE_TYPE_CONTACT,
--- a/libpurple/purplecontact.h Thu Sep 29 01:08:59 2022 -0500
+++ b/libpurple/purplecontact.h Thu Sep 29 03:48:09 2022 -0500
@@ -48,11 +48,17 @@
* @account: The [class@Purple.Account] this contact is from.
- * @username: The username of the contact.
+ * @id: (nullable): The id of the contact. * Creates a new [class@Purple.Contact].
+ * If @id is %NULL, an ID will be randomly generated. + * Returns: (transfer full): The new instance. -PurpleContact *purple_contact_new(PurpleAccount *account, const gchar *username);
+PurpleContact *purple_contact_new(PurpleAccount *account, const gchar *id); * purple_contact_get_account:
--- a/libpurple/purplecontactmanager.c Thu Sep 29 01:08:59 2022 -0500
+++ b/libpurple/purplecontactmanager.c Thu Sep 29 03:48:09 2022 -0500
@@ -323,7 +323,8 @@
- needle = purple_contact_new(account, username);
+ needle = purple_contact_new(account, NULL); + purple_contact_set_username(needle, username); found = g_list_store_find_with_equal_func(contacts, needle,
purple_contact_manager_find_with_username_helper,
@@ -354,8 +355,7 @@
- needle = g_object_new(PURPLE_TYPE_CONTACT, "account", account, "id", id,
+ needle = purple_contact_new(account, id); found = g_list_store_find_with_equal_func(contacts, needle,
purple_contact_manager_find_with_id_helper,
--- a/libpurple/tests/test_contact.c Thu Sep 29 01:08:59 2022 -0500
+++ b/libpurple/tests/test_contact.c Thu Sep 29 03:48:09 2022 -0500
@@ -31,10 +31,10 @@
PurpleContact *contact = NULL;
account = purple_account_new("test", "test");
- contact = purple_contact_new(account, "username");
+ contact = purple_contact_new(account, "id"); g_assert_true(purple_contact_get_account(contact) == account);
- g_assert_cmpstr(purple_contact_get_username(contact), ==, "username");
+ g_assert_cmpstr(purple_contact_get_id(contact), ==, "id"); g_clear_object(&contact);
g_clear_object(&account);
@@ -69,6 +69,7 @@
"display-name", "display-name",
@@ -91,7 +92,7 @@
/* Compare all the things. */
+ g_assert_cmpstr(id, ==, "id1"); g_assert_true(account1 == account);
g_assert_cmpstr(username, ==, "username");
g_assert_cmpstr(display_name, ==, "display-name");
--- a/libpurple/tests/test_contact_manager.c Thu Sep 29 01:08:59 2022 -0500
+++ b/libpurple/tests/test_contact_manager.c Thu Sep 29 03:48:09 2022 -0500
@@ -198,10 +198,12 @@
account = purple_account_new("test", "test");
- contact1 = purple_contact_new(account, "user1");
+ contact1 = purple_contact_new(account, NULL); + purple_contact_set_username(contact1, "user1"); purple_contact_manager_add(manager, contact1);
- contact2 = purple_contact_new(account, "user2");
+ contact2 = purple_contact_new(account, NULL); + purple_contact_set_username(contact2, "user2"); purple_contact_manager_add(manager, contact2);
found = purple_contact_manager_find_with_username(manager, account,
@@ -235,12 +237,10 @@
account = purple_account_new("test", "test");
- contact1 = g_object_new(PURPLE_TYPE_CONTACT, "account", account, "id",
+ contact1 = purple_contact_new(account, "id-1"); purple_contact_manager_add(manager, contact1);
- contact2 = g_object_new(PURPLE_TYPE_CONTACT, "account", account, "id",
+ contact2 = purple_contact_new(account, "id-2"); purple_contact_manager_add(manager, contact2);
found = purple_contact_manager_find_with_id(manager, account, "id-1");