Thu, 17 Apr 2025 23:33:42 -0500
Add Purple.ContactInfo:external for tracking external contacts
Testing Done:
Ran the tests under valgrind and called in the turtles.
Bugs closed: PIDGIN-18090
Reviewed at https://reviews.imfreedom.org/r/3973/
--- a/libpurple/purplecontactinfo.c Thu Apr 17 23:29:23 2025 -0500 +++ b/libpurple/purplecontactinfo.c Thu Apr 17 23:33:42 2025 -0500 @@ -38,6 +38,7 @@ char *note; char *sid; gboolean favorite; + gboolean external; char *name_for_display; @@ -71,6 +72,7 @@ PROP_SID, PROP_FAVORITE, PROP_NAME_FOR_DISPLAY, + PROP_EXTERNAL, N_PROPERTIES, }; static GParamSpec *properties[N_PROPERTIES] = {NULL, }; @@ -220,6 +222,9 @@ case PROP_FAVORITE: g_value_set_boolean(value, purple_contact_info_get_favorite(info)); break; + case PROP_EXTERNAL: + g_value_set_boolean(value, purple_contact_info_get_external(info)); + break; default: G_OBJECT_WARN_INVALID_PROPERTY_ID(obj, param_id, pspec); break; @@ -277,6 +282,9 @@ case PROP_FAVORITE: purple_contact_info_set_favorite(info, g_value_get_boolean(value)); break; + case PROP_EXTERNAL: + purple_contact_info_set_external(info, g_value_get_boolean(value)); + break; default: G_OBJECT_WARN_INVALID_PROPERTY_ID(obj, param_id, pspec); break; @@ -597,6 +605,22 @@ NULL, G_PARAM_READABLE | G_PARAM_STATIC_STRINGS); + /** + * PurpleContactInfo:external: + * + * Whether or not the contact is an external contact. + * + * Some chat networks like Microsoft Teams and Slack have a concept of + * external contacts that are not members of the organization but can + * access some portion of the network. This flag represents that. + * + * Since: 3.0 + */ + properties[PROP_EXTERNAL] = g_param_spec_boolean( + "external", NULL, NULL, + FALSE, + G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS); + g_object_class_install_properties(obj_class, N_PROPERTIES, properties); /** @@ -1184,3 +1208,28 @@ return menu; } + +gboolean +purple_contact_info_get_external(PurpleContactInfo *info) { + PurpleContactInfoPrivate *priv = NULL; + + g_return_val_if_fail(PURPLE_IS_CONTACT_INFO(info), FALSE); + + priv = purple_contact_info_get_instance_private(info); + + return priv->external; +} + +void +purple_contact_info_set_external(PurpleContactInfo *info, gboolean external) { + PurpleContactInfoPrivate *priv = NULL; + + g_return_if_fail(PURPLE_IS_CONTACT_INFO(info)); + + priv = purple_contact_info_get_instance_private(info); + if(priv->external != external) { + priv->external = external; + + g_object_notify_by_pspec(G_OBJECT(info), properties[PROP_EXTERNAL]); + } +}
--- a/libpurple/purplecontactinfo.h Thu Apr 17 23:29:23 2025 -0500 +++ b/libpurple/purplecontactinfo.h Thu Apr 17 23:33:42 2025 -0500 @@ -580,6 +580,29 @@ PURPLE_AVAILABLE_IN_3_0 BirbActionMenu *purple_contact_info_get_menu(PurpleContactInfo *info); +/** + * purple_contact_info_get_external: + * + * Gets whether or not the contact is an external contact. + * + * Returns: true if the contact is external to the network. + * + * Since: 3.0 + */ +PURPLE_AVAILABLE_IN_3_0 +gboolean purple_contact_info_get_external(PurpleContactInfo *info); + +/** + * purple_contact_info_set_external: + * @external: true to make the contact info as external + * + * Sets whether or not the contact is considered external. + * + * Since: 3.0 + */ +PURPLE_AVAILABLE_IN_3_0 +void purple_contact_info_set_external(PurpleContactInfo *info, gboolean external); + G_END_DECLS #endif /* PURPLE_CONTACT_INFO_H */
--- a/libpurple/tests/test_contact_info.c Thu Apr 17 23:29:23 2025 -0500 +++ b/libpurple/tests/test_contact_info.c Thu Apr 17 23:33:42 2025 -0500 @@ -58,6 +58,7 @@ char *note = NULL; char *sid = NULL; char *name_for_display = NULL; + gboolean external = FALSE; gboolean favorite = FALSE; avatar = g_object_new(PURPLE_TYPE_AVATAR, NULL); @@ -85,6 +86,7 @@ "permission", PURPLE_CONTACT_INFO_PERMISSION_ALLOW, "sid", "sid", "favorite", TRUE, + "external", TRUE, NULL); /* Now use g_object_get to read all of the properties. */ @@ -106,6 +108,7 @@ "sid", &sid, "name-for-display", &name_for_display, "favorite", &favorite, + "external", &external, NULL); /* Compare all the things. */ @@ -127,6 +130,7 @@ g_assert_true(permission == PURPLE_CONTACT_INFO_PERMISSION_ALLOW); g_assert_cmpstr(sid, ==, "sid"); g_assert_true(favorite); + g_assert_true(external); /* Free/unref all the things. */ g_clear_pointer(&id, g_free);