pidgin/pidgin

1ecc0512e714
Parents 9da3c24cac29
Children 50a483611feb
Make purple_contact_new take the id instead of the username.

Username is already readwrite, but id is not, and most protocols have id's for
everything, so lets make that the normal case in the api.

Testing Done:
Ran the unit tests.

Reviewed at https://reviews.imfreedom.org/r/1851/
--- 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 @@
* Public API
*****************************************************************************/
PurpleContact *
-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,
"account", account,
- "username", username,
+ "id", id,
NULL);
}
--- 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 @@
/**
* purple_contact_new:
* @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.
+ *
+ * Since: 3.0.0
*/
-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 @@
return NULL;
}
- 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,
&position);
@@ -354,8 +355,7 @@
return NULL;
}
- needle = g_object_new(PURPLE_TYPE_CONTACT, "account", account, "id", id,
- NULL);
+ needle = purple_contact_new(account, id);
found = g_list_store_find_with_equal_func(contacts, needle,
purple_contact_manager_find_with_id_helper,
&position);
--- 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 @@
contact = g_object_new(
PURPLE_TYPE_CONTACT,
"account", account,
+ "id", "id1",
"username", "username",
"display-name", "display-name",
"alias", "alias",
@@ -91,7 +92,7 @@
NULL);
/* Compare all the things. */
- g_assert_nonnull(id);
+ 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",
- "id-1", NULL);
+ contact1 = purple_contact_new(account, "id-1");
purple_contact_manager_add(manager, contact1);
- contact2 = g_object_new(PURPLE_TYPE_CONTACT, "account", account, "id",
- "id-2", NULL);
+ contact2 = purple_contact_new(account, "id-2");
purple_contact_manager_add(manager, contact2);
found = purple_contact_manager_find_with_id(manager, account, "id-1");