cpw.darkrain42.roster: d0917299: Various roster cleanups. Refs #7008.
darkrain42 at pidgin.im
darkrain42 at pidgin.im
Sat Jun 6 20:20:30 EDT 2009
-----------------------------------------------------------------
Revision: d091729988805684afa360dc1f96ed46cd10e080
Ancestor: 42b26858f379ef210c6754854bfdc0969ab9ebfd
Author: darkrain42 at pidgin.im
Date: 2009-06-07T00:16:05
Branch: im.pidgin.cpw.darkrain42.roster
URL: http://d.pidgin.im/viewmtn/revision/info/d091729988805684afa360dc1f96ed46cd10e080
Modified files:
libpurple/protocols/jabber/google.c
libpurple/protocols/jabber/roster.c
ChangeLog:
Various roster cleanups. Refs #7008.
I haven't tested it, but this may resolve the grouping/case problem (strcmp => purple_utf8_strcasecmp)
-------------- next part --------------
============================================================
--- libpurple/protocols/jabber/google.c 02aced3c4f07414bd17762acd50cc7c09e419456
+++ libpurple/protocols/jabber/google.c 8448e48824ec9d3fb213a15f8f1cb17aa7316682
@@ -987,7 +987,6 @@ gboolean jabber_google_roster_incoming(J
gboolean jabber_google_roster_incoming(JabberStream *js, xmlnode *item)
{
PurpleAccount *account = purple_connection_get_account(js->gc);
- GSList *list = account->deny;
const char *jid = xmlnode_get_attrib(item, "jid");
gboolean on_block_list = FALSE;
@@ -1005,18 +1004,20 @@ gboolean jabber_google_roster_incoming(J
jid_norm = g_strdup(jabber_normalize(account, jid));
- while (list) {
- if (!strcmp(jid_norm, (char*)list->data)) {
- on_block_list = TRUE;
- break;
- }
- list = list->next;
- }
+ on_block_list = NULL != g_slist_find_custom(account->deny, jid_norm,
+ (GCompareFunc)strcmp);
if (grt && (*grt == 'H' || *grt == 'h')) {
- PurpleBuddy *buddy = purple_find_buddy(account, jid_norm);
- if (buddy)
- purple_blist_remove_buddy(buddy);
+ /* Hidden; don't show this buddy. */
+ GSList *buddies = purple_find_buddies(account, jid_norm);
+ if (buddies)
+ purple_debug_info("jabber", "Removing %s from local buddy list\n",
+ jid_norm);
+
+ for ( ; buddies; buddies = g_slist_delete_link(buddies, buddies)) {
+ purple_blist_remove_buddy(buddies->data);
+ }
+
g_free(jid_norm);
return FALSE;
}
============================================================
--- libpurple/protocols/jabber/roster.c ae789d5498723948729f1fe1de8e66b72d21f4ba
+++ libpurple/protocols/jabber/roster.c 7e18333bfd21f177232eb51d613dc941f93cbb6f
@@ -52,21 +52,23 @@ static void remove_purple_buddies(Jabber
g_slist_free(buddies);
}
-static void add_purple_buddies_to_groups(JabberStream *js, const char *jid,
+static void add_purple_buddy_to_groups(JabberStream *js, const char *jid,
const char *alias, GSList *groups)
{
- GSList *buddies, *g2, *l;
+ GSList *buddies, *l;
gchar *my_bare_jid;
GList *pool = NULL;
buddies = purple_find_buddies(js->gc->account, jid);
- g2 = groups;
-
if(!groups) {
if(!buddies)
- g2 = g_slist_append(g2, g_strdup(_("Buddies")));
+ groups = g_slist_append(groups, g_strdup(_("Buddies")));
else {
+ /* TODO: What should we do here? Removing the local buddies
+ * is wrong, but so is letting the group state get out of sync with
+ * the server.
+ */
g_slist_free(buddies);
return;
}
@@ -78,9 +80,15 @@ static void add_purple_buddies_to_groups
PurpleBuddy *b = buddies->data;
PurpleGroup *g = purple_buddy_get_group(b);
- buddies = g_slist_remove(buddies, b);
+ buddies = g_slist_delete_link(buddies, buddies);
- if((l = g_slist_find_custom(g2, purple_group_get_name(g), (GCompareFunc)strcmp))) {
+ /* XMPP groups are case-sensitive, but libpurple groups are
+ * case-insensitive. We treat a buddy in both "Friends" and "friends"
+ * as only being in one group, so if we push changes about the buddy
+ * to the server, the buddy will be dropped from one of the groups.
+ */
+ if((l = g_slist_find_custom(groups, purple_group_get_name(g), (GCompareFunc)purple_utf8_strcasecmp))) {
+ /* The buddy is already on the local list. Update info. */
const char *servernick, *balias;
/* Previously stored serverside / buddy-supplied alias */
@@ -89,19 +97,23 @@ static void add_purple_buddies_to_groups
/* Alias from our roster retrieval */
balias = purple_buddy_get_local_buddy_alias(b);
- if(alias && (!balias || strcmp(balias, alias)))
+ if(alias && !purple_strequal(alias, balias))
purple_serv_got_private_alias(js->gc, jid, alias);
g_free(l->data);
- g2 = g_slist_delete_link(g2, l);
+ groups = g_slist_delete_link(groups, l);
} else {
+ /* This buddy isn't in the group on the server anymore */
pool = g_list_prepend(pool, b);
}
}
- while(g2) {
- PurpleGroup *g = purple_find_group(g2->data);
+ while(groups) {
+ PurpleGroup *g = purple_find_group(groups->data);
PurpleBuddy *b = NULL;
+ /* If there are buddies we would otherwise delete, move them to
+ * the new group (instead of deleting them below)
+ */
if (pool) {
b = pool->data;
pool = g_list_delete_link(pool, pool);
@@ -110,7 +122,7 @@ static void add_purple_buddies_to_groups
}
if(!g) {
- g = purple_group_new(g2->data);
+ g = purple_group_new(groups->data);
purple_blist_add_group(g, NULL);
}
@@ -131,10 +143,12 @@ static void add_purple_buddies_to_groups
jabber_presence_fake_to_self(js, status);
}
- g_free(g2->data);
- g2 = g_slist_delete_link(g2, g2);
+ g_free(groups->data);
+ groups = g_slist_delete_link(groups, groups);
}
+ /* Remove this person from all the groups they're no longer in on the
+ * server */
while (pool) {
PurpleBuddy *b = pool->data;
purple_blist_remove_buddy(b);
@@ -205,23 +219,24 @@ void jabber_roster_parse(JabberStream *j
remove_purple_buddies(js, jid);
} else {
GSList *groups = NULL;
+ gboolean seen_empty = FALSE;
if (js->server_caps & JABBER_CAP_GOOGLE_ROSTER)
if (!jabber_google_roster_incoming(js, item))
continue;
for(group = xmlnode_get_child(item, "group"); group; group = xmlnode_get_next_twin(group)) {
- char *group_name;
+ char *group_name = xmlnode_get_data(group);
- if(!(group_name = xmlnode_get_data(group)))
+ if (!group_name && !seen_empty) {
group_name = g_strdup("");
+ seen_empty = TRUE;
+ }
- if (g_slist_find_custom(groups, group_name, (GCompareFunc)purple_utf8_strcasecmp) == NULL)
- groups = g_slist_append(groups, group_name);
- else
- g_free(group_name);
+ groups = g_slist_prepend(groups, group_name);
}
- add_purple_buddies_to_groups(js, jid, name, groups);
+
+ add_purple_buddy_to_groups(js, jid, name, groups);
}
}
More information about the Commits
mailing list