Tue, 10 Sep 2024 01:07:47 -0500
Update Purple.NotificationAddContact to take an id parameter
We also set the account property from the contact if it was not yet already
set.
Testing Done:
Ran the unit tests under valgrind and called in the turtles for the rest.
Bugs closed: PIDGIN-17938
Reviewed at https://reviews.imfreedom.org/r/3476/
--- a/libpurple/purplenotification.c Tue Sep 10 00:51:13 2024 -0500 +++ b/libpurple/purplenotification.c Tue Sep 10 01:07:47 2024 -0500 @@ -522,7 +522,7 @@ { g_return_val_if_fail(PURPLE_IS_ADD_CONTACT_REQUEST(request), NULL); - return purple_notification_add_contact_new(request); + return purple_notification_add_contact_new(NULL, request); } PurpleNotification *
--- a/libpurple/purplenotificationaddcontact.c Tue Sep 10 00:51:13 2024 -0500 +++ b/libpurple/purplenotificationaddcontact.c Tue Sep 10 01:07:47 2024 -0500 @@ -77,10 +77,17 @@ g_return_if_fail(PURPLE_IS_NOTIFICATION_ADD_CONTACT(notification)); if(g_set_object(¬ification->request, request)) { + PurpleAccount *account = NULL; + GObject *obj = G_OBJECT(notification); + + g_object_freeze_notify(obj); + if(PURPLE_IS_ADD_CONTACT_REQUEST(request)) { PurpleContact *contact = NULL; contact = purple_add_contact_request_get_contact(request); + account = purple_contact_get_account(contact); + g_signal_connect_object(contact, "notify", G_CALLBACK(purple_notification_add_contact_contact_notify_cb), notification, G_CONNECT_DEFAULT); @@ -91,8 +98,11 @@ notification, G_CONNECT_DEFAULT); } - g_object_notify_by_pspec(G_OBJECT(notification), - properties[PROP_REQUEST]); + purple_notification_set_account(PURPLE_NOTIFICATION(notification), + account); + + g_object_notify_by_pspec(obj, properties[PROP_REQUEST]); + g_object_thaw_notify(obj); purple_notification_add_contact_update(notification); } @@ -208,11 +218,14 @@ * Public API *****************************************************************************/ PurpleNotification * -purple_notification_add_contact_new(PurpleAddContactRequest *request) { +purple_notification_add_contact_new(const char *id, + PurpleAddContactRequest *request) +{ g_return_val_if_fail(PURPLE_IS_ADD_CONTACT_REQUEST(request), NULL); return g_object_new( PURPLE_TYPE_NOTIFICATION_ADD_CONTACT, + "id", id, "request", request, NULL); }
--- a/libpurple/purplenotificationaddcontact.h Tue Sep 10 00:51:13 2024 -0500 +++ b/libpurple/purplenotificationaddcontact.h Tue Sep 10 01:07:47 2024 -0500 @@ -54,16 +54,20 @@ /** * purple_notification_add_contact_new: + * @id: (nullable): An identifier for this notification. * @request: The add contact request. * * Creates a new [class@Notification] for @request. * + * Since @request has a [class@Contact] which has a [class@Account], + * [property@Notification:account] will automatically be set to that. + * * Returns: The new notification. * * Since: 3.0 */ PURPLE_AVAILABLE_IN_3_0 -PurpleNotification *purple_notification_add_contact_new(PurpleAddContactRequest *request); +PurpleNotification *purple_notification_add_contact_new(const char *id, PurpleAddContactRequest *request); /** * purple_notification_add_contact_get_request:
--- a/libpurple/tests/test_notification_add_contact.c Tue Sep 10 00:51:13 2024 -0500 +++ b/libpurple/tests/test_notification_add_contact.c Tue Sep 10 01:07:47 2024 -0500 @@ -49,7 +49,7 @@ account = purple_account_new("test", "test"); contact = purple_contact_new(account, "remote"); request = purple_add_contact_request_new(contact); - notification = purple_notification_add_contact_new(request); + notification = purple_notification_add_contact_new(NULL, request); g_assert_true(PURPLE_IS_NOTIFICATION(notification)); g_assert_true(PURPLE_IS_NOTIFICATION_ADD_CONTACT(notification)); @@ -64,10 +64,12 @@ static void test_purple_notification_add_contact_properties(void) { PurpleAccount *account = NULL; + PurpleAccount *account1 = NULL; PurpleAddContactRequest *request = NULL; PurpleAddContactRequest *request1 = NULL; PurpleContact *contact = NULL; PurpleNotification *notification = NULL; + char *id = NULL; account = purple_account_new("test", "test"); contact = purple_contact_new(account, "username"); @@ -75,14 +77,23 @@ notification = g_object_new( PURPLE_TYPE_NOTIFICATION_ADD_CONTACT, + "id", "notification1", "request", request, NULL); g_object_get( notification, + "account", &account1, + "id", &id, "request", &request1, NULL); + g_assert_true(account1 == account); + g_clear_object(&account1); + + g_assert_cmpstr(id, ==, "notification1"); + g_clear_pointer(&id, g_free); + g_assert_true(request1 == request); g_clear_object(&request1); @@ -106,7 +117,7 @@ contact = purple_contact_new(account, "remote-username"); request = purple_add_contact_request_new(contact); - notification = purple_notification_add_contact_new(request); + notification = purple_notification_add_contact_new(NULL, request); g_signal_connect(notification, "notify::title", G_CALLBACK(test_purple_notification_add_contact_notify_cb), &counter);