Thu, 31 Jul 2025 16:55:45 -0500
Remove searching from Purple.ProtocolContacts
This is being moved to Purple.ProtocolDirectory and being implemented in a
different way.
Testing Done:
Called in the turtles.
Reviewed at https://reviews.imfreedom.org/r/4078/
--- a/libpurple/purpleprotocolcontacts.c Thu Jul 31 16:54:02 2025 -0500 +++ b/libpurple/purpleprotocolcontacts.c Thu Jul 31 16:55:45 2025 -0500 @@ -25,15 +25,6 @@ #include "util.h" /****************************************************************************** - * Default Implementations - *****************************************************************************/ -static guint -purple_protocol_contacts_default_get_minimum_search_length(G_GNUC_UNUSED PurpleProtocolContacts *protocol_contacts) -{ - return 3; -} - -/****************************************************************************** * GInterface Implementation *****************************************************************************/ G_DEFINE_INTERFACE(PurpleProtocolContacts, purple_protocol_contacts, @@ -42,128 +33,11 @@ static void purple_protocol_contacts_default_init(G_GNUC_UNUSED PurpleProtocolContactsInterface *iface) { - iface->get_minimum_search_length = purple_protocol_contacts_default_get_minimum_search_length; } /****************************************************************************** * Public API *****************************************************************************/ -gboolean -purple_protocol_contacts_implements_search(PurpleProtocolContacts *protocol_contacts) -{ - PurpleProtocolContactsInterface *iface = NULL; - - g_return_val_if_fail(PURPLE_IS_PROTOCOL_CONTACTS(protocol_contacts), - FALSE); - - iface = PURPLE_PROTOCOL_CONTACTS_GET_IFACE(protocol_contacts); - - if(iface->get_minimum_search_length == NULL) { - return FALSE; - } - - if(iface->search_async == NULL) { - return FALSE; - } - - if(iface->search_finish == NULL) { - return FALSE; - } - - return TRUE; -} - -guint -purple_protocol_contacts_get_minimum_search_length(PurpleProtocolContacts *protocol_contacts) -{ - PurpleProtocolContactsInterface *iface = NULL; - - g_return_val_if_fail(PURPLE_IS_PROTOCOL_CONTACTS(protocol_contacts), 3); - - iface = PURPLE_PROTOCOL_CONTACTS_GET_IFACE(protocol_contacts); - if(iface != NULL && iface->get_minimum_search_length != NULL) { - return iface->get_minimum_search_length(protocol_contacts); - } - - return 3; -} - -void -purple_protocol_contacts_search_async(PurpleProtocolContacts *protocol_contacts, - PurpleAccount *account, - const char *text, - GCancellable *cancellable, - GAsyncReadyCallback callback, - gpointer data) -{ - PurpleProtocolContactsInterface *iface = NULL; - - g_return_if_fail(PURPLE_IS_PROTOCOL_CONTACTS(protocol_contacts)); - g_return_if_fail(PURPLE_IS_ACCOUNT(account)); - g_return_if_fail(!purple_strempty(text)); - - iface = PURPLE_PROTOCOL_CONTACTS_GET_IFACE(protocol_contacts); - if(iface != NULL && iface->search_async != NULL) { - iface->search_async(protocol_contacts, account, text, cancellable, - callback, data); - } else { - g_task_report_new_error(G_OBJECT(protocol_contacts), callback, data, - purple_protocol_contacts_search_async, - PURPLE_PROTOCOL_CONTACTS_DOMAIN, 0, - "%s does not implement search_async", - G_OBJECT_TYPE_NAME(protocol_contacts)); - } -} - -GListModel * -purple_protocol_contacts_search_finish(PurpleProtocolContacts *protocol_contacts, - GAsyncResult *result, - GError **error) -{ - PurpleProtocolContactsInterface *iface = NULL; - - g_return_val_if_fail(PURPLE_IS_PROTOCOL_CONTACTS(protocol_contacts), NULL); - g_return_val_if_fail(G_IS_ASYNC_RESULT(result), NULL); - - if(g_async_result_is_tagged(result, purple_protocol_contacts_search_async)) - { - return g_task_propagate_pointer(G_TASK(result), error); - } - - iface = PURPLE_PROTOCOL_CONTACTS_GET_IFACE(protocol_contacts); - if(iface != NULL && iface->search_finish != NULL) { - GListModel *ret = NULL; - - ret = iface->search_finish(protocol_contacts, result, error); - if(G_IS_LIST_MODEL(ret)) { - GType type = G_TYPE_INVALID; - - type = g_list_model_get_item_type(G_LIST_MODEL(ret)); - if(g_type_is_a(type, PURPLE_TYPE_CONTACT_INFO)) { - return ret; - } - - /* The GListModel we got back doesn't have an item type that is - * PurpleContactInfo or a subclass of it. - */ - g_clear_object(&ret); - - g_set_error(error, PURPLE_PROTOCOL_CONTACTS_DOMAIN, 0, - "%s returned a list of type %s which is not " - "PurpleContactInfo or a subclass of", - G_OBJECT_TYPE_NAME(protocol_contacts), - g_type_name(type)); - } - - return ret; - } - - g_warning("purple_protocol_contacts_search_finish called without calling " - "purple_protocol_contacts_search_async"); - - return NULL; -} - void purple_protocol_contacts_get_profile_async(PurpleProtocolContacts *protocol_contacts, PurpleContactInfo *info,
--- a/libpurple/purpleprotocolcontacts.h Thu Jul 31 16:54:02 2025 -0500 +++ b/libpurple/purpleprotocolcontacts.h Thu Jul 31 16:55:45 2025 -0500 @@ -65,10 +65,6 @@ GTypeInterface parent; /*< public >*/ - guint (*get_minimum_search_length)(PurpleProtocolContacts *protocol_contacts); - void (*search_async)(PurpleProtocolContacts *protocol_contacts, PurpleAccount *account, const char *text, GCancellable *cancellable, GAsyncReadyCallback callback, gpointer data); - GListModel *(*search_finish)(PurpleProtocolContacts *protocol_contacts, GAsyncResult *result, GError **error); - void (*get_profile_async)(PurpleProtocolContacts *protocol_contacts, PurpleContactInfo *info, GCancellable *cancellable, GAsyncReadyCallback callback, gpointer data); char *(*get_profile_finish)(PurpleProtocolContacts *protocol_contacts, GAsyncResult *result, GError **error); @@ -82,75 +78,6 @@ G_BEGIN_DECLS /** - * purple_protocol_contacts_implements_search: - * @protocol_contacts: The instance. - * - * Checks if @protocol_contacts implements - * [vfunc@ProtocolContacts.search_async] and - * [vfunc@ProtocolContacts.search_finish]. - * - * Returns: %TRUE if the search interface is implemented, otherwise %FALSE. - * - * Since: 3.0 - */ -PURPLE_AVAILABLE_IN_3_0 -gboolean purple_protocol_contacts_implements_search(PurpleProtocolContacts *protocol_contacts); - -/** - * purple_protocol_contacts_get_minimum_search_length: - * @protocol_contacts: The instance. - * - * Gets the minimum length of the search term before - * [method@ProtocolContacts.search_async] should be called. - * - * The default implementation returns 3. - * - * Returns: The minimum length of the search term. - * - * Since: 3.0 - */ -PURPLE_AVAILABLE_IN_3_0 -guint purple_protocol_contacts_get_minimum_search_length(PurpleProtocolContacts *protocol_contacts); - -/** - * purple_protocol_contacts_search_async: - * @protocol_contacts: The instance. - * @account: The [class@Account] to search under. - * @text: The text to search for which must not be an empty string. - * @cancellable: (nullable): optional GCancellable object, %NULL to ignore. - * @callback: (scope async): a #GAsyncReadyCallback to call when the request is - * satisfied. - * @data: User data to pass to @callback. - * - * Starts the process of searching for contacts using @account that match - * @text. - * - * Call [method@ProtocolContacts.search_finish] to get the results. - * - * Since: 3.0 - */ -PURPLE_AVAILABLE_IN_3_0 -void purple_protocol_contacts_search_async(PurpleProtocolContacts *protocol_contacts, PurpleAccount *account, const char *text, GCancellable *cancellable, GAsyncReadyCallback callback, gpointer data); - -/** - * purple_protocol_contacts_search_finish: - * @protocol_contacts: The instance. - * @result: The [iface@Gio.AsyncResult] from the previous - * [method@ProtocolContacts.search_async] call. - * @error: Return address for a #GError, or %NULL. - * - * Finishes a previous call to [method@ProtocolContacts.search_async] and - * gets the result. - * - * Returns: (transfer full): A [iface@Gio.ListModel] of the matched contacts or - * %NULL with @error set on error. - * - * Since: 3.0 - */ -PURPLE_AVAILABLE_IN_3_0 -GListModel *purple_protocol_contacts_search_finish(PurpleProtocolContacts *protocol_contacts, GAsyncResult *result, GError **error); - -/** * purple_protocol_contacts_get_profile_async: * @protocol_contacts: The instance. * @info: The [class@ContactInfo] whose profile to get.
--- a/libpurple/tests/test_protocol_contacts.c Thu Jul 31 16:54:02 2025 -0500 +++ b/libpurple/tests/test_protocol_contacts.c Thu Jul 31 16:55:45 2025 -0500 @@ -65,59 +65,6 @@ * TestProtocolContactsEmpty Tests *****************************************************************************/ static void -test_purple_protocol_contacts_empty_get_minimum_search_length(void) { - PurpleProtocolContacts *protocol = NULL; - guint minimum_search_length = 0; - - protocol = g_object_new(test_purple_protocol_contacts_empty_get_type(), - NULL); - minimum_search_length = purple_protocol_contacts_get_minimum_search_length(protocol); - - /* There is a default implementation that returns 3. */ - g_assert_cmpuint(minimum_search_length, ==, 3); - - g_assert_finalize_object(protocol); -} - -static void -test_purple_protocol_contacts_empty_search_cb(GObject *source, - GAsyncResult *result, - G_GNUC_UNUSED gpointer data) -{ - PurpleProtocolContacts *protocol = NULL; - GError *error = NULL; - GListModel *model = NULL; - - g_assert_true(PURPLE_IS_PROTOCOL_CONTACTS(source)); - - protocol = PURPLE_PROTOCOL_CONTACTS(source); - - model = purple_protocol_contacts_search_finish(protocol, result, &error); - g_assert_error(error, PURPLE_PROTOCOL_CONTACTS_DOMAIN, 0); - g_clear_error(&error); - g_assert_null(model); -} - -static void -test_purple_protocol_contacts_empty_search_async(void) { - PurpleAccount *account = NULL; - PurpleProtocolContacts *protocol = NULL; - - protocol = g_object_new(test_purple_protocol_contacts_empty_get_type(), - NULL); - - account = purple_account_new("test", "test"); - purple_protocol_contacts_search_async(protocol, account, "alice", NULL, - test_purple_protocol_contacts_empty_search_cb, - NULL); - - g_main_context_iteration(NULL, FALSE); - - g_assert_finalize_object(account); - g_assert_finalize_object(protocol); -} - -static void test_purple_protocol_contacts_empty_get_profile_cb(GObject *source, GAsyncResult *result, G_GNUC_UNUSED gpointer data) @@ -203,60 +150,10 @@ gboolean should_error; - guint search_async; - guint search_finish; guint get_profile_async; guint get_profile_finish; }; -static guint -test_purple_protocol_contacts_get_minimum_search_length(PurpleProtocolContacts *protocol_contacts) { - g_assert_true(PURPLE_IS_PROTOCOL_CONTACTS(protocol_contacts)); - - return 2; -} - -static void -test_purple_protocol_contacts_search_async(PurpleProtocolContacts *protocol_contacts, - G_GNUC_UNUSED PurpleAccount *account, - G_GNUC_UNUSED const char *text, - GCancellable *cancellable, - GAsyncReadyCallback callback, - gpointer data) -{ - TestPurpleProtocolContacts *protocol = NULL; - GTask *task = NULL; - - protocol = TEST_PURPLE_PROTOCOL_CONTACTS(protocol_contacts); - protocol->search_async += 1; - - task = g_task_new(protocol_contacts, cancellable, callback, data); - if(protocol->should_error) { - GError *error = g_error_new_literal(TEST_PURPLE_PROTOCOL_CONTACTS_DOMAIN, - 0, "error"); - g_task_return_error(task, error); - } else { - g_task_return_pointer(task, - g_list_store_new(PURPLE_TYPE_CONTACT_INFO), - g_object_unref); - } - - g_clear_object(&task); -} - -static GListModel * -test_purple_protocol_contacts_search_finish(PurpleProtocolContacts *protocol_contacts, - GAsyncResult *result, - GError **error) -{ - TestPurpleProtocolContacts *protocol = NULL; - - protocol = TEST_PURPLE_PROTOCOL_CONTACTS(protocol_contacts); - protocol->search_finish += 1; - - return g_task_propagate_pointer(G_TASK(result), error); -} - static void test_purple_protocol_contacts_get_profile_async(PurpleProtocolContacts *r, G_GNUC_UNUSED PurpleContactInfo *info, @@ -315,11 +212,6 @@ static void test_purple_protocol_contacts_iface_init(PurpleProtocolContactsInterface *iface) { - iface->get_minimum_search_length = - test_purple_protocol_contacts_get_minimum_search_length; - iface->search_async = test_purple_protocol_contacts_search_async; - iface->search_finish = test_purple_protocol_contacts_search_finish; - iface->get_profile_async = test_purple_protocol_contacts_get_profile_async; iface->get_profile_finish = test_purple_protocol_contacts_get_profile_finish; @@ -335,8 +227,6 @@ static void test_purple_protocol_contacts_init(TestPurpleProtocolContacts *protocol_contacts) { - protocol_contacts->search_async = 0; - protocol_contacts->search_finish = 0; protocol_contacts->get_profile_async = 0; protocol_contacts->get_profile_finish = 0; } @@ -347,98 +237,6 @@ } /****************************************************************************** - * TestProtocolContacts search test - *****************************************************************************/ -static void -test_protocol_contacts_search_minimum_length(void) { - PurpleProtocolContacts *protocol = NULL; - guint minimum_search_length = 0; - - protocol = g_object_new(test_purple_protocol_contacts_get_type(), NULL); - - minimum_search_length = - test_purple_protocol_contacts_get_minimum_search_length(protocol); - - g_assert_cmpuint(minimum_search_length, ==, 2); - - g_assert_finalize_object(protocol); -} - -static void -test_purple_protocol_contacts_search_cb(GObject *obj, GAsyncResult *res, - G_GNUC_UNUSED gpointer data) -{ - TestPurpleProtocolContacts *test_protocol = NULL; - PurpleProtocolContacts *protocol = NULL; - GError *error = NULL; - GListModel *result = NULL; - - test_protocol = TEST_PURPLE_PROTOCOL_CONTACTS(obj); - protocol = PURPLE_PROTOCOL_CONTACTS(obj); - - result = purple_protocol_contacts_search_finish(protocol, res, &error); - if(test_protocol->should_error) { - g_assert_error(error, TEST_PURPLE_PROTOCOL_CONTACTS_DOMAIN, 0); - g_clear_error(&error); - g_assert_null(result); - } else { - GType type = G_TYPE_INVALID; - g_assert_no_error(error); - g_assert_true(G_IS_LIST_MODEL(result)); - - type = g_list_model_get_item_type(result); - g_assert_true(g_type_is_a(type, PURPLE_TYPE_CONTACT_INFO)); - g_clear_object(&result); - } -} - -static void -test_purple_protocol_contacts_search_normal(void) { - TestPurpleProtocolContacts *protocol = NULL; - PurpleAccount *account = NULL; - - protocol = g_object_new(test_purple_protocol_contacts_get_type(), NULL); - account = purple_account_new("test", "test"); - - purple_protocol_contacts_search_async(PURPLE_PROTOCOL_CONTACTS(protocol), - account, "bob", NULL, - test_purple_protocol_contacts_search_cb, - account); - - g_main_context_iteration(NULL, FALSE); - - g_assert_cmpuint(protocol->search_async, ==, 1); - g_assert_cmpuint(protocol->search_finish, ==, 1); - - g_assert_finalize_object(protocol); - g_clear_object(&account); -} - -static void -test_purple_protocol_contacts_search_error(void) { - TestPurpleProtocolContacts *protocol = NULL; - PurpleAccount *account = NULL; - - protocol = g_object_new(test_purple_protocol_contacts_get_type(), NULL); - protocol->should_error = TRUE; - - account = purple_account_new("test", "test"); - - purple_protocol_contacts_search_async(PURPLE_PROTOCOL_CONTACTS(protocol), - account, "bob", NULL, - test_purple_protocol_contacts_search_cb, - account); - - g_main_context_iteration(NULL, FALSE); - - g_assert_cmpuint(protocol->search_async, ==, 1); - g_assert_cmpuint(protocol->search_finish, ==, 1); - - g_assert_finalize_object(protocol); - g_clear_object(&account); -} - -/****************************************************************************** * TestProtocolContacts get profile test *****************************************************************************/ static void @@ -559,10 +357,6 @@ g_test_set_nonfatal_assertions(); - g_test_add_func("/protocol-contacts/empty/get-minimum-search-length", - test_purple_protocol_contacts_empty_get_minimum_search_length); - g_test_add_func("/protocol-contacts/empty/search-async", - test_purple_protocol_contacts_empty_search_async); g_test_add_func("/protocol-contacts/empty/get-profile-async", test_purple_protocol_contacts_empty_get_profile_async); g_test_add_func("/protocol-contacts/empty/get-actions", @@ -570,12 +364,6 @@ g_test_add_func("/protocol-contacts/empty/get-menu", test_purple_protocol_contacts_empty_get_menu); - g_test_add_func("/protocol-contacts/normal/get-minimum-search-length", - test_protocol_contacts_search_minimum_length); - g_test_add_func("/protocol-contacts/normal/search-async-normal", - test_purple_protocol_contacts_search_normal); - g_test_add_func("/protocol-contacts/normal/search-async-error", - test_purple_protocol_contacts_search_error); g_test_add_func("/protocol-contacts/normal/get-profile-normal", test_purple_protocol_contacts_get_profile_normal); g_test_add_func("/protocol-contacts/normal/get-profile-error",