# HG changeset patch
# User Paul Aurich <paul@darkrain42.org>
# Date 1266280585 0
# Node ID d4b9df8e17f6da5e51e1f222a50fdb19b7cb5fb3
# Parent  0b6cfe040cd0452d47df3b906aa0fd433a6badc8
jabber: Fix another corner case that introduced duplicates to the list.

This occurs when the roster contains either two groups with the exact
same name or a name that differs only by case.  The solution: uniquify
the list of groups.  Fixes #10950.

diff -r 0b6cfe040cd0 -r d4b9df8e17f6 ChangeLog
--- a/ChangeLog	Mon Feb 15 19:16:38 2010 +0000
+++ b/ChangeLog	Tue Feb 16 00:36:25 2010 +0000
@@ -62,6 +62,9 @@
 	* The default value for the file transfer proxies is automatically
 	  updated when an account connects, if it is still the old (broken)
 	  default (from 'proxy.jabber.org' to 'proxy.eu.jabber.org').
+	* Fix an issue where libpurple created duplicate buddies if the roster
+	  contains a buddy in two groups that differ only by case
+	  (e.g. "XMPP" and "xmpp") (or not at all).
 
 	Yahoo:
 	* Don't send <span> and </span> tags.  (Fartash Faghri)
diff -r 0b6cfe040cd0 -r d4b9df8e17f6 libpurple/protocols/jabber/roster.c
--- a/libpurple/protocols/jabber/roster.c	Mon Feb 15 19:16:38 2010 +0000
+++ b/libpurple/protocols/jabber/roster.c	Tue Feb 16 00:36:25 2010 +0000
@@ -259,7 +259,16 @@
 					seen_empty = TRUE;
 				}
 
-				groups = g_slist_prepend(groups, group_name);
+				/*
+				 * See the note in add_purple_buddy_to_groups; the core handles
+				 * names case-insensitively and this is required to not
+				 * end up with duplicates if a buddy is in, e.g.,
+				 * 'XMPP' and 'xmpp'
+				 */
+				if (g_slist_find_custom(groups, group_name, (GCompareFunc)purple_utf8_strcasecmp))
+					g_free(group_name);
+				else
+					groups = g_slist_prepend(groups, group_name);
 			}
 
 			add_purple_buddy_to_groups(js, jid, name, groups);