--- a/libpurple/purpleconversation.c Tue Apr 09 23:06:58 2024 -0500
+++ b/libpurple/purpleconversation.c Tue Apr 09 23:11:12 2024 -0500
@@ -1035,6 +1035,50 @@
/******************************************************************************
*****************************************************************************/
+purple_conversation_is_dm(PurpleConversation *conversation) { + PurpleConversationPrivate *priv = NULL; + g_return_val_if_fail(PURPLE_IS_CONVERSATION(conversation), FALSE); + priv = purple_conversation_get_instance_private(conversation); + return priv->type == PURPLE_CONVERSATION_TYPE_DM; +purple_conversation_is_group_dm(PurpleConversation *conversation) { + PurpleConversationPrivate *priv = NULL; + g_return_val_if_fail(PURPLE_IS_CONVERSATION(conversation), FALSE); + priv = purple_conversation_get_instance_private(conversation); + return priv->type == PURPLE_CONVERSATION_TYPE_GROUP_DM; +purple_conversation_is_channel(PurpleConversation *conversation) { + PurpleConversationPrivate *priv = NULL; + g_return_val_if_fail(PURPLE_IS_CONVERSATION(conversation), FALSE); + priv = purple_conversation_get_instance_private(conversation); + return priv->type == PURPLE_CONVERSATION_TYPE_CHANNEL; +purple_conversation_is_thread(PurpleConversation *conversation) { + PurpleConversationPrivate *priv = NULL; + g_return_val_if_fail(PURPLE_IS_CONVERSATION(conversation), FALSE); + priv = purple_conversation_get_instance_private(conversation); + return priv->type == PURPLE_CONVERSATION_TYPE_THREAD; purple_conversation_present(PurpleConversation *conv) {
PurpleConversationUiOps *ops;
--- a/libpurple/purpleconversation.h Tue Apr 09 23:06:58 2024 -0500
+++ b/libpurple/purpleconversation.h Tue Apr 09 23:11:12 2024 -0500
@@ -162,6 +162,70 @@
+ * purple_conversation_is_dm: + * @conversation: The instance. + * Checks if @conversation is a direct message or not. + * This is a quick helper around manually checking the results of + * [method@Conversation.get_conversation_type]. + * Returns: %TRUE if @conversation is a direct message, otherwise %FALSE. +gboolean purple_conversation_is_dm(PurpleConversation *conversation); + * purple_conversation_is_group_dm: + * @conversation: The instance. + * Checks if @conversation is a group direct message or not. + * This is a quick helper around manually checking the results of + * [method@Conversation.get_conversation_type]. + * Returns: %TRUE if @conversation is a group direct message, otherwise %FALSE. +gboolean purple_conversation_is_group_dm(PurpleConversation *conversation); + * purple_conversation_is_channel: + * @conversation: The instance. + * Checks if @conversation is a channel or not. + * This is a quick helper around manually checking the results of + * [method@Conversation.get_conversation_type]. + * Returns: %TRUE if @conversation is a channel, otherwise %FALSE. +gboolean purple_conversation_is_channel(PurpleConversation *conversation); + * purple_conversation_is_thread: + * @conversation: The instance. + * Checks if @conversation is a thread or not. + * This is a quick helper around manually checking the results of + * [method@Conversation.get_conversation_type]. + * Returns: %TRUE if @conversation is a thread, otherwise %FALSE. +gboolean purple_conversation_is_thread(PurpleConversation *conversation); * purple_conversation_present:
* @conv: The conversation to present
--- a/libpurple/tests/test_conversation.c Tue Apr 09 23:06:58 2024 -0500
+++ b/libpurple/tests/test_conversation.c Tue Apr 09 23:11:12 2024 -0500
@@ -203,6 +203,105 @@
/******************************************************************************
+ *****************************************************************************/ +test_purple_conversation_is_dm(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, + "name", "this is required for some reason", + g_assert_true(PURPLE_IS_CONVERSATION(conversation)); + g_assert_true(purple_conversation_is_dm(conversation)); + g_assert_false(purple_conversation_is_group_dm(conversation)); + g_assert_false(purple_conversation_is_channel(conversation)); + g_assert_false(purple_conversation_is_thread(conversation)); + g_assert_finalize_object(conversation); + g_clear_object(&account); +test_purple_conversation_is_group_dm(void) { + PurpleAccount *account = NULL; + PurpleConversation *conversation = NULL; + account = purple_account_new("test", "test"); + conversation = g_object_new( + PURPLE_TYPE_CONVERSATION, + "type", PURPLE_CONVERSATION_TYPE_GROUP_DM, + "name", "this is required for some reason", + g_assert_true(PURPLE_IS_CONVERSATION(conversation)); + g_assert_false(purple_conversation_is_dm(conversation)); + g_assert_true(purple_conversation_is_group_dm(conversation)); + g_assert_false(purple_conversation_is_channel(conversation)); + g_assert_false(purple_conversation_is_thread(conversation)); + g_assert_finalize_object(conversation); + g_clear_object(&account); +test_purple_conversation_is_channel(void) { + PurpleAccount *account = NULL; + PurpleConversation *conversation = NULL; + account = purple_account_new("test", "test"); + conversation = g_object_new( + PURPLE_TYPE_CONVERSATION, + "type", PURPLE_CONVERSATION_TYPE_CHANNEL, + "name", "this is required for some reason", + g_assert_true(PURPLE_IS_CONVERSATION(conversation)); + g_assert_false(purple_conversation_is_dm(conversation)); + g_assert_false(purple_conversation_is_group_dm(conversation)); + g_assert_true(purple_conversation_is_channel(conversation)); + g_assert_false(purple_conversation_is_thread(conversation)); + g_assert_finalize_object(conversation); + g_clear_object(&account); +test_purple_conversation_is_thread(void) { + PurpleAccount *account = NULL; + PurpleConversation *conversation = NULL; + account = purple_account_new("test", "test"); + conversation = g_object_new( + PURPLE_TYPE_CONVERSATION, + "type", PURPLE_CONVERSATION_TYPE_THREAD, + "name", "this is required for some reason", + g_assert_true(PURPLE_IS_CONVERSATION(conversation)); + g_assert_false(purple_conversation_is_dm(conversation)); + g_assert_false(purple_conversation_is_group_dm(conversation)); + g_assert_false(purple_conversation_is_channel(conversation)); + g_assert_true(purple_conversation_is_thread(conversation)); + g_assert_finalize_object(conversation); + g_clear_object(&account); +/****************************************************************************** * Membership tests and helpers
*****************************************************************************/
@@ -364,6 +463,14 @@
g_test_add_func("/conversation/set-topic-full",
test_purple_conversation_set_topic_full);
+ g_test_add_func("/conversation/is-dm", test_purple_conversation_is_dm); + g_test_add_func("/conversation/is-group-dm", + test_purple_conversation_is_group_dm); + g_test_add_func("/conversation/is-channel", + test_purple_conversation_is_channel); + g_test_add_func("/conversation/is-thread", + test_purple_conversation_is_thread); g_test_add_func("/conversation/members/add-remove",
test_purple_conversation_members_add_remove);