Changeset - 8b6973539f23
[Not reviewed]
0 8 0
Jan Kaluza - 13 years ago 2012-11-27 12:51:19
hanzz.k@gmail.com
Postpone room subject forwarding if we haven't sent initial presences yet
8 files changed with 55 insertions and 10 deletions:
0 comments (0 inline, 0 general)
backends/libcommuni/ircnetworkplugin.cpp
Show inline comments
 
@@ -11,6 +11,7 @@ DEFINE_LOGGER(logger, "IRCNetworkPlugin");
 
IRCNetworkPlugin::IRCNetworkPlugin(Config *config, Swift::QtEventLoop *loop, const std::string &host, int port) {
 
	this->config = config;
 
	m_currentServer = 0;
 
	m_firstPing = true;
 
	m_socket = new QTcpSocket();
 
	m_socket->connectToHost(FROM_UTF8(host), port);
 
	connect(m_socket, SIGNAL(readyRead()), this, SLOT(readData()));
 
@@ -48,6 +49,17 @@ void IRCNetworkPlugin::readData() {
 
	if (availableBytes == 0)
 
		return;
 

	
 
	if (m_firstPing) {
 
		m_firstPing = false;
 
		// Users can join the network without registering if we allow
 
		// one user to connect multiple IRC networks.
 
		if (m_servers.empty()) {
 
			NetworkPlugin::PluginConfig cfg;
 
			cfg.setNeedRegistration(false);
 
			sendConfig(cfg);
 
		}
 
	}
 

	
 
	std::string d = std::string(m_socket->readAll().data(), availableBytes);
 
	handleDataRead(d);
 
}
backends/libcommuni/ircnetworkplugin.h
Show inline comments
 
@@ -46,4 +46,5 @@ class IRCNetworkPlugin : public QObject, public NetworkPlugin {
 
		std::vector<std::string> m_servers;
 
		int m_currentServer;
 
		std::string m_identify;
 
		bool m_firstPing;
 
};
 
\ No newline at end of file
backends/libcommuni/session.cpp
Show inline comments
 
@@ -189,6 +189,7 @@ void MyIrcSession::on_messageReceived(IrcMessage *message) {
 
void MyIrcSession::on_numericMessageReceived(IrcMessage *message) {
 
	QString channel;
 
	QStringList members;
 
	std::string nick;
 

	
 
	IrcNumericMessage *m = (IrcNumericMessage *) message;
 
	switch (m->code()) {
 
@@ -196,7 +197,14 @@ void MyIrcSession::on_numericMessageReceived(IrcMessage *message) {
 
			m_topicData = TO_UTF8(m->parameters().value(2));
 
			break;
 
		case 333:
 
			 np->handleSubject(user, TO_UTF8(m->parameters().value(1)) + suffix, m_topicData, TO_UTF8(m->parameters().value(2)));
 
			nick = TO_UTF8(m->parameters().value(2));
 
			if (nick.find("!") != std::string::npos) {
 
				nick = nick.substr(0, nick.find("!"));
 
			}
 
			if (nick.find("/") != std::string::npos) {
 
				nick = nick.substr(0, nick.find("/"));
 
			}
 
			np->handleSubject(user, TO_UTF8(m->parameters().value(1)) + suffix, m_topicData, nick);
 
			break;
 
		case 353:
 
			channel = m->parameters().value(2);
include/transport/conversation.h
Show inline comments
 
@@ -148,6 +148,8 @@ class Conversation {
 
		Swift::JID m_jid;
 
		std::list<Swift::JID> m_jids;
 
		std::map<std::string, Participant> m_participants;
 
		boost::shared_ptr<Swift::Message> m_subject;
 
		bool m_sentInitialPresence;
 
};
 

	
 
}
plugin/cpp/networkplugin.cpp
Show inline comments
 
@@ -63,7 +63,7 @@ NetworkPlugin::~NetworkPlugin() {
 
}
 

	
 
void NetworkPlugin::sendConfig(const PluginConfig &cfg) {
 
	std::string data = "[registration]";
 
	std::string data = "[registration]\n";
 
	data += std::string("needPassword=") + (cfg.m_needPassword ? "1" : "0") + "\n";
 
	data += std::string("needRegistration=") + (cfg.m_needRegistration ? "1" : "0") + "\n";
 

	
src/conversation.cpp
Show inline comments
 
@@ -33,6 +33,7 @@ Conversation::Conversation(ConversationManager *conversationManager, const std::
 
// 	m_conversationManager->addConversation(this);
 
	m_muc = isMUC;
 
	m_jid = m_conversationManager->getUser()->getJID().toBare();
 
	m_sentInitialPresence = false;
 
}
 

	
 
Conversation::~Conversation() {
 
@@ -128,6 +129,11 @@ void Conversation::handleMessage(boost::shared_ptr<Swift::Message> &message, con
 
		BOOST_FOREACH(const Swift::JID &jid, m_jids) {
 
			message->setTo(jid);
 
			message->setFrom(Swift::JID(legacyName, m_conversationManager->getComponent()->getJID().toBare(), n));
 
			// Subject has to be sent after our own presence (the one with code 110)
 
			if (!message->getSubject().empty() && m_sentInitialPresence == false) {
 
				m_subject = message;
 
				return;
 
			}
 
			m_conversationManager->getComponent()->getStanzaChannel()->sendMessage(message);
 
		}
 
	}
 
@@ -169,6 +175,7 @@ Swift::Presence::ref Conversation::generatePresence(const std::string &nick, int
 
		Swift::MUCUserPayload::StatusCode c;
 
		c.code = 110;
 
		p->addStatusCode(c);
 
		m_sentInitialPresence = true;
 
	}
 

	
 
	
 
@@ -217,6 +224,11 @@ void Conversation::handleParticipantChanged(const std::string &nick, int flag, i
 
	if (!newname.empty()) {
 
		handleParticipantChanged(newname, flag, status, statusMessage);
 
	}
 

	
 
	if (m_sentInitialPresence && m_subject) {
 
		m_conversationManager->getComponent()->getStanzaChannel()->sendMessage(m_subject);
 
		m_subject.reset();
 
	}
 
}
 

	
 
}
src/tests/conversationmanager.cpp
Show inline comments
 
@@ -94,26 +94,35 @@ class ConversationManagerTest : public CPPUNIT_NS :: TestFixture, public BasicTe
 

	
 
	void handleSubjectMessages() {
 
		User *user = userManager->getUser("user@localhost");
 
		TestingConversation *conv = new TestingConversation(user->getConversationManager(), "#room", true);
 
		
 
		TestingConversation *conv = new TestingConversation(user->getConversationManager(), "buddy1");
 
		user->getConversationManager()->addConversation(conv);
 
		conv->onMessageToSend.connect(boost::bind(&ConversationManagerTest::handleMessageReceived, this, _1, _2));
 
		conv->setNickname("nickname");
 
		conv->addJID("user@localhost/resource");
 

	
 
		boost::shared_ptr<Swift::Message> msg(new Swift::Message());
 
		msg->setSubject("subject");
 
		msg->setType(Swift::Message::Groupchat);
 

	
 
		// Forward it
 
		conv->handleMessage(msg);
 
		loop->processEvents();
 

	
 
		CPPUNIT_ASSERT_EQUAL(1, (int) received.size());
 
		CPPUNIT_ASSERT(dynamic_cast<Swift::Message *>(getStanza(received[0])));
 
		CPPUNIT_ASSERT_EQUAL(std::string("subject"), dynamic_cast<Swift::Message *>(getStanza(received[0]))->getSubject());
 
		// No response, because presence with code 110 has not been sent yet and we must not send
 
		// subject before this one.
 
		CPPUNIT_ASSERT_EQUAL(0, (int) received.size());
 

	
 
		// this user presence - status code 110
 
		conv->handleParticipantChanged("nickname", 1, Swift::StatusShow::Away, "my status message");
 
		loop->processEvents();
 
		
 
		CPPUNIT_ASSERT_EQUAL(2, (int) received.size());
 
		CPPUNIT_ASSERT(dynamic_cast<Swift::Message *>(getStanza(received[1])));
 
		CPPUNIT_ASSERT_EQUAL(std::string("subject"), dynamic_cast<Swift::Message *>(getStanza(received[1]))->getSubject());
 
		received.clear();
 

	
 
		// send response
 
		msg->setFrom("user@localhost/resource");
 
		msg->setTo("buddy1@localhost/bot");
 
		msg->setTo("#room@localhost");
 
		injectMessage(msg);
 
		loop->processEvents();
 
		
src/usermanager.cpp
Show inline comments
 
@@ -247,7 +247,8 @@ void UserManager::handlePresence(Swift::Presence::ref presence) {
 
		// We allow auto_register feature in gateway-mode. This allows IRC user to register
 
		// the transport just by joining the room.
 
		if (!m_component->inServerMode()) {
 
			if (!registered && CONFIG_BOOL(m_component->getConfig(), "registration.auto_register")) {
 
			if (!registered && (CONFIG_BOOL(m_component->getConfig(), "registration.auto_register") ||
 
				!CONFIG_BOOL_DEFAULTED(m_component->getConfig(), "registration.needRegistration", true))) {
 
				res.password = "";
 
				res.jid = userkey;
 

	
0 comments (0 inline, 0 general)