Mon, 21 Apr 2025 22:43:29 -0500
Add Purple.Conversation:url
Some networks allow you to specify a URL that's related to a conversation.
This property allows us to store that.
Testing Done:
Ran the tests under valgrind and called in the turtles.
Bugs closed: PIDGIN-18091
Reviewed at https://reviews.imfreedom.org/r/3974/
--- a/libpurple/purpleconversation.c Thu Apr 17 23:35:53 2025 -0500 +++ b/libpurple/purpleconversation.c Mon Apr 21 22:43:29 2025 -0500 @@ -81,6 +81,8 @@ gboolean drafting; GError *error; + + char *url; }; enum { @@ -117,6 +119,7 @@ PROP_LOGGING, PROP_DRAFTING, PROP_ERROR, + PROP_URL, N_PROPERTIES, }; static GParamSpec *properties[N_PROPERTIES] = {NULL, }; @@ -603,6 +606,9 @@ purple_conversation_set_drafting(conversation, g_value_get_boolean(value)); break; + case PROP_URL: + purple_conversation_set_url(conversation, g_value_get_string(value)); + break; case PROP_ERROR: purple_conversation_set_error(conversation, g_value_get_boxed(value)); break; @@ -741,6 +747,9 @@ case PROP_ERROR: g_value_set_boxed(value, purple_conversation_get_error(conversation)); break; + case PROP_URL: + g_value_set_string(value, purple_conversation_get_url(conversation)); + break; default: G_OBJECT_WARN_INVALID_PROPERTY_ID(obj, param_id, pspec); break; @@ -817,6 +826,8 @@ g_clear_error(&conversation->error); + g_clear_pointer(&conversation->url, g_free); + G_OBJECT_CLASS(purple_conversation_parent_class)->finalize(object); } @@ -1335,6 +1346,23 @@ G_TYPE_ERROR, G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS); + /** + * PurpleConversation:url: + * + * A URL related to the conversation. + * + * Some networks, notably IRC, allow you to associate a URL with a + * conversation. In that case, it is generally a URL to get more + * information about the conversation and not a URL to the conversation + * itself. + * + * Since: 3.0 + */ + properties[PROP_URL] = g_param_spec_string( + "url", NULL, NULL, + NULL, + G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS); + g_object_class_install_properties(obj_class, N_PROPERTIES, properties); /** @@ -2266,3 +2294,20 @@ return member; } + +const char * +purple_conversation_get_url(PurpleConversation *conversation) { + g_return_val_if_fail(PURPLE_IS_CONVERSATION(conversation), NULL); + + return conversation->url; +} + +void +purple_conversation_set_url(PurpleConversation *conversation, const char *url) +{ + g_return_if_fail(PURPLE_IS_CONVERSATION(conversation)); + + if(g_set_str(&conversation->url, url)) { + g_object_notify_by_pspec(G_OBJECT(conversation), properties[PROP_URL]); + } +}
--- a/libpurple/purpleconversation.h Thu Apr 17 23:35:53 2025 -0500 +++ b/libpurple/purpleconversation.h Mon Apr 21 22:43:29 2025 -0500 @@ -1042,6 +1042,29 @@ PURPLE_AVAILABLE_IN_3_0 PurpleConversationMember *purple_conversation_find_or_add_member(PurpleConversation *conversation, PurpleContactInfo *info, gboolean announce, const char *message); +/** + * purple_conversation_get_url: + * + * Gets the URL associated with the conversation. + * + * Returns: (nullable): The URL for the conversation. + * + * Since: 3.0 + */ +PURPLE_AVAILABLE_IN_3_0 +const char *purple_conversation_get_url(PurpleConversation *conversation); + +/** + * purple_conversation_set_url: + * @url: (nullable): the new URL + * + * Sets the URL for the conversation. + * + * Since: 3.0 + */ +PURPLE_AVAILABLE_IN_3_0 +void purple_conversation_set_url(PurpleConversation *conversation, const char *url); + G_END_DECLS #endif /* PURPLE_CONVERSATION_H */
--- a/libpurple/tests/test_conversation.c Thu Apr 17 23:35:53 2025 -0500 +++ b/libpurple/tests/test_conversation.c Mon Apr 21 22:43:29 2025 -0500 @@ -68,6 +68,7 @@ char *title = NULL; char *title_for_display = NULL; char *topic = NULL; + char *url = NULL; char *user_nickname = NULL; gboolean age_restricted = FALSE; gboolean avatar_editable = FALSE; @@ -122,6 +123,7 @@ "topic-updated", topic_updated, "type", PURPLE_CONVERSATION_TYPE_THREAD, "typing-state", PURPLE_TYPING_STATE_TYPING, + "url", "https://pidgin.im/", "user-nickname", "knick-knack", NULL); @@ -154,6 +156,7 @@ "topic-updated", &topic_updated1, "type", &type, "typing-state", &typing_state, + "url", &url, "user-nickname", &user_nickname, NULL); @@ -232,6 +235,9 @@ g_assert_cmpuint(typing_state, ==, PURPLE_TYPING_STATE_TYPING); + g_assert_cmpstr(url, ==, "https://pidgin.im/"); + g_clear_pointer(&url, g_free); + g_assert_cmpstr(user_nickname, ==, "knick-knack"); g_clear_pointer(&user_nickname, g_free);