--- a/libpurple/purplemessage.c Wed Feb 22 22:21:40 2023 -0600
+++ b/libpurple/purplemessage.c Thu Feb 23 01:01:07 2023 -0600
@@ -42,6 +42,8 @@
PurpleMessageFlags flags;
@@ -56,6 +58,7 @@
static GParamSpec *properties[N_PROPERTIES];
@@ -119,6 +122,9 @@
g_value_set_flags(value, purple_message_get_flags(message));
+ g_value_set_boxed(value, purple_message_get_error(message)); G_OBJECT_WARN_INVALID_PROPERTY_ID(object, param_id, pspec);
@@ -160,6 +166,9 @@
purple_message_set_flags(message, g_value_get_flags(value));
+ purple_message_set_error(message, g_value_get_boxed(value)); G_OBJECT_WARN_INVALID_PROPERTY_ID(object, param_id, pspec);
@@ -177,6 +186,8 @@
g_free(message->recipient);
g_free(message->contents);
+ g_clear_error(&message->error); if(message->timestamp != NULL) {
g_date_time_unref(message->timestamp);
@@ -317,6 +328,20 @@
PURPLE_TYPE_MESSAGE_FLAGS, 0,
G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS);
+ * An error that this message encountered. This could be something like a + * failed delivery, or failed redaction, or rate limited, etc. + properties[PROP_ERROR] = g_param_spec_boxed( + "An error that the message encountered", + G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS); g_object_class_install_properties(obj_class, N_PROPERTIES, properties);
@@ -574,6 +599,25 @@
+purple_message_set_error(PurpleMessage *message, GError *error) { + g_return_if_fail(PURPLE_IS_MESSAGE(message)); + g_clear_error(&message->error); + g_propagate_error(&message->error, error); + g_object_notify_by_pspec(G_OBJECT(message), properties[PROP_ERROR]); +purple_message_get_error(PurpleMessage *message) { + g_return_val_if_fail(PURPLE_IS_MESSAGE(message), NULL); purple_message_add_attachment(PurpleMessage *message,
PurpleAttachment *attachment)
--- a/libpurple/purplemessage.h Wed Feb 22 22:21:40 2023 -0600
+++ b/libpurple/purplemessage.h Thu Feb 23 01:01:07 2023 -0600
@@ -378,6 +378,29 @@
PurpleMessageFlags purple_message_get_flags(PurpleMessage *message);
+ * purple_message_set_error: + * @message: The instance. + * @error: (nullable) (transfer full): The error to set. + * Sets the error of @message to at @error. +void purple_message_set_error(PurpleMessage *message, GError *error); + * purple_message_get_error: + * @message: The instance. + * Gets the error from @message. + * Returns: (nullable) (transfer none): The error from @message or %NULL. +GError *purple_message_get_error(PurpleMessage *message); * purple_message_add_attachment:
* @message: The #PurpleMessage instance.
* @attachment: The #PurpleAttachment instance.
--- a/libpurple/tests/meson.build Wed Feb 22 22:21:40 2023 -0600
+++ b/libpurple/tests/meson.build Thu Feb 23 01:01:07 2023 -0600
@@ -14,6 +14,7 @@
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/libpurple/tests/test_message.c Thu Feb 23 01:01:07 2023 -0600
@@ -0,0 +1,108 @@
+ * Purple - Internet Messaging Library + * Copyright (C) Pidgin Developers <devel@pidgin.im> + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 2 of the License, or (at your option) any later version. + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * You should have received a copy of the GNU Lesser General Public + * License along with this library; if not, see <https://www.gnu.org/licenses/>. +/****************************************************************************** + *****************************************************************************/ +test_purple_message_properties(void) { + PurpleMessage *message = NULL; + PurpleMessageContentType content_type = 0; + PurpleMessageFlags flags = 0; + GDateTime *timestamp = NULL; + GDateTime *timestamp1 = NULL; + char *author_alias = NULL; + char *author_name_color = NULL; + char *recipient = NULL; + timestamp = g_date_time_new_from_unix_utc(911347200); + error = g_error_new(g_quark_from_static_string("test-message"), 0, + message = g_object_new( + "author-alias", "alias", + "author-name-color", "purple", + "contents", "Now that is a big door", + "content-type", PURPLE_MESSAGE_CONTENT_TYPE_MARKDOWN, + "timestamp", timestamp, + "flags", PURPLE_MESSAGE_SYSTEM, + "author-alias", &author_alias, + "author-name-color", &author_name_color, + "recipient", &recipient, + "content-type", &content_type, + "timestamp", ×tamp1, + g_assert_cmpstr(id, ==, "id"); + g_assert_cmpstr(author, ==, "author"); + g_assert_cmpstr(author_alias, ==, "alias"); + g_assert_cmpstr(author_name_color, ==, "purple"); + g_assert_cmpstr(recipient, ==, "pidgy"); + g_assert_cmpstr(contents, ==, "Now that is a big door"); + g_assert_cmpint(content_type, ==, PURPLE_MESSAGE_CONTENT_TYPE_MARKDOWN); + g_assert_true(g_date_time_equal(timestamp1, timestamp)); + g_assert_cmpint(flags, ==, PURPLE_MESSAGE_SYSTEM); + g_assert_error(error1, error->domain, error->code); + g_clear_pointer(&id, g_free); + g_clear_pointer(&author, g_free); + g_clear_pointer(&author_alias, g_free); + g_clear_pointer(&author_name_color, g_free); + g_clear_pointer(&recipient, g_free); + g_clear_pointer(&contents, g_free); + g_clear_pointer(×tamp, g_date_time_unref); + g_clear_pointer(×tamp1, g_date_time_unref); + g_clear_error(&error1); + g_clear_object(&message); +/****************************************************************************** + *****************************************************************************/ +main(gint argc, gchar *argv[]) { + g_test_init(&argc, &argv, NULL); + g_test_add_func("/message/properties", + test_purple_message_properties);