changeset 7972:ac01b7d67ff9

[gaim-migrate @ 8649] yay, /nick for jabber i'll be really happy if marv finishes /command support for the core soon ;-) committer: Tailor Script <tailor@pidgin.im>
author Nathan Walp <nwalp@pidgin.im>
date Fri, 02 Jan 2004 07:34:26 +0000
parents 6fca0d9cc98b
children aa99b8390092
files src/protocols/jabber/chat.c src/protocols/jabber/chat.h src/protocols/jabber/message.c src/protocols/jabber/presence.c
diffstat 4 files changed, 63 insertions(+), 6 deletions(-) [+]
line wrap: on
line diff
--- a/src/protocols/jabber/chat.c	Fri Jan 02 06:16:44 2004 +0000
+++ b/src/protocols/jabber/chat.c	Fri Jan 02 07:34:26 2004 +0000
@@ -571,3 +571,25 @@
 }
 
 
+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);
+}
+
+
--- a/src/protocols/jabber/chat.h	Fri Jan 02 06:16:44 2004 +0000
+++ b/src/protocols/jabber/chat.h	Fri Jan 02 07:34:26 2004 +0000
@@ -56,6 +56,7 @@
 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_ */
--- a/src/protocols/jabber/message.c	Fri Jan 02 06:16:44 2004 +0000
+++ b/src/protocols/jabber/message.c	Fri Jan 02 07:34:26 2004 +0000
@@ -499,6 +499,10 @@
 	} 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);
--- a/src/protocols/jabber/presence.c	Fri Jan 02 06:16:44 2004 +0000
+++ b/src/protocols/jabber/presence.c	Fri Jan 02 07:34:26 2004 +0000
@@ -308,12 +308,42 @@
 		}
 
 		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))