Polling users home timeline
This commit is contained in:
parent
e9891aa200
commit
f8a183661c
3 changed files with 30 additions and 1 deletions
|
@ -2,8 +2,14 @@
|
|||
DEFINE_LOGGER(logger, "TimelineRequest")
|
||||
void TimelineRequest::run()
|
||||
{
|
||||
|
||||
bool success;
|
||||
|
||||
if(userRequested != "") success = twitObj->timelineUserGet(false, false, 20, userRequested, false);
|
||||
else success = twitObj->timelineHomeGet();
|
||||
|
||||
replyMsg = "";
|
||||
if( twitObj->timelineUserGet(false, false, 20, userRequested, false) ) {
|
||||
if(success) {
|
||||
LOG4CXX_INFO(logger, "Sending timeline request for user " << user)
|
||||
|
||||
while(replyMsg.length() == 0) {
|
||||
|
|
|
@ -33,6 +33,10 @@ TwitterPlugin::TwitterPlugin(Config *config, Swift::SimpleEventLoop *loop, Stora
|
|||
|
||||
tp = new ThreadPool(loop_, 10);
|
||||
|
||||
m_timer = m_factories->getTimerFactory()->createTimer(60000);
|
||||
m_timer->onTick.connect(boost::bind(&TwitterPlugin::pollForTweets, this));
|
||||
m_timer->start();
|
||||
|
||||
LOG4CXX_INFO(logger, "Starting the plugin.");
|
||||
}
|
||||
|
||||
|
@ -95,6 +99,7 @@ void TwitterPlugin::handleLogoutRequest(const std::string &user, const std::stri
|
|||
delete sessions[user];
|
||||
sessions[user] = NULL;
|
||||
connectionState[user] = DISCONNECTED;
|
||||
onlineUsers.erase(user);
|
||||
}
|
||||
|
||||
|
||||
|
@ -134,6 +139,19 @@ void TwitterPlugin::handleBuddyRemovedRequest(const std::string &user, const std
|
|||
}
|
||||
|
||||
|
||||
void TwitterPlugin::pollForTweets()
|
||||
{
|
||||
boost::mutex::scoped_lock lock(userlock);
|
||||
std::set<std::string>::iterator it = onlineUsers.begin();
|
||||
while(it != onlineUsers.end()) {
|
||||
std::string user = *it;
|
||||
tp->runAsThread(new TimelineRequest(np, sessions[user], user, ""));
|
||||
it++;
|
||||
}
|
||||
m_timer->start();
|
||||
}
|
||||
|
||||
|
||||
bool TwitterPlugin::getUserOAuthKeyAndSecret(const std::string user, std::string &key, std::string &secret)
|
||||
{
|
||||
boost::mutex::scoped_lock lock(dblock);
|
||||
|
@ -218,4 +236,5 @@ void TwitterPlugin::pinExchangeComplete(const std::string user, const std::strin
|
|||
sessions[user]->getOAuth().setOAuthTokenKey( OAuthAccessTokenKey );
|
||||
sessions[user]->getOAuth().setOAuthTokenSecret( OAuthAccessTokenSecret );
|
||||
connectionState[user] = CONNECTED;
|
||||
onlineUsers.insert(user);
|
||||
}
|
||||
|
|
|
@ -48,6 +48,7 @@ class TwitterPlugin : public NetworkPlugin {
|
|||
Swift::BoostNetworkFactories *m_factories;
|
||||
Swift::BoostIOServiceThread m_boostIOServiceThread;
|
||||
boost::shared_ptr<Swift::Connection> m_conn;
|
||||
Swift::Timer::ref m_timer;
|
||||
StorageBackend *storagebackend;
|
||||
|
||||
TwitterPlugin(Config *config, Swift::SimpleEventLoop *loop, StorageBackend *storagebackend, const std::string &host, int port);
|
||||
|
@ -71,6 +72,8 @@ class TwitterPlugin : public NetworkPlugin {
|
|||
|
||||
void handleBuddyRemovedRequest(const std::string &user, const std::string &buddyName, const std::vector<std::string> &groups);
|
||||
|
||||
void pollForTweets();
|
||||
|
||||
bool getUserOAuthKeyAndSecret(const std::string user, std::string &key, std::string &secret);
|
||||
|
||||
bool storeUserOAuthKeyAndSecret(const std::string user, const std::string OAuthKey, const std::string OAuthSecret);
|
||||
|
@ -96,6 +99,7 @@ class TwitterPlugin : public NetworkPlugin {
|
|||
ThreadPool *tp;
|
||||
std::map<std::string, twitCurl*> sessions;
|
||||
std::map<std::string, status> connectionState;
|
||||
std::set<std::string> onlineUsers;
|
||||
};
|
||||
|
||||
#endif
|
||||
|
|
Loading…
Add table
Reference in a new issue