--- a/libpurple/purpleconversation.c Tue Apr 16 00:41:54 2024 -0500
+++ b/libpurple/purpleconversation.c Tue Apr 16 22:27:20 2024 -0500
@@ -95,6 +95,7 @@
static GParamSpec *properties[N_PROPERTIES] = {NULL, };
@@ -910,6 +911,26 @@
g_object_class_install_properties(obj_class, N_PROPERTIES, properties);
+ * PurpleConversation::present: + * @conversation: The instance. + * Emitted by [method@Conversation.present] when something wants the + * conversation presented to the user. + signals[SIG_PRESENT] = g_signal_new_class_handler( + G_OBJECT_CLASS_TYPE(klass), * PurpleConversation::member-added:
* @conversation: The instance.
* @member: The [class@Purple.ConversationMember] instance.
@@ -992,7 +1013,10 @@
-purple_conversation_present(G_GNUC_UNUSED PurpleConversation *conversation) {
+purple_conversation_present(PurpleConversation *conversation) { + g_return_if_fail(PURPLE_IS_CONVERSATION(conversation)); + g_signal_emit(conversation, signals[SIG_PRESENT], 0); --- a/libpurple/purpleconversation.h Tue Apr 16 00:41:54 2024 -0500
+++ b/libpurple/purpleconversation.h Tue Apr 16 22:27:20 2024 -0500
@@ -158,8 +158,7 @@
* purple_conversation_present:
* @conversation: The conversation to present
- * Present a conversation to the user. This allows core code to initiate a
- * conversation by displaying the IM dialog.
+ * Emits [signal@Conversation::present]. --- a/libpurple/purpleconversationmanager.c Tue Apr 16 00:41:54 2024 -0500
+++ b/libpurple/purpleconversationmanager.c Tue Apr 16 22:27:20 2024 -0500
@@ -30,6 +30,7 @@
SIG_CONVERSATION_CHANGED,
+ SIG_PRESENT_CONVERSATION, static guint signals[N_SIGNALS] = {0, };
@@ -105,8 +106,6 @@
/******************************************************************************
*****************************************************************************/
-/* This callback propagates the notify signal from conversations. */
purple_conversation_manager_conversation_changed_cb(GObject *source,
@@ -117,6 +116,13 @@
+purple_conversation_manager_present_conversation_cb(PurpleConversation *conversation, + g_signal_emit(data, signals[SIG_PRESENT_CONVERSATION], 0, conversation); /******************************************************************************
*****************************************************************************/
@@ -212,6 +218,29 @@
PURPLE_TYPE_CONVERSATION,
+ * PurpleConversationManager::present-conversation: + * @manager: The instance. + * @conversation: The conversation that should be presented. + * This is a propagation of [signal@Conversation::present]. This means that + * your callback will be called for any conversation that @manager knows + signals[SIG_PRESENT_CONVERSATION] = g_signal_new_class_handler( + "present-conversation", + G_OBJECT_CLASS_TYPE(klass), + PURPLE_TYPE_CONVERSATION); /******************************************************************************
@@ -258,6 +287,9 @@
g_signal_connect_object(conversation, "notify",
G_CALLBACK(purple_conversation_manager_conversation_changed_cb),
+ g_signal_connect_object(conversation, "present", + G_CALLBACK(purple_conversation_manager_present_conversation_cb), /* Tell everyone about the new conversation. */
g_signal_emit(manager, signals[SIG_REGISTERED], 0, conversation);
@@ -284,6 +316,9 @@
g_signal_handlers_disconnect_by_func(conversation,
purple_conversation_manager_conversation_changed_cb,
+ g_signal_handlers_disconnect_by_func(conversation, + purple_conversation_manager_present_conversation_cb, /* Tell everyone about the unregistered conversation. */
g_signal_emit(manager, signals[SIG_UNREGISTERED], 0, conversation);
--- a/libpurple/tests/test_conversation.c Tue Apr 16 00:41:54 2024 -0500
+++ b/libpurple/tests/test_conversation.c Tue Apr 16 22:27:20 2024 -0500
@@ -448,6 +448,46 @@
/******************************************************************************
+ *****************************************************************************/ +test_purple_conversation_present_cb(PurpleConversation *conversation, + g_assert_true(PURPLE_IS_CONVERSATION(conversation)); + *counter = *counter + 1; +test_purple_conversation_signals_present(void) { + PurpleAccount *account = NULL; + PurpleConversation *conversation = NULL; + account = purple_account_new("test", "test"); + conversation = g_object_new( + PURPLE_TYPE_CONVERSATION, + "type", PURPLE_CONVERSATION_TYPE_DM, + g_signal_connect(conversation, "present", + G_CALLBACK(test_purple_conversation_present_cb), + g_assert_cmpuint(counter, ==, 0); + purple_conversation_present(conversation); + g_assert_cmpuint(counter, ==, 1); + g_assert_finalize_object(conversation); + g_clear_object(&account); +/****************************************************************************** *****************************************************************************/
@@ -477,6 +517,9 @@
g_test_add_func("/conversation/message/write-one",
test_purple_conversation_message_write_one);
+ g_test_add_func("/conversation/signals/present", + test_purple_conversation_signals_present); --- a/libpurple/tests/test_conversation_manager.c Tue Apr 16 00:41:54 2024 -0500
+++ b/libpurple/tests/test_conversation_manager.c Tue Apr 16 22:27:20 2024 -0500
@@ -26,12 +26,15 @@
*****************************************************************************/
-test_purple_conversation_manager_counter_cb(G_GNUC_UNUSED PurpleConversationManager *manager,
- G_GNUC_UNUSED PurpleConversation *conversation,
+test_purple_conversation_manager_counter_cb(PurpleConversationManager *manager, + PurpleConversation *conversation, + g_assert_true(PURPLE_IS_CONVERSATION_MANAGER(manager)); + g_assert_true(PURPLE_IS_CONVERSATION(conversation)); @@ -163,6 +166,43 @@
g_clear_object(&manager);
+test_purple_conversation_manager_signal_present_conversation(void) { + PurpleAccount *account = NULL; + PurpleConversation *conversation = NULL; + PurpleConversationManager *manager = NULL; + account = purple_account_new("test", "test"); + manager = g_object_new(PURPLE_TYPE_CONVERSATION_MANAGER, NULL); + g_signal_connect(manager, "present-conversation", + G_CALLBACK(test_purple_conversation_manager_counter_cb), + conversation = g_object_new( + PURPLE_TYPE_CONVERSATION, + "type", PURPLE_CONVERSATION_TYPE_DM, + ret = purple_conversation_manager_register(manager, conversation); + g_assert_cmpuint(counter, ==, 0); + purple_conversation_present(conversation); + g_assert_cmpuint(counter, ==, 1); + ret = purple_conversation_manager_unregister(manager, conversation); + g_assert_finalize_object(manager); + g_assert_finalize_object(conversation); + g_clear_object(&account); /******************************************************************************
*****************************************************************************/
@@ -304,6 +344,8 @@
g_test_add_func("/conversation-manager/signals/conversation-changed",
test_purple_conversation_manager_signal_conversation_changed);
+ g_test_add_func("/conversation-manager/signals/present-conversation", + test_purple_conversation_manager_signal_present_conversation); g_test_add_func("/conversation-manager/find-dm/empty",
test_purple_conversation_manager_find_dm_empty);