Slack: allow registering an account and chatting with normal contacts.
This commit is contained in:
parent
2922d57bfd
commit
26a01b8efa
15 changed files with 215 additions and 54 deletions
|
@ -9,13 +9,16 @@
|
|||
#include <string.h>
|
||||
#include "rapidjson/document.h"
|
||||
|
||||
#include "Swiften/Network/Timer.h"
|
||||
|
||||
namespace Transport {
|
||||
|
||||
class HTTPRequest;
|
||||
class Component;
|
||||
|
||||
class HTTPRequestQueue {
|
||||
public:
|
||||
HTTPRequestQueue(int delayBetweenRequests = 1);
|
||||
HTTPRequestQueue(Component *component, int delayBetweenRequests = 1);
|
||||
|
||||
virtual ~HTTPRequestQueue();
|
||||
|
||||
|
@ -23,10 +26,14 @@ class HTTPRequestQueue {
|
|||
|
||||
void sendNextRequest();
|
||||
|
||||
private:
|
||||
void handleRequestFinished();
|
||||
|
||||
private:
|
||||
int m_delay;
|
||||
std::queue<HTTPRequest *> m_queue;
|
||||
bool m_processing;
|
||||
Swift::Timer::ref m_queueTimer;
|
||||
};
|
||||
|
||||
}
|
||||
|
|
|
@ -40,7 +40,7 @@ class NetworkPlugin {
|
|||
|
||||
class PluginConfig {
|
||||
public:
|
||||
PluginConfig() : m_needPassword(true), m_needRegistration(false), m_supportMUC(false), m_rawXML(false),
|
||||
PluginConfig() : m_needPassword(true), m_needRegistration(true), m_supportMUC(false), m_rawXML(false),
|
||||
m_disableJIDEscaping(false) {}
|
||||
virtual ~PluginConfig() {}
|
||||
|
||||
|
|
|
@ -36,7 +36,29 @@ namespace Transport {
|
|||
|
||||
DEFINE_LOGGER(logger, "SlackAPI");
|
||||
|
||||
SlackAPI::SlackAPI(Component *component, const std::string &token) {
|
||||
#define GET_ARRAY(FROM, NAME) rapidjson::Value &NAME = FROM[#NAME]; \
|
||||
if (!NAME.IsArray()) { \
|
||||
LOG4CXX_ERROR(logger, "No '" << #NAME << "' object in the reply."); \
|
||||
return; \
|
||||
}
|
||||
|
||||
#define STORE_STRING(FROM, NAME) rapidjson::Value &NAME##_tmp = FROM[#NAME]; \
|
||||
if (!NAME##_tmp.IsString()) { \
|
||||
LOG4CXX_ERROR(logger, "No '" << #NAME << "' string in the reply."); \
|
||||
LOG4CXX_ERROR(logger, data); \
|
||||
return; \
|
||||
} \
|
||||
std::string NAME = NAME##_tmp.GetString();
|
||||
|
||||
#define STORE_BOOL(FROM, NAME) rapidjson::Value &NAME##_tmp = FROM[#NAME]; \
|
||||
if (!NAME##_tmp.IsBool()) { \
|
||||
LOG4CXX_ERROR(logger, "No '" << #NAME << "' string in the reply."); \
|
||||
LOG4CXX_ERROR(logger, data); \
|
||||
return; \
|
||||
} \
|
||||
bool NAME = NAME##_tmp.GetBool();
|
||||
|
||||
SlackAPI::SlackAPI(Component *component, const std::string &token) : HTTPRequestQueue(component) {
|
||||
m_component = component;
|
||||
m_token = token;
|
||||
}
|
||||
|
@ -60,6 +82,29 @@ void SlackAPI::sendMessage(const std::string &from, const std::string &to, const
|
|||
queueRequest(req);
|
||||
}
|
||||
|
||||
void SlackAPI::deleteMessage(const std::string &channel, const std::string &ts) {
|
||||
LOG4CXX_INFO(logger, "Deleting message " << channel << " " << ts);
|
||||
std::string url = "https://slack.com/api/chat.delete?";
|
||||
url += "&channel=" + Util::urlencode(channel);
|
||||
url += "&ts=" + Util::urlencode(ts);
|
||||
url += "&token=" + Util::urlencode(m_token);
|
||||
|
||||
HTTPRequest *req = new HTTPRequest(THREAD_POOL(m_component), HTTPRequest::Get, url,
|
||||
boost::bind(&SlackAPI::handleSendMessage, this, _1, _2, _3, _4));
|
||||
queueRequest(req);
|
||||
}
|
||||
|
||||
void SlackAPI::setPurpose(const std::string &channel, const std::string &purpose) {
|
||||
std::string url = "https://slack.com/api/channels.setPurpose?";
|
||||
url += "&channel=" + Util::urlencode(channel);
|
||||
url += "&purpose=" + Util::urlencode(purpose);
|
||||
url += "&token=" + Util::urlencode(m_token);
|
||||
|
||||
HTTPRequest *req = new HTTPRequest(THREAD_POOL(m_component), HTTPRequest::Get, url,
|
||||
boost::bind(&SlackAPI::handleSendMessage, this, _1, _2, _3, _4));
|
||||
queueRequest(req);
|
||||
}
|
||||
|
||||
std::string SlackAPI::getChannelId(HTTPRequest *req, bool ok, rapidjson::Document &resp, const std::string &data) {
|
||||
if (!ok) {
|
||||
LOG4CXX_ERROR(logger, req->getError());
|
||||
|
@ -137,28 +182,6 @@ void SlackAPI::usersList(HTTPRequest::Callback callback) {
|
|||
queueRequest(req);
|
||||
}
|
||||
|
||||
#define GET_ARRAY(FROM, NAME) rapidjson::Value &NAME = FROM[#NAME]; \
|
||||
if (!NAME.IsArray()) { \
|
||||
LOG4CXX_ERROR(logger, "No '" << #NAME << "' object in the reply."); \
|
||||
return; \
|
||||
}
|
||||
|
||||
#define STORE_STRING(FROM, NAME) rapidjson::Value &NAME##_tmp = FROM[#NAME]; \
|
||||
if (!NAME##_tmp.IsString()) { \
|
||||
LOG4CXX_ERROR(logger, "No '" << #NAME << "' string in the reply."); \
|
||||
LOG4CXX_ERROR(logger, data); \
|
||||
return; \
|
||||
} \
|
||||
std::string NAME = NAME##_tmp.GetString();
|
||||
|
||||
#define STORE_BOOL(FROM, NAME) rapidjson::Value &NAME##_tmp = FROM[#NAME]; \
|
||||
if (!NAME##_tmp.IsBool()) { \
|
||||
LOG4CXX_ERROR(logger, "No '" << #NAME << "' string in the reply."); \
|
||||
LOG4CXX_ERROR(logger, data); \
|
||||
return; \
|
||||
} \
|
||||
bool NAME = NAME##_tmp.GetBool();
|
||||
|
||||
void SlackAPI::getSlackChannelInfo(HTTPRequest *req, bool ok, rapidjson::Document &resp, const std::string &data, std::map<std::string, SlackChannelInfo> &ret) {
|
||||
if (!ok) {
|
||||
LOG4CXX_ERROR(logger, req->getError());
|
||||
|
@ -182,11 +205,11 @@ void SlackAPI::getSlackChannelInfo(HTTPRequest *req, bool ok, rapidjson::Documen
|
|||
|
||||
rapidjson::Value &members = channels[i]["members"];
|
||||
for (int y = 0; members.IsArray() && y < members.Size(); y++) {
|
||||
if (!members[i].IsString()) {
|
||||
if (!members[y].IsString()) {
|
||||
continue;
|
||||
}
|
||||
|
||||
info.members.push_back(members[i].GetString());
|
||||
info.members.push_back(members[y].GetString());
|
||||
}
|
||||
|
||||
ret[info.name] = info;
|
||||
|
|
|
@ -79,7 +79,9 @@ class SlackAPI : public HTTPRequestQueue {
|
|||
void imOpen(const std::string &uid, HTTPRequest::Callback callback);
|
||||
std::string getChannelId(HTTPRequest *req, bool ok, rapidjson::Document &resp, const std::string &data);
|
||||
|
||||
void deleteMessage(const std::string &channel, const std::string &ts);
|
||||
void sendMessage(const std::string &from, const std::string &to, const std::string &text);
|
||||
void setPurpose(const std::string &channel, const std::string &purpose);
|
||||
|
||||
static void getSlackChannelInfo(HTTPRequest *req, bool ok, rapidjson::Document &resp, const std::string &data, std::map<std::string, SlackChannelInfo> &channels);
|
||||
static void getSlackImInfo(HTTPRequest *req, bool ok, rapidjson::Document &resp, const std::string &data, std::map<std::string, SlackImInfo> &ims);
|
||||
|
|
|
@ -89,7 +89,8 @@ void SlackRTM::handlePayloadReceived(const std::string &payload) {
|
|||
STORE_STRING(d, channel);
|
||||
STORE_STRING(d, user);
|
||||
STORE_STRING(d, text);
|
||||
onMessageReceived(channel, user, text);
|
||||
STORE_STRING(d, ts);
|
||||
onMessageReceived(channel, user, text, ts);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -80,7 +80,7 @@ class SlackRTM {
|
|||
return m_api;
|
||||
}
|
||||
|
||||
boost::signal<void (const std::string &channel, const std::string &user, const std::string &text)> onMessageReceived;
|
||||
boost::signal<void (const std::string &channel, const std::string &user, const std::string &text, const std::string &ts)> onMessageReceived;
|
||||
|
||||
private:
|
||||
void handlePayloadReceived(const std::string &payload);
|
||||
|
|
|
@ -21,6 +21,7 @@
|
|||
#include "SlackRosterManager.h"
|
||||
#include "SlackFrontend.h"
|
||||
#include "SlackUser.h"
|
||||
#include "SlackSession.h"
|
||||
|
||||
#include "transport/Buddy.h"
|
||||
#include "transport/User.h"
|
||||
|
@ -40,11 +41,49 @@ DEFINE_LOGGER(logger, "SlackRosterManager");
|
|||
|
||||
SlackRosterManager::SlackRosterManager(User *user, Component *component) : RosterManager(user, component){
|
||||
m_user = user;
|
||||
m_transport = component;
|
||||
m_component = component;
|
||||
|
||||
m_onlineBuddiesTimer = m_component->getNetworkFactories()->getTimerFactory()->createTimer(20000);
|
||||
m_onlineBuddiesTimer->onTick.connect(boost::bind(&SlackRosterManager::sendOnlineBuddies, this));
|
||||
m_onlineBuddiesTimer->start();
|
||||
}
|
||||
|
||||
SlackRosterManager::~SlackRosterManager() {
|
||||
m_onlineBuddiesTimer->stop();
|
||||
}
|
||||
|
||||
void SlackRosterManager::sendOnlineBuddies() {
|
||||
std::string onlineBuddies = "Online users: ";
|
||||
Swift::StatusShow s;
|
||||
std::string statusMessage;
|
||||
|
||||
const RosterManager::BuddiesMap &roster = getBuddies();
|
||||
for(RosterManager::BuddiesMap::const_iterator bt = roster.begin(); bt != roster.end(); bt++) {
|
||||
Buddy *b = (*bt).second;
|
||||
if (!b) {
|
||||
continue;
|
||||
}
|
||||
|
||||
if (!(b->getStatus(s, statusMessage))) {
|
||||
continue;
|
||||
}
|
||||
|
||||
if (s.getType() == Swift::StatusShow::None) {
|
||||
continue;
|
||||
}
|
||||
|
||||
onlineBuddies += b->getAlias() + ", ";
|
||||
}
|
||||
|
||||
if (m_onlineBuddies != onlineBuddies) {
|
||||
m_onlineBuddies = onlineBuddies;
|
||||
SlackSession *session = static_cast<SlackUser *>(m_user)->getSession();
|
||||
if (session) {
|
||||
session->setPurpose(m_onlineBuddies);
|
||||
}
|
||||
}
|
||||
|
||||
m_onlineBuddiesTimer->start();
|
||||
}
|
||||
|
||||
void SlackRosterManager::doRemoveBuddy(Buddy *buddy) {
|
||||
|
|
|
@ -26,6 +26,8 @@
|
|||
#include <algorithm>
|
||||
#include <map>
|
||||
|
||||
#include "Swiften/Network/Timer.h"
|
||||
|
||||
namespace Transport {
|
||||
|
||||
class Buddy;
|
||||
|
@ -44,11 +46,14 @@ class SlackRosterManager : public RosterManager {
|
|||
virtual void doAddBuddy(Buddy *buddy);
|
||||
virtual void doUpdateBuddy(Buddy *buddy);
|
||||
|
||||
void sendOnlineBuddies();
|
||||
|
||||
private:
|
||||
RosterStorage *m_rosterStorage;
|
||||
User *m_user;
|
||||
Component *m_transport;
|
||||
Component *m_component;
|
||||
Swift::Timer::ref m_onlineBuddiesTimer;
|
||||
std::string m_onlineBuddies;
|
||||
};
|
||||
|
||||
}
|
||||
|
|
|
@ -22,6 +22,7 @@
|
|||
#include "SlackFrontend.h"
|
||||
#include "SlackUser.h"
|
||||
#include "SlackRTM.h"
|
||||
#include "SlackRosterManager.h"
|
||||
|
||||
#include "transport/Transport.h"
|
||||
#include "transport/HTTPRequest.h"
|
||||
|
@ -43,13 +44,13 @@ namespace Transport {
|
|||
|
||||
DEFINE_LOGGER(logger, "SlackSession");
|
||||
|
||||
SlackSession::SlackSession(Component *component, StorageBackend *storageBackend, UserInfo uinfo) : m_uinfo(uinfo) {
|
||||
SlackSession::SlackSession(Component *component, StorageBackend *storageBackend, UserInfo uinfo) : m_uinfo(uinfo), m_user(NULL) {
|
||||
m_component = component;
|
||||
m_storageBackend = storageBackend;
|
||||
|
||||
m_rtm = new SlackRTM(component, storageBackend, uinfo);
|
||||
m_rtm->onRTMStarted.connect(boost::bind(&SlackSession::handleRTMStarted, this));
|
||||
m_rtm->onMessageReceived.connect(boost::bind(&SlackSession::handleMessageReceived, this, _1, _2, _3, false));
|
||||
m_rtm->onMessageReceived.connect(boost::bind(&SlackSession::handleMessageReceived, this, _1, _2, _3, _4, false));
|
||||
|
||||
}
|
||||
|
||||
|
@ -62,16 +63,34 @@ void SlackSession::sendMessage(boost::shared_ptr<Swift::Message> message) {
|
|||
return;
|
||||
}
|
||||
|
||||
std::string &channel = m_jid2channel[message->getFrom().toBare().toString()];
|
||||
std::string from = message->getFrom().getResource();
|
||||
std::string channel = m_jid2channel[message->getFrom().toBare().toString()];
|
||||
LOG4CXX_INFO(logger, "JID is " << message->getFrom().toBare().toString());
|
||||
if (channel.empty()) {
|
||||
if (m_slackChannel.empty()) {
|
||||
LOG4CXX_ERROR(logger, m_uinfo.jid << ": Received message for unknown channel from " << message->getFrom().toBare().toString());
|
||||
return;
|
||||
}
|
||||
channel = m_slackChannel;
|
||||
from = Buddy::JIDToLegacyName(message->getFrom());
|
||||
|
||||
Buddy *b;
|
||||
if (m_user && (b = m_user->getRosterManager()->getBuddy(from)) != NULL) {
|
||||
from = b->getAlias() + " (" + from + ")";
|
||||
}
|
||||
}
|
||||
|
||||
m_rtm->getAPI()->sendMessage(message->getFrom().getResource(), channel, message->getBody());
|
||||
LOG4CXX_INFO(logger, "FROM " << from);
|
||||
m_rtm->getAPI()->sendMessage(from, channel, message->getBody());
|
||||
}
|
||||
|
||||
void SlackSession::setPurpose(const std::string &purpose) {
|
||||
if (m_slackChannel.empty()) {
|
||||
return;
|
||||
}
|
||||
|
||||
LOG4CXX_INFO(logger, "Setting channel purppose: " << m_slackChannel << " " << purpose);
|
||||
m_rtm->getAPI()->setPurpose(m_slackChannel, purpose);
|
||||
}
|
||||
|
||||
void SlackSession::handleJoinMessage(const std::string &message, std::vector<std::string> &args, bool quiet) {
|
||||
|
@ -81,10 +100,15 @@ void SlackSession::handleJoinMessage(const std::string &message, std::vector<std
|
|||
std::string legacyServer = SlackAPI::SlackObjectToPlainText(args[4]);
|
||||
std::string slackChannel = SlackAPI::SlackObjectToPlainText(args[5], true);
|
||||
|
||||
m_uinfo.uin = name;
|
||||
m_storageBackend->setUser(m_uinfo);
|
||||
|
||||
std::string to = legacyRoom + "%" + legacyServer + "@" + m_component->getJID().toString();
|
||||
if (!CONFIG_BOOL_DEFAULTED(m_component->getConfig(), "registration.needRegistration", true)) {
|
||||
m_uinfo.uin = name;
|
||||
m_storageBackend->setUser(m_uinfo);
|
||||
}
|
||||
// else {
|
||||
// to = legacyRoom + "\\40" + legacyServer + "@" + m_component->getJID().toString();
|
||||
// }
|
||||
|
||||
m_jid2channel[to] = slackChannel;
|
||||
m_channel2jid[slackChannel] = to;
|
||||
|
||||
|
@ -173,7 +197,7 @@ void SlackSession::handleRegisterMessage(const std::string &message, std::vector
|
|||
}
|
||||
}
|
||||
|
||||
void SlackSession::handleMessageReceived(const std::string &channel, const std::string &user, const std::string &message, bool quiet) {
|
||||
void SlackSession::handleMessageReceived(const std::string &channel, const std::string &user, const std::string &message, const std::string &ts, bool quiet) {
|
||||
if (m_ownerChannel != channel) {
|
||||
std::string to = m_channel2jid[channel];
|
||||
if (!to.empty()) {
|
||||
|
@ -185,7 +209,41 @@ void SlackSession::handleMessageReceived(const std::string &channel, const std::
|
|||
m_component->getFrontend()->onMessageReceived(msg);
|
||||
}
|
||||
else {
|
||||
// When changing the purpose, we do not want to spam to room with the info,
|
||||
// so remove the purpose message.
|
||||
// if (message.find("set the channel purpose") != std::string::npos) {
|
||||
// m_rtm->getAPI()->deleteMessage(channel, ts);
|
||||
// }
|
||||
// TODO: MAP `user` to JID somehow and send the message to proper JID.
|
||||
// So far send to all online contacts
|
||||
|
||||
if (!m_user || !m_user->getRosterManager()) {
|
||||
return;
|
||||
}
|
||||
|
||||
Swift::StatusShow s;
|
||||
std::string statusMessage;
|
||||
const RosterManager::BuddiesMap &roster = m_user->getRosterManager()->getBuddies();
|
||||
for(RosterManager::BuddiesMap::const_iterator bt = roster.begin(); bt != roster.end(); bt++) {
|
||||
Buddy *b = (*bt).second;
|
||||
if (!b) {
|
||||
continue;
|
||||
}
|
||||
|
||||
if (!(b->getStatus(s, statusMessage))) {
|
||||
continue;
|
||||
}
|
||||
|
||||
if (s.getType() == Swift::StatusShow::None) {
|
||||
continue;
|
||||
}
|
||||
|
||||
boost::shared_ptr<Swift::Message> msg(new Swift::Message());
|
||||
msg->setTo(b->getJID());
|
||||
msg->setFrom(Swift::JID("", m_uinfo.jid, "default"));
|
||||
msg->setBody("<" + user + "> " + message);
|
||||
m_component->getFrontend()->onMessageReceived(msg);
|
||||
}
|
||||
}
|
||||
return;
|
||||
}
|
||||
|
@ -240,16 +298,16 @@ void SlackSession::handleImOpen(HTTPRequest *req, bool ok, rapidjson::Document &
|
|||
int type = (int) TYPE_STRING;
|
||||
m_storageBackend->getUserSetting(m_uinfo.id, "rooms", type, rooms);
|
||||
|
||||
if (CONFIG_BOOL_DEFAULTED(m_component->getConfig(), "registration.needRegistration", false)) {
|
||||
if (!CONFIG_BOOL_DEFAULTED(m_component->getConfig(), "registration.needRegistration", true)) {
|
||||
if (rooms.empty()) {
|
||||
std::string msg;
|
||||
msg = "Hi, it seems you have enabled Spectrum 2 transport for your Team. As a Team owner, you should now configure it:\\n";
|
||||
msg += "1. At first, create new channel in which you want this Spectrum 2 transport to send the messages, or choose the existing one.\\n";
|
||||
msg += "2. Invite this Spectrum 2 bot into this channel.\\n";
|
||||
msg += "3. Configure the transportation between 3rd-party network and this channel by executing following command in this chat:\\n";
|
||||
msg += "```.spectrum2 register 3rdPartyAccount 3rdPartyPassword #SlackChannel```\\n";
|
||||
msg += "For example to join XMPP account test@xmpp.tld and transport it into #slack_channel, the command would look like this:\\n";
|
||||
msg += "```.spectrum2 register test@xmpp.tld mypassword #slack_channel```\\n";
|
||||
msg += "```.spectrum2 join.room NameOfYourBotIn3rdPartyNetwork #3rdPartyRoom hostname_of_3rd_party_server #SlackChannel```\\n";
|
||||
msg += "For example to join #test123 channel on Freenode IRC server as MyBot and transport it into #slack_channel, the command would look like this:\\n";
|
||||
msg += "```.spectrum2 join.room MyBot #test123 adams.freenode.net #slack_channel```\\n";
|
||||
msg += "To get full list of available commands, executa `.spectrum2 help`\\n";
|
||||
m_rtm->sendMessage(m_ownerChannel, msg);
|
||||
}
|
||||
|
@ -261,9 +319,9 @@ void SlackSession::handleImOpen(HTTPRequest *req, bool ok, rapidjson::Document &
|
|||
msg += "1. At first, create new channel in which you want this Spectrum 2 transport to send the messages, or choose the existing one.\\n";
|
||||
msg += "2. Invite this Spectrum 2 bot into this channel.\\n";
|
||||
msg += "3. Configure the transportation between 3rd-party network and this channel by executing following command in this chat:\\n";
|
||||
msg += "```.spectrum2 join.room NameOfYourBotIn3rdPartyNetwork #3rdPartyRoom hostname_of_3rd_party_server #SlackChannel```\\n";
|
||||
msg += "For example to join #test123 channel on Freenode IRC server as MyBot and transport it into #slack_channel, the command would look like this:\\n";
|
||||
msg += "```.spectrum2 join.room MyBot #test123 adams.freenode.net #slack_channel```\\n";
|
||||
msg += "```.spectrum2 register 3rdPartyAccount 3rdPartyPassword #SlackChannel```\\n";
|
||||
msg += "For example to join XMPP account test@xmpp.tld and transport it into #slack_channel, the command would look like this:\\n";
|
||||
msg += "```.spectrum2 register test@xmpp.tld mypassword #slack_channel```\\n";
|
||||
msg += "To get full list of available commands, executa `.spectrum2 help`\\n";
|
||||
m_rtm->sendMessage(m_ownerChannel, msg);
|
||||
}
|
||||
|
@ -288,7 +346,7 @@ void SlackSession::handleImOpen(HTTPRequest *req, bool ok, rapidjson::Document &
|
|||
BOOST_FOREACH(const std::string &command, commands) {
|
||||
if (command.size() > 5) {
|
||||
LOG4CXX_INFO(logger, m_uinfo.jid << ": Sending command from storage: " << command);
|
||||
handleMessageReceived(m_ownerChannel, "owner", command, true);
|
||||
handleMessageReceived(m_ownerChannel, "owner", command, "", true);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -38,6 +38,7 @@ class StorageBackend;
|
|||
class HTTPRequest;
|
||||
class SlackRTM;
|
||||
class SlackAPI;
|
||||
class User;
|
||||
|
||||
class SlackSession {
|
||||
public:
|
||||
|
@ -49,9 +50,15 @@ class SlackSession {
|
|||
|
||||
void sendMessage(boost::shared_ptr<Swift::Message> message);
|
||||
|
||||
void setPurpose(const std::string &purpose);
|
||||
|
||||
void setUser(User *user) {
|
||||
m_user = user;
|
||||
}
|
||||
|
||||
private:
|
||||
void handleRTMStarted();
|
||||
void handleMessageReceived(const std::string &channel, const std::string &user, const std::string &message, bool quiet);
|
||||
void handleMessageReceived(const std::string &channel, const std::string &user, const std::string &message, const std::string &ts, bool quiet);
|
||||
void handleImOpen(HTTPRequest *req, bool ok, rapidjson::Document &resp, const std::string &data);
|
||||
|
||||
void handleJoinMessage(const std::string &message, std::vector<std::string> &args, bool quiet = false);
|
||||
|
@ -68,6 +75,7 @@ class SlackSession {
|
|||
std::map<std::string, std::string> m_jid2channel;
|
||||
std::map<std::string, std::string> m_channel2jid;
|
||||
std::string m_slackChannel;
|
||||
User *m_user;
|
||||
};
|
||||
|
||||
}
|
||||
|
|
|
@ -45,6 +45,7 @@ SlackUser::SlackUser(const Swift::JID &jid, UserInfo &userInfo, Component *compo
|
|||
m_userInfo = userInfo;
|
||||
|
||||
m_session = static_cast<SlackUserManager *>(userManager)->moveTempSession(m_jid.toString());
|
||||
m_session->setUser(this);
|
||||
}
|
||||
|
||||
SlackUser::~SlackUser(){
|
||||
|
|
|
@ -313,7 +313,7 @@ void Config::updateBackendConfig(const std::string &backendConfig) {
|
|||
options_description opts("Backend options");
|
||||
opts.add_options()
|
||||
("registration.needPassword", value<bool>()->default_value(true), "")
|
||||
("registration.needRegistration", value<bool>()->default_value(false), "")
|
||||
("registration.needRegistration", value<bool>()->default_value(true), "")
|
||||
("registration.extraField", value<std::vector<std::string> >()->multitoken(), "")
|
||||
("features.receipts", value<bool>()->default_value(false), "")
|
||||
("features.muc", value<bool>()->default_value(false), "")
|
||||
|
|
|
@ -1,22 +1,31 @@
|
|||
#include "transport/HTTPRequestQueue.h"
|
||||
#include "transport/HTTPRequest.h"
|
||||
#include "transport/Transport.h"
|
||||
|
||||
namespace Transport {
|
||||
|
||||
DEFINE_LOGGER(logger, "HTTPRequestQueue")
|
||||
|
||||
HTTPRequestQueue::HTTPRequestQueue(int delay) {
|
||||
HTTPRequestQueue::HTTPRequestQueue(Component *component, int delay) {
|
||||
m_delay = delay;
|
||||
m_processing = false;
|
||||
|
||||
m_queueTimer = component->getNetworkFactories()->getTimerFactory()->createTimer(500);
|
||||
m_queueTimer->onTick.connect(boost::bind(&HTTPRequestQueue::sendNextRequest, this));
|
||||
}
|
||||
|
||||
HTTPRequestQueue::~HTTPRequestQueue() {
|
||||
|
||||
m_queueTimer->stop();
|
||||
}
|
||||
|
||||
void HTTPRequestQueue::handleRequestFinished() {
|
||||
m_queueTimer->start();
|
||||
}
|
||||
|
||||
void HTTPRequestQueue::sendNextRequest() {
|
||||
if (m_queue.empty()) {
|
||||
m_processing = false;
|
||||
m_queueTimer->stop();
|
||||
return;
|
||||
}
|
||||
|
||||
|
@ -26,7 +35,7 @@ void HTTPRequestQueue::sendNextRequest() {
|
|||
|
||||
HTTPRequest *req = m_queue.front();
|
||||
m_queue.pop();
|
||||
req->onRequestFinished.connect(boost::bind(&HTTPRequestQueue::sendNextRequest, this));
|
||||
req->onRequestFinished.connect(boost::bind(&HTTPRequestQueue::handleRequestFinished, this));
|
||||
req->execute();
|
||||
}
|
||||
|
||||
|
|
|
@ -66,7 +66,7 @@ Transport::PresenceOracle *Component::getPresenceOracle() {
|
|||
}
|
||||
|
||||
bool Component::inServerMode() {
|
||||
return CONFIG_BOOL_DEFAULTED(m_config, "service.server_mode", true);
|
||||
return CONFIG_BOOL_DEFAULTED(m_config, "service.server_mode", false);
|
||||
}
|
||||
|
||||
void Component::start() {
|
||||
|
|
|
@ -23,6 +23,8 @@
|
|||
#include "transport/Util.h"
|
||||
#include "transport/Logging.h"
|
||||
|
||||
#include "Swiften/StringCodecs/Hexify.h"
|
||||
|
||||
#include <boost/foreach.hpp>
|
||||
#include <boost/make_shared.hpp>
|
||||
#include <map>
|
||||
|
@ -131,10 +133,16 @@ void WebSocketClient::handleDataRead(boost::shared_ptr<Swift::SafeByteArray> dat
|
|||
|
||||
while (m_buffer.size() > 0) {
|
||||
if (m_buffer.size() >= 2) {
|
||||
LOG4CXX_INFO(logger, "BUFFER: '" << m_buffer << "'");
|
||||
LOG4CXX_INFO(logger, "BUFFER: '" << Swift::Hexify::hexify(Swift::createByteArray(m_buffer)) << "'");
|
||||
uint8_t opcode = *((uint8_t *) &m_buffer[0]) & 0xf;
|
||||
uint8_t size7 = *((uint8_t *) &m_buffer[1]);
|
||||
uint8_t size7 = *((uint8_t *) &m_buffer[1]) & 127;
|
||||
bool mask = *((uint8_t *) &m_buffer[1]) & 128;
|
||||
uint16_t size16 = 0;
|
||||
int header_size = 2;
|
||||
LOG4CXX_INFO(logger, "OPCODE: " << (int) opcode);
|
||||
LOG4CXX_INFO(logger, "SIZE7: " << (int) size7);
|
||||
LOG4CXX_INFO(logger, "MASK: " << (int) mask);
|
||||
if (size7 == 126) {
|
||||
if (m_buffer.size() >= 4) {
|
||||
size16 = *((uint16_t *) &m_buffer[2]);
|
||||
|
|
Loading…
Add table
Reference in a new issue