From: Nathan W. <fac...@us...> - 2004-01-02 07:34:31
|
Update of /cvsroot/gaim/gaim/src/protocols/jabber In directory sc8-pr-cvs1:/tmp/cvs-serv16283/src/protocols/jabber Modified Files: chat.c chat.h message.c presence.c Log Message: yay, /nick for jabber i'll be really happy if marv finishes /command support for the core soon ;-) Index: chat.c =================================================================== RCS file: /cvsroot/gaim/gaim/src/protocols/jabber/chat.c,v retrieving revision 1.16 retrieving revision 1.17 diff -u -d -p -r1.16 -r1.17 --- chat.c 2 Jan 2004 06:16:44 -0000 1.16 +++ chat.c 2 Jan 2004 07:34:26 -0000 1.17 @@ -571,3 +571,25 @@ void jabber_chat_set_topic(GaimConnectio } +void jabber_chat_change_nick(JabberChat *chat, const char *nick) +{ + xmlnode *presence; + char *full_jid; + + if(!chat->muc) { + gaim_conv_chat_write(GAIM_CONV_CHAT(chat->conv), "", + _("Nick changing not supported in non-MUC chatrooms"), + GAIM_MESSAGE_SYSTEM, time(NULL)); + return; + } + + presence = jabber_presence_create(chat->js->gc->away_state, chat->js->gc->away); + full_jid = g_strdup_printf("%s@%s/%s", chat->room, chat->server, nick); + xmlnode_set_attrib(presence, "to", full_jid); + g_free(full_jid); + + jabber_send(chat->js, presence); + xmlnode_free(presence); +} + + Index: chat.h =================================================================== RCS file: /cvsroot/gaim/gaim/src/protocols/jabber/chat.h,v retrieving revision 1.7 retrieving revision 1.8 diff -u -d -p -r1.7 -r1.8 --- chat.h 2 Jan 2004 06:16:44 -0000 1.7 +++ chat.h 2 Jan 2004 07:34:26 -0000 1.8 @@ -56,6 +56,7 @@ void jabber_chat_create_instant_room(Jab void jabber_chat_register(JabberChat *chat); void jabber_chat_change_topic(JabberChat *chat, const char *topic); void jabber_chat_set_topic(GaimConnection *gc, int id, const char *topic); +void jabber_chat_change_nick(JabberChat *chat, const char *nick); #endif /* _GAIM_JABBER_CHAT_H_ */ Index: message.c =================================================================== RCS file: /cvsroot/gaim/gaim/src/protocols/jabber/message.c,v retrieving revision 1.26 retrieving revision 1.27 diff -u -d -p -r1.26 -r1.27 --- message.c 2 Jan 2004 06:16:44 -0000 1.26 +++ message.c 2 Jan 2004 07:34:26 -0000 1.27 @@ -499,6 +499,10 @@ int jabber_message_send_chat(GaimConnect } else if(!strncmp(msg, "/topic", 6)) { jabber_chat_change_topic(chat, strlen(msg) > 7 ? msg+7 : NULL); return 1; + } else if(!strncmp(msg, "/nick", 5)) { + if(strlen(msg) > 6) + jabber_chat_change_nick(chat, msg+6); + return 1; } jm = g_new0(JabberMessage, 1); Index: presence.c =================================================================== RCS file: /cvsroot/gaim/gaim/src/protocols/jabber/presence.c,v retrieving revision 1.29 retrieving revision 1.30 diff -u -d -p -r1.29 -r1.30 --- presence.c 31 Dec 2003 08:22:55 -0000 1.29 +++ presence.c 2 Jan 2004 07:34:26 -0000 1.30 @@ -308,12 +308,42 @@ void jabber_presence_parse(JabberStream } if(type && !strcmp(type, "unavailable")) { - if(!strcmp(jid->resource, chat->nick)) { - serv_got_chat_left(js->gc, chat->id); - jabber_chat_destroy(chat); - } else { - gaim_conv_chat_remove_user(GAIM_CONV_CHAT(chat->conv), jid->resource, - NULL); + gboolean nick_change = FALSE; + if(chat->muc) { + xmlnode *x; + for(x = packet->child; x; x = x->next) { + const char *xmlns, *nick, *code; + xmlnode *stat, *item; + if(strcmp(x->name, "x")) + continue; + if(!(xmlns = xmlnode_get_attrib(x, "xmlns")) || + strcmp(xmlns, "http://jabber.org/protocol/muc#user")) + continue; + if(!(stat = xmlnode_get_child(x, "status"))) + continue; + if(!(code = xmlnode_get_attrib(stat, "code")) || strcmp(code, "303")) + continue; + if(!(item = xmlnode_get_child(x, "item"))) + continue; + if(!(nick = xmlnode_get_attrib(item, "nick"))) + continue; + nick_change = TRUE; + gaim_conv_chat_rename_user(GAIM_CONV_CHAT(chat->conv), jid->resource, nick); + if(!g_utf8_collate(jid->resource, chat->nick)) { + g_free(chat->nick); + chat->nick = g_strdup(nick); + } + break; + } + } + if(!nick_change) { + if(!strcmp(jid->resource, chat->nick)) { + serv_got_chat_left(js->gc, chat->id); + jabber_chat_destroy(chat); + } else { + gaim_conv_chat_remove_user(GAIM_CONV_CHAT(chat->conv), jid->resource, + NULL); + } } } else { if(!jabber_chat_find_buddy(chat->conv, jid->resource)) |