pidgin/pidgin

Don't allow duplicate tags in PurpleTags

18 months ago, Gary Kramlich
9d2735c0e848
Parents f22da7f7845a
Children 55aaac83f315
Don't allow duplicate tags in PurpleTags

Originally I was thinking it might be useful to store counter objects in the
tags, but that adds a bunch of complexity to the serialization layer and tag
users can just get the existing tag, and then increment the value themselves.

Testing Done:
Ran the unit tests.

Reviewed at https://reviews.imfreedom.org/r/2053/
--- a/libpurple/purpletags.c Wed Nov 09 23:04:13 2022 -0600
+++ b/libpurple/purpletags.c Wed Nov 09 23:15:35 2022 -0600
@@ -119,6 +119,10 @@
g_return_if_fail(PURPLE_IS_TAGS(tags));
g_return_if_fail(tag != NULL);
+ /* Remove any existing tags with this value. */
+ purple_tags_remove(tags, tag);
+
+ /* Add the new tag. */
tags->tags = g_list_append(tags->tags, g_strdup(tag));
}
--- a/libpurple/purpletags.h Wed Nov 09 23:04:13 2022 -0600
+++ b/libpurple/purpletags.h Wed Nov 09 23:15:35 2022 -0600
@@ -95,7 +95,8 @@
* @tags: The instance.
* @tag: The tag data.
*
- * Adds @tag to @tags.
+ * Adds @tag to @tags. If the tag already exists, the existing tag will be
+ * replaced.
*
* Since: 3.0.0
*/
--- a/libpurple/tests/test_tags.c Wed Nov 09 23:04:13 2022 -0600
+++ b/libpurple/tests/test_tags.c Wed Nov 09 23:15:35 2022 -0600
@@ -86,7 +86,7 @@
g_assert_cmpuint(purple_tags_get_count(tags), ==, 1);
purple_tags_add(tags, "tag1");
- g_assert_cmpuint(purple_tags_get_count(tags), ==, 2);
+ g_assert_cmpuint(purple_tags_get_count(tags), ==, 1);
g_clear_object(&tags);
}
@@ -122,7 +122,7 @@
g_assert_cmpuint(purple_tags_get_count(tags), ==, 1);
purple_tags_add(tags, "tag1:purple");
- g_assert_cmpuint(purple_tags_get_count(tags), ==, 2);
+ g_assert_cmpuint(purple_tags_get_count(tags), ==, 1);
g_clear_object(&tags);
}