Slack: Handle disconnection from 3rd-party network
This commit is contained in:
parent
b44919ed9b
commit
004f941038
9 changed files with 39 additions and 3 deletions
|
@ -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;
|
||||
};
|
||||
|
||||
}
|
||||
|
|
|
@ -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) {
|
||||
|
|
|
@ -34,7 +34,7 @@ SlackFrontendPlugin::~SlackFrontendPlugin() {
|
|||
}
|
||||
|
||||
std::string SlackFrontendPlugin::name() const {
|
||||
return "xmpp";
|
||||
return "slack";
|
||||
}
|
||||
|
||||
Frontend *SlackFrontendPlugin::createFrontend() {
|
||||
|
|
|
@ -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();
|
||||
|
|
|
@ -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) {
|
||||
|
|
|
@ -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;
|
||||
}
|
||||
|
||||
|
||||
|
|
|
@ -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;
|
||||
|
|
|
@ -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;
|
||||
|
|
|
@ -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 :)
|
||||
|
|
Loading…
Add table
Reference in a new issue