changeset 26780:5c4a4a0f5929

When we download a buddy's vCard to update an avatar, also try to update the nickname.
author Paul Aurich <paul@darkrain42.org>
date Sat, 02 May 2009 20:42:55 +0000
parents d387f1164b3a
children 0c1983abe991
files libpurple/protocols/jabber/presence.c
diffstat 1 files changed, 24 insertions(+), 1 deletions(-) [+]
line wrap: on
line diff
--- a/libpurple/protocols/jabber/presence.c	Sat May 02 19:14:07 2009 +0000
+++ b/libpurple/protocols/jabber/presence.c	Sat May 02 20:42:55 2009 +0000
@@ -340,7 +340,7 @@
                           xmlnode *packet, gpointer blah)
 {
 	JabberBuddy *jb = NULL;
-	xmlnode *vcard, *photo, *binval;
+	xmlnode *vcard, *photo, *binval, *fn, *nick;
 	char *text;
 
 	if(!from)
@@ -352,6 +352,29 @@
 
 	if((vcard = xmlnode_get_child(packet, "vCard")) ||
 			(vcard = xmlnode_get_child_with_namespace(packet, "query", "vcard-temp"))) {
+		/* The logic here regarding the nickname and full name is copied from
+		 * buddy.c:jabber_vcard_parse. */
+		gchar *nickname = NULL;
+		if ((fn = xmlnode_get_child(vcard, "FN")))
+			nickname = xmlnode_get_data(fn);
+
+		if ((nick = xmlnode_get_child(vcard, "NICKNAME"))) {
+			char *tmp = xmlnode_get_data(nick);
+			char *bare_jid = jabber_get_bare_jid(from);
+			if (strstr(bare_jid, tmp) == NULL) {
+				g_free(nickname);
+				nickname = tmp;
+			} else
+				g_free(tmp);
+
+			g_free(bare_jid);
+		}
+
+		if (nickname) {
+			serv_got_alias(js->gc, from, nickname);
+			g_free(nickname);
+		}
+
 		if((photo = xmlnode_get_child(vcard, "PHOTO")) &&
 				(( (binval = xmlnode_get_child(photo, "BINVAL")) &&
 				(text = xmlnode_get_data(binval))) ||