Tue, 05 Sep 2023 00:43:49 -0500
Add PurpleConversationType
This is mostly meant to be used by the protocols and maybe the user interfaces
to do things they might need to do. Internally to libpurple this is basically
ignored.
Testing Done:
Ran the unit tests.
Reviewed at https://reviews.imfreedom.org/r/2599/
--- a/libpurple/purpleconversation.c Tue Sep 05 00:22:03 2023 -0500 +++ b/libpurple/purpleconversation.c Tue Sep 05 00:43:49 2023 -0500 @@ -33,6 +33,7 @@ typedef struct { char *id; + PurpleConversationType type; PurpleAccount *account; char *name; @@ -60,6 +61,7 @@ enum { PROP_0, PROP_ID, + PROP_TYPE, PROP_ACCOUNT, PROP_NAME, PROP_TITLE, @@ -275,6 +277,9 @@ case PROP_ID: purple_conversation_set_id(conv, g_value_get_string(value)); break; + case PROP_TYPE: + purple_conversation_set_conversation_type(conv, g_value_get_enum(value)); + break; case PROP_ACCOUNT: purple_conversation_set_account(conv, g_value_get_object(value)); break; @@ -336,6 +341,10 @@ case PROP_ID: g_value_set_string(value, purple_conversation_get_id(conv)); break; + case PROP_TYPE: + g_value_set_enum(value, + purple_conversation_get_conversation_type(conv)); + break; case PROP_ACCOUNT: g_value_set_object(value, purple_conversation_get_account(conv)); break; @@ -509,7 +518,7 @@ obj_class->set_property = purple_conversation_set_property; /** - * PurpleConversation::id: + * PurpleConversation:id: * * An opaque identifier for this conversation. Generally speaking this is * protocol dependent and should only be used as a unique identifier. @@ -522,6 +531,21 @@ NULL, G_PARAM_READWRITE | G_PARAM_CONSTRUCT_ONLY | G_PARAM_STATIC_STRINGS); + /** + * PurpleConversation:type: + * + * A type hint for the conversation. This may be useful for protocols, but + * libpurple treats all conversations the same. + * + * Since: 3.0.0 + */ + properties[PROP_TYPE] = g_param_spec_enum( + "type", "type", + "The type of the conversation.", + PURPLE_TYPE_CONVERSATION_TYPE, + PurpleConversationTypeUnset, + G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS); + properties[PROP_ACCOUNT] = g_param_spec_object( "account", "Account", "The account for the conversation.", @@ -863,6 +887,36 @@ return priv->id; } +PurpleConversationType +purple_conversation_get_conversation_type(PurpleConversation *conversation) { + PurpleConversationPrivate *priv = NULL; + + g_return_val_if_fail(PURPLE_IS_CONVERSATION(conversation), + PurpleConversationTypeUnset); + + priv = purple_conversation_get_instance_private(conversation); + + return priv->type; +} + +void +purple_conversation_set_conversation_type(PurpleConversation *conversation, + PurpleConversationType type) +{ + PurpleConversationPrivate *priv = NULL; + + g_return_if_fail(PURPLE_IS_CONVERSATION(conversation)); + + priv = purple_conversation_get_instance_private(conversation); + + if(type != priv->type) { + priv->type = type; + + g_object_notify_by_pspec(G_OBJECT(conversation), + properties[PROP_TYPE]); + } +} + void purple_conversation_set_account(PurpleConversation *conv, PurpleAccount *account)
--- a/libpurple/purpleconversation.h Tue Sep 05 00:22:03 2023 -0500 +++ b/libpurple/purpleconversation.h Tue Sep 05 00:43:49 2023 -0500 @@ -86,6 +86,33 @@ } PurpleConversationUpdateType; /** + * PurpleConversationType: + * @PurpleConversationTypeUnset: A value to specify that the property has not + * been set. + * @PurpleConversationTypeDM: A direct message between two contacts. + * @PurpleConversationTypeGroupDM: A direct message between a protocol + * dependent number of contacts. + * @PurpleConversationTypeChannel: A multi-user chat that is available to all + * users on the protocol and has features like + * moderation. + * @PurpleConversationTypeThread: A thread is a subset of messages from a + * conversation that are related. + * + * The type of the conversation. This is mostly ignored, but could be useful in + * ways we can't imagine right now. If you come up with one in the future, + * please let us know! + * + * Since: 3.0.0 + */ +typedef enum { + PurpleConversationTypeUnset, + PurpleConversationTypeDM, + PurpleConversationTypeGroupDM, + PurpleConversationTypeChannel, + PurpleConversationTypeThread, +} PurpleConversationType; + +/** * PurpleConversation: * * A core representation of a conversation between two or more people. @@ -163,6 +190,32 @@ const char *purple_conversation_get_id(PurpleConversation *conversation); /** + * purple_conversation_get_conversation_type: + * @conversation: The instance. + * + * Gets the type of @conversation. + * + * Returns: The [enum@ConversationType] of @conversation. + * + * Since: 3.0.0. + */ +PurpleConversationType purple_conversation_get_conversation_type(PurpleConversation *conversation); + +/** + * purple_conversation_set_conversation_type: + * @conversation: The instance. + * @type: The new type. + * + * Sets the type of @conversation to @type. + * + * > Note this only for the internal representation in libpurple and the + * protocol will not be told to change the type. + * + * Since: 3.0.0 + */ +void purple_conversation_set_conversation_type(PurpleConversation *conversation, PurpleConversationType type); + +/** * purple_conversation_set_account: * @conv: The conversation. * @account: The purple_account.
--- a/libpurple/tests/test_conversation.c Tue Sep 05 00:22:03 2023 -0500 +++ b/libpurple/tests/test_conversation.c Tue Sep 05 00:43:49 2023 -0500 @@ -36,6 +36,7 @@ PurpleContactInfo *topic_author1 = NULL; PurpleConversation *conversation = NULL; PurpleConversationManager *conversation_manager = NULL; + PurpleConversationType type = PurpleConversationTypeUnset; PurpleTags *tags = NULL; GDateTime *created_on = NULL; GDateTime *created_on1 = NULL; @@ -78,6 +79,7 @@ "topic", "the topic...", "topic-author", topic_author, "topic-updated", topic_updated, + "type", PurpleConversationTypeThread, "user-nickname", "knick-knack", NULL); @@ -97,6 +99,7 @@ "topic", &topic, "topic-author", &topic_author1, "topic-updated", &topic_updated1, + "type", &type, "user-nickname", &user_nickname, NULL); @@ -142,6 +145,8 @@ g_assert_true(g_date_time_equal(topic_updated1, topic_updated)); g_clear_pointer(&topic_updated1, g_date_time_unref); + g_assert_cmpuint(type, ==, PurpleConversationTypeThread); + g_assert_cmpstr(user_nickname, ==, "knick-knack"); g_clear_pointer(&user_nickname, g_free);