--- a/protocols/demo/purpledemoprotocolactions.c Thu Sep 19 23:25:05 2024 -0500 +++ b/protocols/demo/purpledemoprotocolactions.c Fri Sep 20 20:27:48 2024 -0500 @@ -517,6 +517,55 @@ g_clear_object(&account); } +static const char *auth_request_ids[] = {"chuck", "eve", "mallory", "michael"}; + +static void +purple_demo_protocol_authorization_request(G_GNUC_UNUSED GSimpleAction *action, + GVariant *parameter, + G_GNUC_UNUSED gpointer data) +{ + PurpleAccount *account = NULL; + PurpleAccountManager *account_manager = NULL; + PurpleAuthorizationRequest *request = NULL; + PurpleContact *contact = NULL; + PurpleContactManager *contact_manager = NULL; + PurpleNotification *notification = NULL; + PurpleNotificationManager *notification_manager = NULL; + PurpleTags *tags = NULL; + const char *account_id = NULL; + const char *message = NULL; + static guint counter = 0; + + account_id = g_variant_get_string(parameter, NULL); + account_manager = purple_account_manager_get_default(); + account = purple_account_manager_find_by_id(account_manager, account_id); + + contact_manager = purple_contact_manager_get_default(); + contact = purple_contact_manager_find_with_id(contact_manager, account, + auth_request_ids[counter]); + + tags = purple_contact_info_get_tags(PURPLE_CONTACT_INFO(contact)); + message = purple_tags_get(tags, "auth-request-msg"); + + request = purple_authorization_request_new(contact); + if(!purple_strempty(message)) { + purple_authorization_request_set_message(request, message); + } + + notification = purple_notification_authorization_request_new(NULL, + request); + notification_manager = purple_notification_manager_get_default(); + purple_notification_manager_add(notification_manager, notification); + + counter++; + if(counter >= G_N_ELEMENTS(auth_request_ids)) { + counter = 0; + } + + g_clear_object(¬ification); + g_clear_object(&account); +} + /****************************************************************************** * Helpers *****************************************************************************/ @@ -541,6 +590,10 @@ .activate = purple_demo_protocol_remote_add, .parameter_type = "s", }, { + .name = "authorization-request", + .activate = purple_demo_protocol_authorization_request, + .parameter_type = "s", + }, { .name = "request-fields", .activate = purple_demo_protocol_request_fields_activate, .parameter_type = "s", @@ -590,6 +643,13 @@ g_menu_append_item(menu, item); g_object_unref(item); + item = g_menu_item_new(_("Trigger a contact authorization request"), + "prpl-demo.authorization-request"); + g_menu_item_set_attribute(item, PURPLE_MENU_ATTRIBUTE_DYNAMIC_TARGET, "s", + "account"); + g_menu_append_item(menu, item); + g_object_unref(item); + item = g_menu_item_new(_("Request Fields"), "prpl-demo.request-fields"); g_menu_item_set_attribute(item, PURPLE_MENU_ATTRIBUTE_DYNAMIC_TARGET, "s", "account");