Add a logging property to Purple.Conversation

Tue, 27 Aug 2024 00:01:29 -0500

author
Gary Kramlich <grim@reaperworld.com>
date
Tue, 27 Aug 2024 00:01:29 -0500
changeset 42908
64bbb9d4bf94
parent 42907
147ae29ea508
child 42909
440ed16de928

Add a logging property to Purple.Conversation

This property is used to determine whether or not we are logging messages.
It's setup in a way to mimic the way log toggling works in Google Chat so that
can be replicated, but our users may want to ignore that in the future.

Testing Done:
Ran the conversation tests under valgrind and let the turtles handle the rest.

Reviewed at https://reviews.imfreedom.org/r/3441/

libpurple/purpleconversation.c file | annotate | diff | comparison | revisions
libpurple/purpleconversation.h file | annotate | diff | comparison | revisions
libpurple/tests/test_conversation.c file | annotate | diff | comparison | revisions
--- a/libpurple/purpleconversation.c	Mon Aug 26 23:57:48 2024 -0500
+++ b/libpurple/purpleconversation.c	Tue Aug 27 00:01:29 2024 -0500
@@ -70,6 +70,8 @@
 	PurpleTypingState typing_state;
 	guint typing_state_source;
 	GDateTime *last_typing;
+
+	gboolean logging;
 };
 
 enum {
@@ -100,6 +102,7 @@
 	PROP_MESSAGES,
 	PROP_NEEDS_ATTENTION,
 	PROP_TYPING_STATE,
+	PROP_LOGGING,
 	N_PROPERTIES,
 };
 static GParamSpec *properties[N_PROPERTIES] = {NULL, };
@@ -468,6 +471,10 @@
 		purple_conversation_set_typing_state(conversation,
 		                                     g_value_get_enum(value));
 		break;
+	case PROP_LOGGING:
+		purple_conversation_set_logging(conversation,
+		                                g_value_get_boolean(value));
+		break;
 	default:
 		G_OBJECT_WARN_INVALID_PROPERTY_ID(obj, param_id, pspec);
 		break;
@@ -579,6 +586,10 @@
 		g_value_set_enum(value,
 		                 purple_conversation_get_typing_state(conversation));
 		break;
+	case PROP_LOGGING:
+		g_value_set_boolean(value,
+		                    purple_conversation_get_logging(conversation));
+		break;
 	default:
 		G_OBJECT_WARN_INVALID_PROPERTY_ID(obj, param_id, pspec);
 		break;
@@ -1081,6 +1092,18 @@
 		PURPLE_TYPING_STATE_NONE,
 		G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS);
 
+	/**
+	 * PurpleConversation:logging:
+	 *
+	 * Whether or not this conversation is currently being logged.
+	 *
+	 * Since: 3.0
+	 */
+	properties[PROP_LOGGING] = g_param_spec_boolean(
+		"logging", NULL, NULL,
+		FALSE,
+		G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS);
+
 	g_object_class_install_properties(obj_class, N_PROPERTIES, properties);
 
 	/**
@@ -1324,7 +1347,7 @@
 	g_return_if_fail(PURPLE_IS_CONVERSATION(conversation));
 	g_return_if_fail(message != NULL);
 
-	if(!(purple_message_get_flags(message) & PURPLE_MESSAGE_NO_LOG)) {
+	if(conversation->logging) {
 		GError *error = NULL;
 		PurpleHistoryManager *manager = NULL;
 		gboolean success = FALSE;
@@ -1831,3 +1854,24 @@
 		}
 	}
 }
+
+gboolean
+purple_conversation_get_logging(PurpleConversation *conversation) {
+	g_return_val_if_fail(PURPLE_IS_CONVERSATION(conversation), FALSE);
+
+	return conversation->logging;
+}
+
+void
+purple_conversation_set_logging(PurpleConversation *conversation,
+                                gboolean logging)
+{
+	g_return_if_fail(PURPLE_IS_CONVERSATION(conversation));
+
+	if(conversation->logging != logging) {
+		conversation->logging = logging;
+
+		g_object_notify_by_pspec(G_OBJECT(conversation),
+		                         properties[PROP_LOGGING]);
+	}
+}
--- a/libpurple/purpleconversation.h	Mon Aug 26 23:57:48 2024 -0500
+++ b/libpurple/purpleconversation.h	Tue Aug 27 00:01:29 2024 -0500
@@ -859,6 +859,31 @@
 PURPLE_AVAILABLE_IN_3_0
 void purple_conversation_set_typing_state(PurpleConversation *conversation, PurpleTypingState typing_state);
 
+/**
+ * purple_conversation_get_logging:
+ * @conversation: The instance.
+ *
+ * Gets whether or not @conversation is currently being logged.
+ *
+ * Returns: %TRUE if @conversation is being logged, otherwise %FALSE.
+ *
+ * Since: 3.0
+ */
+PURPLE_AVAILABLE_IN_3_0
+gboolean purple_conversation_get_logging(PurpleConversation *conversation);
+
+/**
+ * purple_conversation_set_logging:
+ * @conversation: The instance.
+ * @logging: The new logging state.
+ *
+ * Sets the logging state of @conversation to @logging.
+ *
+ * Since: 3.0
+ */
+PURPLE_AVAILABLE_IN_3_0
+void purple_conversation_set_logging(PurpleConversation *conversation, gboolean logging);
+
 G_END_DECLS
 
 #endif /* PURPLE_CONVERSATION_H */
--- a/libpurple/tests/test_conversation.c	Mon Aug 26 23:57:48 2024 -0500
+++ b/libpurple/tests/test_conversation.c	Tue Aug 27 00:01:29 2024 -0500
@@ -71,6 +71,7 @@
 	gboolean age_restricted = FALSE;
 	gboolean favorite = FALSE;
 	gboolean needs_attention = FALSE;
+	gboolean logging = FALSE;
 
 	account = g_object_new(
 		PURPLE_TYPE_ACCOUNT,
@@ -99,6 +100,7 @@
 		"description", "to describe or not to describe...",
 		"favorite", TRUE,
 		"id", "id1",
+		"logging", TRUE,
 		"name", "name1",
 		"needs-attention", TRUE,
 		"title", "test conversation",
@@ -122,6 +124,7 @@
 		"favorite", &favorite,
 		"global-id", &global_id,
 		"id", &id,
+		"logging", &logging,
 		"members", &members,
 		"name", &name,
 		"needs-attention", &needs_attention,
@@ -169,6 +172,8 @@
 	g_assert_true(G_IS_LIST_MODEL(members));
 	g_clear_object(&members);
 
+	g_assert_true(logging);
+
 	g_assert_cmpstr(name, ==, "name1");
 	g_clear_pointer(&name, g_free);
 

mercurial