Changeset - 004f9410384a
[Not reviewed]
0 9 0
Jan Kaluza - 10 years ago 2015-12-21 13:41:30
jkaluza@redhat.com
Slack: Handle disconnection from 3rd-party network
9 files changed with 39 insertions and 3 deletions:
0 comments (0 inline, 0 general)
include/transport/User.h
Show inline comments
 
@@ -134,6 +134,10 @@ class User {
 
			return m_cacheMessages;
 
		}
 

	
 
		void setReconnectLimit(int limit) {
 
			m_reconnectLimit = limit;
 
		}
 

	
 
		boost::signal<void ()> onReadyToConnect;
 
		boost::signal<void (Swift::Presence::ref presence)> onPresenceChanged;
 
		boost::signal<void (Swift::Presence::ref presence)> onRawPresenceReceived;
 
@@ -165,6 +169,7 @@ class User {
 
		std::list<Swift::Presence::ref> m_joinedRooms;
 
		std::map<std::string, std::string> m_settings;
 
		bool m_cacheMessages;
 
		int m_reconnectLimit;
 
};
 

	
 
}
spectrum/src/frontends/slack/SlackFrontend.cpp
Show inline comments
 
@@ -98,7 +98,9 @@ RosterManager *SlackFrontend::createRosterManager(User *user, Component *compone
 
}
 

	
 
User *SlackFrontend::createUser(const Swift::JID &jid, UserInfo &userInfo, Component *component, UserManager *userManager) {
 
	return new SlackUser(jid, userInfo, component, userManager);
 
	SlackUser *user = new SlackUser(jid, userInfo, component, userManager);
 
	user->setReconnectLimit(-1);
 
	return user;
 
}
 

	
 
UserManager *SlackFrontend::createUserManager(Component *component, UserRegistry *userRegistry, StorageBackend *storageBackend) {
spectrum/src/frontends/slack/SlackFrontendPlugin.cpp
Show inline comments
 
@@ -34,7 +34,7 @@ SlackFrontendPlugin::~SlackFrontendPlugin() {
 
}
 

	
 
std::string SlackFrontendPlugin::name() const {
 
	return "xmpp";
 
	return "slack";
 
}
 

	
 
Frontend *SlackFrontendPlugin::createFrontend() {
spectrum/src/frontends/slack/SlackSession.cpp
Show inline comments
 
@@ -91,6 +91,16 @@ void SlackSession::sendOnlineBuddies() {
 
	m_onlineBuddiesTimer->start();
 
}
 

	
 
void SlackSession::sendMessageToAll(const std::string &msg) {
 
	std::vector<std::string> channels;
 
	for (std::map<std::string, std::string>::const_iterator it = m_jid2channel.begin(); it != m_jid2channel.end(); it++) {
 
		if (std::find(channels.begin(), channels.end(), it->second) == channels.end()) {
 
			channels.push_back(it->second);
 
			m_rtm->getAPI()->sendMessage("Soectrum 2", it->second, msg);
 
		}
 
	}
 
}
 

	
 
void SlackSession::sendMessage(boost::shared_ptr<Swift::Message> message) {
 
	if (m_user) {
 
		std::map<std::string, Conversation *> convs = m_user->getConversationManager()->getConversations();
spectrum/src/frontends/slack/SlackSession.h
Show inline comments
 
@@ -51,6 +51,8 @@ class SlackSession {
 

	
 
		void sendMessage(boost::shared_ptr<Swift::Message> message);
 

	
 
		void sendMessageToAll(const std::string &msg);
 

	
 
		void setPurpose(const std::string &purpose, const std::string &channel = "");
 

	
 
		void setUser(User *user) {
spectrum/src/frontends/slack/SlackUser.cpp
Show inline comments
 
@@ -55,7 +55,19 @@ SlackUser::~SlackUser(){
 
}
 

	
 
void SlackUser::disconnectUser(const std::string &error, Swift::SpectrumErrorPayload::Error e) {
 
	if (!m_session) {
 
		return;
 
	}
 

	
 
	if (!error.empty()) {
 
		m_session->sendMessageToAll(error);
 
	}
 
	else {
 
		m_session->sendMessageToAll("Disconnected from 3rd-party network for unknown reason.");
 
	}
 
	m_session->sendMessageToAll("Try using ```.spectrum2 reconnect``` to reconnect.");
 
	static_cast<SlackUserManager *>(m_userManager)->moveTempSession(m_jid.toString(), m_session);
 
	m_session = NULL;
 
}
 

	
 

	
spectrum/src/frontends/slack/SlackUserManager.cpp
Show inline comments
 
@@ -77,6 +77,10 @@ SlackSession *SlackUserManager::moveTempSession(const std::string &user) {
 
	return NULL;
 
}
 

	
 
void SlackUserManager::moveTempSession(const std::string &user, SlackSession *session) {
 
	m_tempSessions[user] = session;
 
}
 

	
 

	
 
UserRegistration *SlackUserManager::getUserRegistration() {
 
	return m_userRegistration;
spectrum/src/frontends/slack/SlackUserManager.h
Show inline comments
 
@@ -60,6 +60,7 @@ class SlackUserManager : public UserManager {
 
		void sendMessage(boost::shared_ptr<Swift::Message> message);
 

	
 
		SlackSession *moveTempSession(const std::string &user);
 
		void moveTempSession(const std::string &user, SlackSession *session);
 

	
 
	private:
 
		Component *m_component;
src/User.cpp
Show inline comments
 
@@ -397,7 +397,7 @@ void User::handleDisconnected(const std::string &error, Swift::SpectrumErrorPayl
 
	}
 

	
 
	if (e == Swift::SpectrumErrorPayload::CONNECTION_ERROR_OTHER_ERROR || e == Swift::SpectrumErrorPayload::CONNECTION_ERROR_NETWORK_ERROR) {
 
		if (m_reconnectCounter < 3) {
 
		if (m_reconnectLimit < 0 || m_reconnectCounter < m_reconnectLimit) {
 
			m_reconnectCounter++;
 
			LOG4CXX_INFO(logger, m_jid.toString() << ": Disconnecting from legacy network " << error << ", trying to reconnect automatically.");
 
			// Simulate destruction/resurrection :)
0 comments (0 inline, 0 general)