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(); \
|
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_component = component;
|
||||||
m_token = token;
|
m_token = token;
|
||||||
m_idManager = idManager;
|
m_idManager = idManager;
|
||||||
|
m_domain = domain;
|
||||||
}
|
}
|
||||||
|
|
||||||
SlackAPI::~SlackAPI() {
|
SlackAPI::~SlackAPI() {
|
||||||
|
@ -393,6 +394,7 @@ void SlackAPI::handleSlackChannelCreate(HTTPRequest *req, bool ok, rapidjson::Do
|
||||||
return;
|
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));
|
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();
|
std::map<std::string, SlackChannelInfo> &channels = m_idManager->getChannels();
|
||||||
SlackAPI::getSlackChannelInfo(req, ok, resp, data, channels);
|
SlackAPI::getSlackChannelInfo(req, ok, resp, data, channels);
|
||||||
|
|
||||||
if (channels.find(channel) != channels.end()) {
|
std::string channelId = m_idManager->getId(channel);
|
||||||
channelsInvite(channel, userId, boost::bind(&SlackAPI::handleSlackChannelInvite, this, _1, _2, _3, _4, channels[channel].id, userId, callback));
|
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 {
|
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));
|
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);
|
std::string channelId = m_idManager->getId(channel);
|
||||||
if (channelId != channel) {
|
if (channelId != channel) {
|
||||||
if (m_idManager->hasMember(channelId, userId)) {
|
if (m_idManager->hasMember(channelId, userId)) {
|
||||||
|
LOG4CXX_INFO(logger, m_domain << ": createChannel: Channel " << channel << " already exists and " << userId << " is already there.");
|
||||||
callback(channelId);
|
callback(channelId);
|
||||||
}
|
}
|
||||||
else {
|
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 {
|
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));
|
channelsList(boost::bind(&SlackAPI::handleSlackChannelList, this, _1, _2, _3, _4, channel, userId, callback));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -69,7 +69,7 @@ class SlackUserInfo {
|
||||||
|
|
||||||
class SlackAPI : public HTTPRequestQueue {
|
class SlackAPI : public HTTPRequestQueue {
|
||||||
public:
|
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();
|
virtual ~SlackAPI();
|
||||||
|
|
||||||
|
@ -107,6 +107,7 @@ class SlackAPI : public HTTPRequestQueue {
|
||||||
Component *m_component;
|
Component *m_component;
|
||||||
SlackIdManager *m_idManager;
|
SlackIdManager *m_idManager;
|
||||||
std::string m_token;
|
std::string m_token;
|
||||||
|
std::string m_domain;
|
||||||
};
|
};
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -55,7 +55,7 @@ SlackRTM::SlackRTM(Component *component, StorageBackend *storageBackend, SlackId
|
||||||
int type = (int) TYPE_STRING;
|
int type = (int) TYPE_STRING;
|
||||||
m_storageBackend->getUserSetting(m_uinfo.id, "bot_token", type, m_token);
|
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() {
|
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, "Started RTM, WebSocket URL is " << u);
|
||||||
LOG4CXX_INFO(logger, data);
|
LOG4CXX_INFO(logger, data);
|
||||||
|
|
||||||
|
#ifndef LIBTRANSPORT_TEST
|
||||||
m_client->connectServer(u);
|
m_client->connectServer(u);
|
||||||
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
void SlackRTM::handleWebSocketConnected() {
|
void SlackRTM::handleWebSocketConnected() {
|
||||||
|
|
|
@ -64,7 +64,7 @@ SlackSession::SlackSession(Component *component, StorageBackend *storageBackend,
|
||||||
int type = (int) TYPE_STRING;
|
int type = (int) TYPE_STRING;
|
||||||
std::string token;
|
std::string token;
|
||||||
m_storageBackend->getUserSetting(m_uinfo.id, "access_token", type, 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() {
|
SlackSession::~SlackSession() {
|
||||||
|
|
File diff suppressed because one or more lines are too long
Loading…
Add table
Reference in a new issue