Fix SlackAPI::channelCreate
This commit is contained in:
parent
4b7baa6910
commit
f6949a020a
5 changed files with 21 additions and 9 deletions
|
@ -71,10 +71,11 @@ DEFINE_LOGGER(logger, "SlackAPI");
|
|||
NAME = NAME##_tmp.GetString(); \
|
||||
}
|
||||
|
||||
SlackAPI::SlackAPI(Component *component, SlackIdManager *idManager, const std::string &token) : HTTPRequestQueue(component) {
|
||||
SlackAPI::SlackAPI(Component *component, SlackIdManager *idManager, const std::string &token, const std::string &domain) : HTTPRequestQueue(component) {
|
||||
m_component = component;
|
||||
m_token = token;
|
||||
m_idManager = idManager;
|
||||
m_domain = domain;
|
||||
}
|
||||
|
||||
SlackAPI::~SlackAPI() {
|
||||
|
@ -393,6 +394,7 @@ void SlackAPI::handleSlackChannelCreate(HTTPRequest *req, bool ok, rapidjson::Do
|
|||
return;
|
||||
}
|
||||
|
||||
LOG4CXX_INFO(logger, m_domain << ": createChannel: Channel " << channel << " created, going to invite " << userId << " there.");
|
||||
channelsInvite(channelId, userId, boost::bind(&SlackAPI::handleSlackChannelInvite, this, _1, _2, _3, _4, channelId, userId, callback));
|
||||
}
|
||||
|
||||
|
@ -400,10 +402,13 @@ void SlackAPI::handleSlackChannelList(HTTPRequest *req, bool ok, rapidjson::Docu
|
|||
std::map<std::string, SlackChannelInfo> &channels = m_idManager->getChannels();
|
||||
SlackAPI::getSlackChannelInfo(req, ok, resp, data, channels);
|
||||
|
||||
if (channels.find(channel) != channels.end()) {
|
||||
channelsInvite(channel, userId, boost::bind(&SlackAPI::handleSlackChannelInvite, this, _1, _2, _3, _4, channels[channel].id, userId, callback));
|
||||
std::string channelId = m_idManager->getId(channel);
|
||||
if (channelId != channel) {
|
||||
LOG4CXX_INFO(logger, m_domain << ": createChannel: Channel " << channel << " already exists, will just invite " << userId << " there.");
|
||||
channelsInvite(channelId, userId, boost::bind(&SlackAPI::handleSlackChannelInvite, this, _1, _2, _3, _4, channelId, userId, callback));
|
||||
}
|
||||
else {
|
||||
LOG4CXX_INFO(logger, m_domain << ": createChannel: Going to create channel " << channel << ".");
|
||||
channelsCreate(channel, boost::bind(&SlackAPI::handleSlackChannelCreate, this, _1, _2, _3, _4, channel, userId, callback));
|
||||
}
|
||||
}
|
||||
|
@ -412,13 +417,16 @@ void SlackAPI::createChannel(const std::string &channel, const std::string &user
|
|||
std::string channelId = m_idManager->getId(channel);
|
||||
if (channelId != channel) {
|
||||
if (m_idManager->hasMember(channelId, userId)) {
|
||||
LOG4CXX_INFO(logger, m_domain << ": createChannel: Channel " << channel << " already exists and " << userId << " is already there.");
|
||||
callback(channelId);
|
||||
}
|
||||
else {
|
||||
channelsInvite(channel, userId, boost::bind(&SlackAPI::handleSlackChannelInvite, this, _1, _2, _3, _4, channelId, userId, callback));
|
||||
LOG4CXX_INFO(logger, m_domain << ": createChannel: Channel " << channel << " already exists, will just invite " << userId << " there.");
|
||||
channelsInvite(channelId, userId, boost::bind(&SlackAPI::handleSlackChannelInvite, this, _1, _2, _3, _4, channelId, userId, callback));
|
||||
}
|
||||
}
|
||||
else {
|
||||
LOG4CXX_INFO(logger, m_domain << ": createChannel: Channel " << channel << " not found in the cache, will refresh the channels list.");
|
||||
channelsList(boost::bind(&SlackAPI::handleSlackChannelList, this, _1, _2, _3, _4, channel, userId, callback));
|
||||
}
|
||||
}
|
||||
|
|
|
@ -69,7 +69,7 @@ class SlackUserInfo {
|
|||
|
||||
class SlackAPI : public HTTPRequestQueue {
|
||||
public:
|
||||
SlackAPI(Component *component, SlackIdManager *idManager, const std::string &token);
|
||||
SlackAPI(Component *component, SlackIdManager *idManager, const std::string &token, const std::string &domain);
|
||||
|
||||
virtual ~SlackAPI();
|
||||
|
||||
|
@ -107,6 +107,7 @@ class SlackAPI : public HTTPRequestQueue {
|
|||
Component *m_component;
|
||||
SlackIdManager *m_idManager;
|
||||
std::string m_token;
|
||||
std::string m_domain;
|
||||
};
|
||||
|
||||
}
|
||||
|
|
|
@ -55,7 +55,7 @@ SlackRTM::SlackRTM(Component *component, StorageBackend *storageBackend, SlackId
|
|||
int type = (int) TYPE_STRING;
|
||||
m_storageBackend->getUserSetting(m_uinfo.id, "bot_token", type, m_token);
|
||||
|
||||
m_api = new SlackAPI(component, m_idManager, m_token);
|
||||
m_api = new SlackAPI(component, m_idManager, m_token, m_uinfo.jid);
|
||||
}
|
||||
|
||||
SlackRTM::~SlackRTM() {
|
||||
|
@ -203,7 +203,9 @@ void SlackRTM::handleRTMStart(HTTPRequest *req, bool ok, rapidjson::Document &re
|
|||
LOG4CXX_INFO(logger, "Started RTM, WebSocket URL is " << u);
|
||||
LOG4CXX_INFO(logger, data);
|
||||
|
||||
#ifndef LIBTRANSPORT_TEST
|
||||
m_client->connectServer(u);
|
||||
#endif
|
||||
}
|
||||
|
||||
void SlackRTM::handleWebSocketConnected() {
|
||||
|
|
|
@ -64,7 +64,7 @@ SlackSession::SlackSession(Component *component, StorageBackend *storageBackend,
|
|||
int type = (int) TYPE_STRING;
|
||||
std::string token;
|
||||
m_storageBackend->getUserSetting(m_uinfo.id, "access_token", type, token);
|
||||
m_api = new SlackAPI(m_component, m_idManager, token);
|
||||
m_api = new SlackAPI(m_component, m_idManager, token, m_uinfo.jid);
|
||||
}
|
||||
|
||||
SlackSession::~SlackSession() {
|
||||
|
|
File diff suppressed because one or more lines are too long
Loading…
Add table
Reference in a new issue