Slack: Handle channels starting with hash, do not reconnect to Slack RTM when URL expired
This commit is contained in:
parent
db0e73cc01
commit
00c5273fbb
6 changed files with 43 additions and 3 deletions
|
@ -2086,9 +2086,12 @@ static void transportDataReceived(gpointer data, gint source, PurpleInputConditi
|
|||
if (CONFIG_STRING(config, "service.protocol") == "prpl-telegram") {
|
||||
cfg.setNeedPassword(false);
|
||||
}
|
||||
if (CONFIG_STRING(config, "service.protocol") != "prpl-irc") {
|
||||
if (CONFIG_STRING(config, "service.protocol") == "prpl-irc") {
|
||||
cfg.setNeedRegistration(false);
|
||||
}
|
||||
else {
|
||||
cfg.setNeedRegistration(true);
|
||||
}
|
||||
np->sendConfig(cfg);
|
||||
}
|
||||
|
||||
|
|
|
@ -55,6 +55,7 @@ class WebSocketClient {
|
|||
virtual ~WebSocketClient();
|
||||
|
||||
void connectServer(const std::string &u);
|
||||
void disconnectServer();
|
||||
|
||||
void write(const std::string &data);
|
||||
|
||||
|
|
|
@ -82,6 +82,13 @@ void WebSocketClient::connectServer(const std::string &url) {
|
|||
connectServer();
|
||||
}
|
||||
|
||||
void WebSocketClient::disconnectServer() {
|
||||
if (m_conn) {
|
||||
m_conn->onDataRead.disconnect(boost::bind(&WebSocketClient::handleDataRead, this, _1));
|
||||
m_conn->disconnect();
|
||||
}
|
||||
}
|
||||
|
||||
void WebSocketClient::write(const std::string &data) {
|
||||
if (!m_conn) {
|
||||
return;
|
||||
|
|
|
@ -92,6 +92,14 @@ void SlackRTM::start() {
|
|||
return; \
|
||||
}
|
||||
|
||||
#define STORE_INT(FROM, NAME) rapidjson::Value &NAME##_tmp = FROM[#NAME]; \
|
||||
if (!NAME##_tmp.IsInt()) { \
|
||||
LOG4CXX_ERROR(logger, "No '" << #NAME << "' number in the reply."); \
|
||||
LOG4CXX_ERROR(logger, payload); \
|
||||
return; \
|
||||
} \
|
||||
int NAME = NAME##_tmp.GetInt();
|
||||
|
||||
void SlackRTM::handlePayloadReceived(const std::string &payload) {
|
||||
rapidjson::Document d;
|
||||
if (d.Parse<0>(payload.c_str()).HasParseError()) {
|
||||
|
@ -144,6 +152,17 @@ void SlackRTM::handlePayloadReceived(const std::string &payload) {
|
|||
std::map<std::string, SlackChannelInfo> &channels = m_idManager->getChannels();
|
||||
SlackAPI::getSlackChannelInfo(NULL, true, d, payload, channels);
|
||||
}
|
||||
else if (type == "error") {
|
||||
GET_OBJECT(d, error);
|
||||
STORE_INT(error, code);
|
||||
|
||||
if (code == 1) {
|
||||
LOG4CXX_INFO(logger, "Reconnecting to Slack network");
|
||||
m_pingTimer->stop();
|
||||
m_client->disconnectServer();
|
||||
start();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void SlackRTM::sendMessage(const std::string &channel, const std::string &message) {
|
||||
|
|
|
@ -200,6 +200,9 @@ void SlackSession::handleJoinRoomCreated(const std::string &channelId, std::vect
|
|||
}
|
||||
|
||||
void SlackSession::handleJoinMessage(const std::string &message, std::vector<std::string> &args, bool quiet) {
|
||||
if (args[5][0] == '#') {
|
||||
args[5].erase(0, 1);
|
||||
}
|
||||
LOG4CXX_INFO(logger, m_uinfo.jid << ": Going to join the room " << args[3] << "@" << args[4] << ", transporting it to channel " << args[5]);
|
||||
m_api->createChannel(args[5], m_idManager->getSelfId(), boost::bind(&SlackSession::handleJoinRoomCreated, this, _1, args));
|
||||
}
|
||||
|
@ -216,7 +219,11 @@ void SlackSession::handleSlackChannelCreated(const std::string &channelId) {
|
|||
m_component->getFrontend()->onPresenceReceived(presence);
|
||||
}
|
||||
|
||||
void SlackSession::leaveRoom(const std::string &channel) {
|
||||
void SlackSession::leaveRoom(const std::string &channel_) {
|
||||
std::string channel = channel_;
|
||||
if (channel[0] == '#') {
|
||||
channel.erase(0, 1);
|
||||
}
|
||||
std::string channelId = m_idManager->getId(channel);
|
||||
std::string to = m_channel2jid[channelId];
|
||||
if (to.empty()) {
|
||||
|
|
|
@ -75,7 +75,7 @@ std::string SlackUserRegistration::createOAuth2URL(const std::vector<std::string
|
|||
m_authsData[oauth2->getState()] = args;
|
||||
|
||||
if (args.size() >= 3) {
|
||||
LOG4CXX_INFO(logger, "Generating OAUth2 URL with slack_channel=" << args[0] << ", 3rd_party_account=" << args[1]);
|
||||
LOG4CXX_INFO(logger, "Generating OAUth2 URL with slack_channel=" << args[1] << ", 3rd_party_account=" << args[2]);
|
||||
}
|
||||
else {
|
||||
LOG4CXX_WARN(logger, "Generating OAUth2 URL with too few arguments");
|
||||
|
@ -180,6 +180,9 @@ std::string SlackUserRegistration::handleOAuth2Code(const std::string &code, con
|
|||
m_storageBackend->getUser(user.jid, user);
|
||||
|
||||
if (!slackChannel.empty()) {
|
||||
if (slackChannel[0] == '#') {
|
||||
slackChannel.erase(0, 1);
|
||||
}
|
||||
m_storageBackend->getUserSetting(user.id, "slack_channel", type, slackChannel);
|
||||
}
|
||||
|
||||
|
|
Loading…
Add table
Reference in a new issue