1010#include " Requests/DestroyFriendRequest.h"
1111#include " Requests/RetweetRequest.h"
1212#include " Requests/ProfileImageRequest.h"
13- #include " Swiften/StringCodecs/Hexify.h"
1413
1514DEFINE_LOGGER (logger, " Twitter Backend" );
1615
1716TwitterPlugin *np = NULL ;
18- Swift::SimpleEventLoop *loop_; // Event Loop
1917
2018const std::string OLD_APP_KEY = " PCWAdQpyyR12ezp2fVwEhw" ;
2119const std::string OLD_APP_SECRET = " EveLmCXJIg2R7BTCpm6OWV8YyX49nI0pxnYXh7JMvDg" ;
@@ -35,7 +33,7 @@ static int cmp(std::string a, std::string b)
3533}
3634
3735
38- TwitterPlugin::TwitterPlugin (Config *config, Swift::SimpleEventLoop *loop, StorageBackend *storagebackend, const std::string &host, int port) : NetworkPlugin()
36+ TwitterPlugin::TwitterPlugin (Config *config, StorageBackend *storagebackend, const std::string &host, int port) : NetworkPlugin()
3937{
4038 this ->config = config;
4139 this ->storagebackend = storagebackend;
@@ -68,56 +66,24 @@ TwitterPlugin::TwitterPlugin(Config *config, Swift::SimpleEventLoop *loop, Stora
6866 OAUTH_SECRET = " twitter_oauth_secret" ;
6967 MODE = " mode" ;
7068
71- m_factories = new Swift::BoostNetworkFactories (loop);
72- m_conn = m_factories->getConnectionFactory ()->createConnection ();
73- m_conn->onDataRead .connect (boost::bind (&TwitterPlugin::_handleDataRead, this , _1));
74- m_conn->connect (Swift::HostAddressPort (*(Swift::HostAddress::fromString (host)), port));
75-
76- tp = new ThreadPool (loop_, 10 );
77-
7869 LOG4CXX_INFO (logger, " Fetch timeout is set to " << CONFIG_INT_DEFAULTED (config, " twitter.fetch_timeout" , 90000 ));
79- tweet_timer = m_factories->getTimerFactory ()->createTimer (CONFIG_INT_DEFAULTED (config, " twitter.fetch_timeout" , 90000 ));
80- message_timer = m_factories->getTimerFactory ()->createTimer (CONFIG_INT_DEFAULTED (config, " twitter.fetch_timeout" , 90000 ));
70+ io = std::make_unique<boost::asio::io_service>();
71+ tweet_timer = std::make_unique<boost::asio::deadline_timer>(io, boost::posix_time::seconds (CONFIG_INT_DEFAULTED (config, " twitter.fetch_timeout" , 90000 )));
72+ message_timer = std::make_unique<boost::asio::deadline_timer>(io, boost::posix_time::seconds (CONFIG_INT_DEFAULTED (config, " twitter.fetch_timeout" , 90000 )));
8173
82- tweet_timer->onTick .connect (boost::bind (&TwitterPlugin::pollForTweets, this ));
83- // message_timer->onTick.connect(boost::bind(&TwitterPlugin::pollForDirectMessages, this));
84-
85- tweet_timer->start ();
86- message_timer->start ();
87- cryptoProvider = std::shared_ptr<Swift::CryptoProvider>(Swift::PlatformCryptoProvider::create ());
74+ tweet_timer->async_wait (boost::bind (&TwitterPlugin::pollForTweets, this ));
75+ // message_timer->async_wait(boost::bind(&TwitterPlugin::pollForDirectMessages, this));
8876
8977
9078 LOG4CXX_INFO (logger, " Starting the plugin." );
79+ connect (host, std::to_string (port));
9180}
9281
9382TwitterPlugin::~TwitterPlugin ()
9483{
9584 delete storagebackend;
9685 std::set<std::string>::iterator it;
9786 for (it = onlineUsers.begin () ; it != onlineUsers.end () ; it++) delete userdb[*it].sessions ;
98- delete tp;
99- }
100-
101- // Send data to NetworkPlugin server
102- void TwitterPlugin::sendData (const std::string &string)
103- {
104- m_conn->write (Swift::createSafeByteArray (string));
105- }
106-
107- // Receive date from the NetworkPlugin server and invoke the appropirate payload handler (implement in the NetworkPlugin class)
108- void TwitterPlugin::_handleDataRead (std::shared_ptr<Swift::SafeByteArray> data)
109- {
110- if (m_firstPing) {
111- m_firstPing = false ;
112- // Users can join the network without registering if we allow
113- // one user to connect multiple IRC networks.
114- NetworkPlugin::PluginConfig cfg;
115- cfg.setNeedPassword (false );
116- sendConfig (cfg);
117- }
118-
119- std::string d (data->begin (), data->end ());
120- handleDataRead (d);
12187}
12288
12389// User trying to login into his twitter account
0 commit comments