Thu, 24 Apr 2025 21:42:59 -0500
Add Purple.Contact.is_own_account
This checks to see if a Purple.Contact shares the Purple.ContactInfo with the
account it is tied to.
Testing Done:
Ran the unit tests under valgrind and called in the turtles.
Reviewed at https://reviews.imfreedom.org/r/3985/
--- a/libpurple/purplecontact.c Thu Apr 24 20:42:31 2025 -0500 +++ b/libpurple/purplecontact.c Thu Apr 24 21:42:59 2025 -0500 @@ -171,6 +171,19 @@ NULL); } +gboolean +purple_contact_is_own_account(PurpleContact *contact) { + PurpleContactInfo *account_info = NULL; + PurpleContactInfo *contact_info = NULL; + + g_return_val_if_fail(PURPLE_IS_CONTACT(contact), FALSE); + + account_info = purple_account_get_contact_info(contact->account); + contact_info = PURPLE_CONTACT_INFO(contact); + + return purple_contact_info_equal(account_info, contact_info); +} + PurpleAccount * purple_contact_get_account(PurpleContact *contact) { g_return_val_if_fail(PURPLE_IS_CONTACT(contact), NULL);
--- a/libpurple/purplecontact.h Thu Apr 24 20:42:31 2025 -0500 +++ b/libpurple/purplecontact.h Thu Apr 24 21:42:59 2025 -0500 @@ -171,6 +171,22 @@ PURPLE_AVAILABLE_IN_3_0 gboolean purple_contact_equal(PurpleContact *a, PurpleContact *b); +/** + * purple_contact_is_own_account: + * + * Checks if contact is for the contact info of the account that it is tied to. + * + * This is just a helper around calling [method@ContactInfo.equal] with the + * contact and [method@Account.get_contact_info] from the account for this + * contact. + * + * Returns: true if this contact is for the account it belongs to. + * + * Since: 3.0 + */ +PURPLE_AVAILABLE_IN_3_0 +gboolean purple_contact_is_own_account(PurpleContact *contact); + G_END_DECLS #endif /* PURPLE_CONTACT_H */
--- a/libpurple/tests/test_contact.c Thu Apr 24 20:42:31 2025 -0500 +++ b/libpurple/tests/test_contact.c Thu Apr 24 21:42:59 2025 -0500 @@ -76,6 +76,29 @@ g_clear_object(&account); } +static void +test_purple_contact_is_own_account(void) { + PurpleAccount *account = NULL; + PurpleContact *contact = NULL; + PurpleContactInfo *info = NULL; + + account = purple_account_new("test", "test"); + + /* Create a random contact and verify that it is not the account. */ + contact = purple_contact_new(account, "id"); + + g_assert_false(purple_contact_is_own_account(contact)); + g_assert_finalize_object(contact); + + /* Now create a contact info with the account's contact's id. */ + info = purple_account_get_contact_info(account); + contact = purple_contact_new(account, purple_contact_info_get_id(info)); + g_assert_true(purple_contact_is_own_account(contact)); + g_assert_finalize_object(contact); + + g_clear_object(&account); +} + /****************************************************************************** * Compare *****************************************************************************/ @@ -295,6 +318,9 @@ g_test_add_func("/contact/properties", test_purple_contact_properties); + g_test_add_func("/contact/is_own_account", + test_purple_contact_is_own_account); + g_test_add_func("/contact/compare/not_null__null", test_purple_contact_compare_not_null__null); g_test_add_func("/contact/compare/null__not_null",