soc.2009.transport: de0ce8b6: Leave chat after unavailable presence

hanzz at soc.pidgin.im hanzz at soc.pidgin.im
Thu Jun 11 05:05:22 EDT 2009


-----------------------------------------------------------------
Revision: de0ce8b66d50015cd194d658359e28b8c924a84b
Ancestor: 5a34f69b622b868539e1dd2d634291590b43572a
Author: hanzz at soc.pidgin.im
Date: 2009-06-11T09:03:33
Branch: im.pidgin.soc.2009.transport
URL: http://d.pidgin.im/viewmtn/revision/info/de0ce8b66d50015cd194d658359e28b8c924a84b

Modified files:
        muchandler.cpp muchandler.h user.cpp

ChangeLog: 

Leave chat after unavailable presence

-------------- next part --------------
============================================================
--- muchandler.cpp	a77a9e591a86e7fc6be2baf6c7b7c81b04bd68b6
+++ muchandler.cpp	34210982423a7462996cc160202c88d3b2fc5f1a
@@ -26,6 +26,7 @@ MUCHandler::MUCHandler(User *user, const
 	m_user = user;
 	m_jid = jid;
 	m_userJid = userJid;
+	m_connected = false;
 }
 	
 MUCHandler::~MUCHandler() {}
@@ -35,18 +36,24 @@ Tag * MUCHandler::handlePresence(const P
 // 	tag.setFrom(p->jid());
 
 // 	return tag.tag();
-	GHashTable *comps = NULL;
-	std::string name = stanza.to().username();
-	PurpleConnection *gc = purple_account_get_connection(m_user->account());
-	if (PURPLE_PLUGIN_PROTOCOL_INFO(gc->prpl)->chat_info_defaults != NULL)
-		comps = PURPLE_PLUGIN_PROTOCOL_INFO(gc->prpl)->chat_info_defaults(gc, name.c_str());
-	if (comps) {
-		serv_join_chat(gc, comps);
+	if (stanza.presence() != Presence::Unavailable) {
+		GHashTable *comps = NULL;
+		std::string name = stanza.to().username();
+		PurpleConnection *gc = purple_account_get_connection(m_user->account());
+		if (PURPLE_PLUGIN_PROTOCOL_INFO(gc->prpl)->chat_info_defaults != NULL)
+			comps = PURPLE_PLUGIN_PROTOCOL_INFO(gc->prpl)->chat_info_defaults(gc, name.c_str());
+		if (comps) {
+			serv_join_chat(gc, comps);
+		}
 	}
+	else if (m_connected) {
+		purple_conversation_destroy(m_conv);
+	}
 	return NULL;
 }
 
 void MUCHandler::addUsers(GList *cbuddies) {
+	m_connected = true;
 	GList *l = cbuddies;
 	while (l != NULL) {
 		PurpleConvChatBuddy *cb = (PurpleConvChatBuddy *)l->data;
============================================================
--- muchandler.h	549406e9de603c1d05b2885da2448bb717b4ed22
+++ muchandler.h	7745f53b1ea9736903295b3dc5905955e6255336
@@ -41,11 +41,15 @@ class MUCHandler
 		void messageReceived(const char *who, const char *msg, PurpleMessageFlags flags, time_t mtime);
 		void renameUser(const char *old_name, const char *new_name, const char *new_alias);
 		void removeUsers(GList *users);
+		bool isConnected() { return m_connected; }
+		void setConversation(PurpleConversation *conv) { m_conv = conv; }
 	
 	private:
 		User *m_user;
 		std::string m_jid;
 		std::string m_userJid;
+		bool m_connected;
+		PurpleConversation *m_conv;
 };
 
 #endif	
============================================================
--- user.cpp	9cf517924a9a1be728bc6db3adea3d2255713d78
+++ user.cpp	d0c07dd64dd1950d79f90243f0f77f4ec306d5ee
@@ -539,13 +539,14 @@ void User::purpleChatAddUsers(PurpleConv
 
 void User::purpleChatAddUsers(PurpleConversation *conv, GList *cbuddies, gboolean new_arrivals) {
 	std::string name(purple_conversation_get_name(conv));
+	MUCHandler *muc = (MUCHandler*) g_hash_table_lookup(m_mucs, name.c_str());
+	if (!muc)
+		return;
 	if (!isOpenedConversation(name)) {
 		m_conversations[name] = conv;
+		muc->setConversation(conv);
 	}
-	MUCHandler *muc = (MUCHandler*) g_hash_table_lookup(m_mucs, name.c_str());
-	if (muc) {
-		muc->addUsers(cbuddies);
-	}
+	muc->addUsers(cbuddies);
 }
 
 void User::purpleChatRenameUser(PurpleConversation *conv, const char *old_name, const char *new_name, const char *new_alias) {
@@ -901,24 +902,31 @@ void User::receivedPresence(const Presen
 void User::receivedPresence(const Presence &stanza){
 	// we're connected
 
-	if (stanza.to().username()!="") {
-		MUCHandler *muc = (MUCHandler*) g_hash_table_lookup(m_mucs, stanza.to().username().c_str());
-		if (muc) {
-			Tag * ret = muc->handlePresence(stanza);
-			if (ret)
-				p->j->send(ret);
+
+
+	if (m_connected){
+
+		if (stanza.to().username()!="") {
+			MUCHandler *muc = (MUCHandler*) g_hash_table_lookup(m_mucs, stanza.to().username().c_str());
+			if (muc) {
+				Tag * ret = muc->handlePresence(stanza);
+				if (ret)
+					p->j->send(ret);
+				if (stanza.presence() == Presence::Unavailable) {
+					g_hash_table_remove(m_mucs, stanza.to().username().c_str());
+					m_conversations.erase(stanza.to().username());
+					delete muc;
+				}
+			}
+			else if (p->protocol()->isMUC(this, stanza.to().bare()) && stanza.presence() != Presence::Unavailable) {
+				MUCHandler *muc = new MUCHandler(this, stanza.to().bare(), stanza.from().full());
+				g_hash_table_replace(m_mucs, g_strdup(stanza.to().username().c_str()), muc);
+				Tag * ret = muc->handlePresence(stanza);
+				if (ret)
+					p->j->send(ret);
+			}
 		}
-		else if (p->protocol()->isMUC(this, stanza.to().bare())) {
-			MUCHandler *muc = new MUCHandler(this, stanza.to().bare(), stanza.from().full());
-			g_hash_table_replace(m_mucs, g_strdup(stanza.to().username().c_str()), muc);
-			Tag * ret = muc->handlePresence(stanza);
-			if (ret)
-				p->j->send(ret);
-		}
-	}
 
-	if (m_connected){
-	
 		// respond to probe presence
 		if (stanza.subtype() == Presence::Probe && stanza.to().username()!=""){
 			std::string name(stanza.to().username());


More information about the Commits mailing list