soc.2009.transport: 4607ce3e: Resend chat topic

hanzz at soc.pidgin.im hanzz at soc.pidgin.im
Fri Jun 12 04:20:29 EDT 2009


-----------------------------------------------------------------
Revision: 4607ce3e7276f9455f02a48603a7ed50aee88986
Ancestor: de0ce8b66d50015cd194d658359e28b8c924a84b
Author: hanzz at soc.pidgin.im
Date: 2009-06-12T08:18:40
Branch: im.pidgin.soc.2009.transport
URL: http://d.pidgin.im/viewmtn/revision/info/4607ce3e7276f9455f02a48603a7ed50aee88986

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

ChangeLog: 

Resend chat topic

-------------- next part --------------
============================================================
--- main.cpp	00e803cc42128985d84e0d104b2c2b7c9e0a7b5f
+++ main.cpp	471c67559846e445ddde8388461651aa0f1e41f7
@@ -167,6 +167,10 @@ static void conv_write_conv(PurpleConver
 	}
 }
 
+static void conv_chat_topic_changed(PurpleConversation *chat, const char *who, const char *topic) {
+	GlooxMessageHandler::instance()->purpleChatTopicChanged(chat, who, topic);
+}
+
 static void conv_chat_add_users(PurpleConversation *conv, GList *cbuddies, gboolean new_arrivals) {
 	GlooxMessageHandler::instance()->purpleChatAddUsers(conv, cbuddies, new_arrivals);
 }
@@ -955,6 +959,16 @@ void GlooxMessageHandler::purpleConversa
 	}
 }
 
+void GlooxMessageHandler::purpleChatTopicChanged(PurpleConversation *conv, const char *who, const char *topic) {
+	PurpleAccount *account = purple_conversation_get_account(conv);
+	User *user = userManager()->getUserByAccount(account);
+	if (user) {
+		if (user->isConnected()){
+			user->purpleChatTopicChanged(conv, who, topic);
+		}
+	}
+}
+
 void GlooxMessageHandler::purpleChatAddUsers(PurpleConversation *conv, GList *cbuddies, gboolean new_arrivals) {
 	PurpleAccount *account = purple_conversation_get_account(conv);
 	User *user = userManager()->getUserByAccount(account);
@@ -1286,6 +1300,7 @@ bool GlooxMessageHandler::initPurple(){
 		purple_signal_connect(purple_xfers_get_handle(), "file-recv-complete", &xfer_handle, PURPLE_CALLBACK(XferComplete), NULL);
 		purple_signal_connect(purple_connections_get_handle(), "signed-on", &conn_handle,PURPLE_CALLBACK(signed_on), NULL);
 		purple_signal_connect(purple_blist_get_handle(), "buddy-removed", &blist_handle,PURPLE_CALLBACK(buddyRemoved), NULL);				
+		purple_signal_connect(purple_conversations_get_handle(), "chat-topic-changed", &conversation_handle, PURPLE_CALLBACK(conv_chat_topic_changed), NULL);
 
 		purple_cmd_register("help", "w", PURPLE_CMD_P_DEFAULT, (PurpleCmdFlag) (PURPLE_CMD_FLAG_CHAT | PURPLE_CMD_FLAG_IM | PURPLE_CMD_FLAG_ALLOW_WRONG_ARGS), NULL, help_command_cb, _("help <command>:  Help on a specific command."), NULL);
 
============================================================
--- main.h	64bc2ecaab87aa67a616e6b6749dcd7933f3fb40
+++ main.h	cb907f165977326df8fd0d0ee1b7f75b75dc2ad1
@@ -159,6 +159,7 @@ public:
 	void purpleMessageReceived(PurpleAccount* account,char * name,char *msg,PurpleConversation *conv,PurpleMessageFlags flags);
 	void purpleConversationWriteIM(PurpleConversation *conv, const char *who, const char *message, PurpleMessageFlags flags, time_t mtime);
 	void purpleConversationWriteChat(PurpleConversation *conv, const char *who, const char *message, PurpleMessageFlags flags, time_t mtime);
+	void purpleChatTopicChanged(PurpleConversation *conv, const char *who, const char *topic);
 	void purpleChatAddUsers(PurpleConversation *conv, GList *cbuddies, gboolean new_arrivals);
 	void purpleChatRenameUser(PurpleConversation *conv, const char *old_name, const char *new_name, const char *new_alias);
 	void purpleChatRemoveUsers(PurpleConversation *conv, GList *users);
============================================================
--- muchandler.cpp	34210982423a7462996cc160202c88d3b2fc5f1a
+++ muchandler.cpp	3e18d5f4399f04dec75858d6b72c4095a565516d
@@ -27,6 +27,8 @@ MUCHandler::MUCHandler(User *user, const
 	m_jid = jid;
 	m_userJid = userJid;
 	m_connected = false;
+	m_topic = "";
+	m_topicUser = "";
 }
 	
 MUCHandler::~MUCHandler() {}
@@ -53,7 +55,6 @@ void MUCHandler::addUsers(GList *cbuddie
 }
 
 void MUCHandler::addUsers(GList *cbuddies) {
-	m_connected = true;
 	GList *l = cbuddies;
 	while (l != NULL) {
 		PurpleConvChatBuddy *cb = (PurpleConvChatBuddy *)l->data;
@@ -76,15 +77,31 @@ void MUCHandler::addUsers(GList *cbuddie
 		x->addAttribute("xmlns", "http://jabber.org/protocol/muc#user");
 		
 		Tag *item = new Tag("item");
-		item->addAttribute("affiliation", "member");
-		item->addAttribute("role", "participant");
 		
+		
+		if (flags & PURPLE_CBFLAGS_OP) {
+			item->addAttribute("affiliation", "admin");
+			item->addAttribute("role", "moderator");
+		}
+		else if (PURPLE_CBFLAGS_FOUNDER) {
+			item->addAttribute("affiliation", "owner");
+			item->addAttribute("role", "moderator");
+		}
+		else {
+			item->addAttribute("affiliation", "member");
+			item->addAttribute("role", "participant");
+		}
+		
 		x->addChild(item);
 		tag->addChild(x);
 		m_user->p->j->send(tag);
 		
 		l = l->next;
 	}
+	if (!m_connected && !m_topic.empty()) {
+		sendTopic();
+	}
+	m_connected = true;
 }
 
 void MUCHandler::messageReceived(const char *who, const char *msg, PurpleMessageFlags flags, time_t mtime) {
@@ -169,3 +186,26 @@ void MUCHandler::removeUsers(GList *user
 	}
 }
 
+void MUCHandler::sendTopic() {
+	Tag *m = new Tag("message");
+	m->addAttribute("from", m_jid + "/" + m_topicUser);
+	m->addAttribute("to", m_userJid);
+	m->addAttribute("type", "groupchat");
+	m->addChild( new Tag("subject", m_topic) );
+
+	m_user->p->j->send(m);
+}
+
+void MUCHandler::topicChanged(const char *who, const char *topic) {
+// <message
+// from='wiccarocks at shakespeare.lit/laptop'
+// to='darkcave at chat.shakespeare.lit'
+// type='groupchat'>
+// <subject>Fire Burn and Cauldron Bubble!</subject>
+// </message>
+	m_topic = std::string(topic);
+	m_topicUser = std::string(who ? who : "transport");
+	if (m_connected)
+		sendTopic();
+}
+
============================================================
--- muchandler.h	7745f53b1ea9736903295b3dc5905955e6255336
+++ muchandler.h	a3a36e9c901b3450ddcf98a05de933729aa82b8f
@@ -41,15 +41,20 @@ 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);
+		void topicChanged(const char *who, const char *topic);
 		bool isConnected() { return m_connected; }
 		void setConversation(PurpleConversation *conv) { m_conv = conv; }
 	
 	private:
+		void sendTopic();
+		
 		User *m_user;
 		std::string m_jid;
 		std::string m_userJid;
 		bool m_connected;
 		PurpleConversation *m_conv;
+		std::string m_topic;
+		std::string m_topicUser;
 };
 
 #endif	
============================================================
--- user.cpp	d0c07dd64dd1950d79f90243f0f77f4ec306d5ee
+++ user.cpp	f591f4c77514348e85bc6ac1f904444517048f04
@@ -482,12 +482,14 @@ void User::purpleConversationWriteChat(P
 		return;
 
 	std::string name(who);
-
+	MUCHandler *muc = (MUCHandler*) g_hash_table_lookup(m_mucs, purple_conversation_get_name(conv));
 	if (!isOpenedConversation(name)) {
-			m_conversations[name] = conv;
+		m_conversations[name] = conv;
+		if (muc)
+			muc->setConversation(conv);
 	}
 
-	MUCHandler *muc = (MUCHandler*) g_hash_table_lookup(m_mucs, purple_conversation_get_name(conv));
+	
 	if (muc) {
 		muc->messageReceived(who, msg, flags, mtime);
 	}
@@ -537,6 +539,13 @@ void User::purpleConversationWriteIM(Pur
 	p->j->send( s );
 }
 
+void User::purpleChatTopicChanged(PurpleConversation *conv, const char *who, const char *topic) {
+	MUCHandler *muc = (MUCHandler*) g_hash_table_lookup(m_mucs, purple_conversation_get_name(conv));
+	if (muc) {
+		muc->topicChanged(who, topic);
+	}
+}
+
 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());
============================================================
--- user.h	978873cc5fb92d2e754c3e90ad182515d47b9ca2
+++ user.h	df704a2f6dafc1de2fabac290322b1303ddab517
@@ -92,6 +92,7 @@ class User {
 		void purpleMessageReceived(PurpleAccount* account,char * name,char *msg,PurpleConversation *conv,PurpleMessageFlags flags);
 		void purpleConversationWriteIM(PurpleConversation *conv, const char *who, const char *msg, PurpleMessageFlags flags, time_t mtime);
 		void purpleConversationWriteChat(PurpleConversation *conv, const char *who, const char *msg, PurpleMessageFlags flags, time_t mtime);
+		void purpleChatTopicChanged(PurpleConversation *conv, const char *who, const char *topic);
 		void purpleChatRenameUser(PurpleConversation *conv, const char *old_name, const char *new_name, const char *new_alias);
 		void purpleChatRemoveUsers(PurpleConversation *conv, GList *users);
 		void purpleChatAddUsers(PurpleConversation *conv, GList *cbuddies, gboolean new_arrivals);


More information about the Commits mailing list