Fri, 20 Sep 2024 20:27:48 -0500
Add an account action to the Demo protocol plugin to create authorization requests
I also had to bind the Purple.Notification:subtitle to the
Purple.AuthorizationRequest:message.
Testing Done:
Made sure the notification displayed as expected and wrapped properly.
Bugs closed: PIDGIN-17948
Reviewed at https://reviews.imfreedom.org/r/3506/
--- a/libpurple/purplenotificationauthorizationrequest.c Thu Sep 19 23:25:05 2024 -0500 +++ b/libpurple/purplenotificationauthorizationrequest.c Fri Sep 20 20:27:48 2024 -0500 @@ -97,6 +97,10 @@ g_signal_connect_object(contact, "notify::name-for-display", G_CALLBACK(purple_notification_authorization_request_notify_cb), notification, G_CONNECT_DEFAULT); + + g_object_bind_property(request, "message", + notification, "subtitle", + G_BINDING_BIDIRECTIONAL | G_BINDING_SYNC_CREATE); } purple_notification_set_account(PURPLE_NOTIFICATION(notification),
--- 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");
--- a/protocols/demo/resources/contacts.json Thu Sep 19 23:25:05 2024 -0500 +++ b/protocols/demo/resources/contacts.json Fri Sep 20 20:27:48 2024 -0500 @@ -136,4 +136,34 @@ "primitive": "do-not-disturb" }, "username": "Erin" +}, { + "id": "chuck", + "presence": { + "primitive": "available" + }, + "username": "Chuck" +}, { + "id": "eve", + "presence": { + "primitive": "invisible" + }, + "tags": [ + "auth-request-msg:Nice avatar!" + ], + "username": "Eve" +}, { + "id": "mallory", + "presence": { + "primitive": "offline" + }, + "username": "Mallory" +}, { + "id": "michael", + "presence": { + "primitive": "streaming" + }, + "tags": [ + "auth-request-msg:Hey come check out my stream!" + ], + "username": "Michael" }]
--- a/protocols/demo/resources/purpledemo.gresource.xml Thu Sep 19 23:25:05 2024 -0500 +++ b/protocols/demo/resources/purpledemo.gresource.xml Fri Sep 20 20:27:48 2024 -0500 @@ -10,13 +10,17 @@ <file>buddy_icons/Alice.png</file> <file>buddy_icons/Bob.png</file> <file>buddy_icons/Carlos.png</file> + <file>buddy_icons/Chuck.png</file> <file>buddy_icons/Echo.png</file> <file>buddy_icons/Eion.png</file> <file>buddy_icons/Elliott.png</file> <file>buddy_icons/Erin.png</file> + <file>buddy_icons/Eve.png</file> <file>buddy_icons/Gary.png</file> <file>buddy_icons/John.png</file> + <file>buddy_icons/Mallory.png</file> <file>buddy_icons/Markus.png</file> + <file>buddy_icons/Michael.png</file> <file>buddy_icons/Richard.png</file> </gresource> </gresources>