10
10
#include " Requests/DestroyFriendRequest.h"
11
11
#include " Requests/RetweetRequest.h"
12
12
#include " Requests/ProfileImageRequest.h"
13
- #include " Swiften/StringCodecs/Hexify.h"
14
13
15
14
DEFINE_LOGGER (logger, " Twitter Backend" );
16
15
17
16
TwitterPlugin *np = NULL ;
18
- Swift::SimpleEventLoop *loop_; // Event Loop
19
17
20
18
const std::string OLD_APP_KEY = " PCWAdQpyyR12ezp2fVwEhw" ;
21
19
const std::string OLD_APP_SECRET = " EveLmCXJIg2R7BTCpm6OWV8YyX49nI0pxnYXh7JMvDg" ;
@@ -35,7 +33,7 @@ static int cmp(std::string a, std::string b)
35
33
}
36
34
37
35
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()
39
37
{
40
38
this ->config = config;
41
39
this ->storagebackend = storagebackend;
@@ -68,56 +66,24 @@ TwitterPlugin::TwitterPlugin(Config *config, Swift::SimpleEventLoop *loop, Stora
68
66
OAUTH_SECRET = " twitter_oauth_secret" ;
69
67
MODE = " mode" ;
70
68
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
-
78
69
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 )));
81
73
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));
88
76
89
77
90
78
LOG4CXX_INFO (logger, " Starting the plugin." );
79
+ connect (host, std::to_string (port));
91
80
}
92
81
93
82
TwitterPlugin::~TwitterPlugin ()
94
83
{
95
84
delete storagebackend;
96
85
std::set<std::string>::iterator it;
97
86
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);
121
87
}
122
88
123
89
// User trying to login into his twitter account
0 commit comments