Tue, 18 Feb 2025 23:25:56 -0600
Set Purple.Notification:create-timestamp to local now if not set
This saves everyone from having to manually call
Purple.Notification.set_created_timestamp_now manually but still allows the
property to be set at instantiation as well as after the fact.
Also remove Purple.Notification.set_created_timestamp_now since it is no longer necessary.
Testing Done:
Ran the tests under valgrind and called in the turtles.
Reviewed at https://reviews.imfreedom.org/r/3848/
--- a/libpurple/purplenotification.c Tue Feb 18 09:55:27 2025 -0600 +++ b/libpurple/purplenotification.c Tue Feb 18 23:25:56 2025 -0600 @@ -99,6 +99,39 @@ * GObject Implementation *****************************************************************************/ static void +purple_notification_constructed(GObject *obj) { + PurpleNotification *notification = NULL; + PurpleNotificationPrivate *priv = NULL; + + G_OBJECT_CLASS(purple_notification_parent_class)->constructed(obj); + + notification = PURPLE_NOTIFICATION(obj); + priv = purple_notification_get_instance_private(notification); + + if(priv->created_timestamp == NULL) { + priv->created_timestamp = g_date_time_new_now_local(); + } +} + +static void +purple_notification_finalize(GObject *obj) { + PurpleNotification *notification = PURPLE_NOTIFICATION(obj); + PurpleNotificationPrivate *priv = NULL; + + priv = purple_notification_get_instance_private(notification); + + g_clear_pointer(&priv->id, g_free); + g_clear_object(&priv->account); + + birb_date_time_clear(&priv->created_timestamp); + g_clear_pointer(&priv->title, g_free); + g_clear_pointer(&priv->subtitle, g_free); + g_clear_pointer(&priv->icon_name, g_free); + + G_OBJECT_CLASS(purple_notification_parent_class)->finalize(obj); +} + +static void purple_notification_get_property(GObject *obj, guint param_id, GValue *value, GParamSpec *pspec) { @@ -197,24 +230,6 @@ } static void -purple_notification_finalize(GObject *obj) { - PurpleNotification *notification = PURPLE_NOTIFICATION(obj); - PurpleNotificationPrivate *priv = NULL; - - priv = purple_notification_get_instance_private(notification); - - g_clear_pointer(&priv->id, g_free); - g_clear_object(&priv->account); - - birb_date_time_clear(&priv->created_timestamp); - g_clear_pointer(&priv->title, g_free); - g_clear_pointer(&priv->subtitle, g_free); - g_clear_pointer(&priv->icon_name, g_free); - - G_OBJECT_CLASS(purple_notification_parent_class)->finalize(obj); -} - -static void purple_notification_init(G_GNUC_UNUSED PurpleNotification *notification) { } @@ -222,9 +237,10 @@ purple_notification_class_init(PurpleNotificationClass *klass) { GObjectClass *obj_class = G_OBJECT_CLASS(klass); + obj_class->constructed = purple_notification_constructed; + obj_class->finalize = purple_notification_finalize; obj_class->get_property = purple_notification_get_property; obj_class->set_property = purple_notification_set_property; - obj_class->finalize = purple_notification_finalize; /** * PurpleNotification:id: @@ -444,18 +460,6 @@ } } -void -purple_notification_set_created_timestamp_now(PurpleNotification *notification) -{ - GDateTime *timestamp = NULL; - - g_return_if_fail(PURPLE_IS_NOTIFICATION(notification)); - - timestamp = g_date_time_new_now_local(); - purple_notification_set_created_timestamp(notification, timestamp); - g_date_time_unref(timestamp); -} - const char * purple_notification_get_title(PurpleNotification *notification) { PurpleNotificationPrivate *priv = NULL;
--- a/libpurple/purplenotification.h Tue Feb 18 09:55:27 2025 -0600 +++ b/libpurple/purplenotification.h Tue Feb 18 23:25:56 2025 -0600 @@ -147,17 +147,6 @@ void purple_notification_set_created_timestamp(PurpleNotification *notification, GDateTime *timestamp); /** - * purple_notification_set_created_timestamp_now: - * @notification: The instance. - * - * Sets the created timestamp of @notification to the current local time. - * - * Since: 3.0 - */ -PURPLE_AVAILABLE_IN_3_0 -void purple_notification_set_created_timestamp_now(PurpleNotification *notification); - -/** * purple_notification_get_title: * @notification: The instance. *
--- a/libpurple/tests/test_notification.c Tue Feb 18 09:55:27 2025 -0600 +++ b/libpurple/tests/test_notification.c Tue Feb 18 23:25:56 2025 -0600 @@ -40,12 +40,7 @@ id = purple_notification_get_id(notification); g_assert_nonnull(id); - /* Make sure that the created-timestamp was not set. */ - created_timestamp = purple_notification_get_created_timestamp(notification); - g_assert_null(created_timestamp); - - /* Make sure set_created_timestamp_now works. */ - purple_notification_set_created_timestamp_now(notification); + /* Make sure that the created-timestamp was set. */ created_timestamp = purple_notification_get_created_timestamp(notification); g_assert_nonnull(created_timestamp);