Files
@ 483eedf5c785
Branch filter:
Location: libtransport.git/backends/twitter/TwitterPlugin.h
483eedf5c785
4.6 KiB
text/plain
Follow/Unfollow users in Multiple contact mode
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 | #ifndef TWITTER_PLUGIN
#define TWITTER_PLUGIN
#include "transport/config.h"
#include "transport/networkplugin.h"
#include "transport/logging.h"
#include "transport/sqlite3backend.h"
#include "transport/mysqlbackend.h"
#include "transport/pqxxbackend.h"
#include "transport/storagebackend.h"
#include "Swiften/Swiften.h"
#include "unistd.h"
#include "signal.h"
#include "sys/wait.h"
#include "sys/signal.h"
#include <boost/algorithm/string.hpp>
#include <boost/signal.hpp>
#include <boost/thread.hpp>
#include <boost/thread/mutex.hpp>
#include "twitcurl.h"
#include "TwitterResponseParser.h"
#include <iostream>
#include <sstream>
#include <map>
#include <vector>
#include <queue>
#include <set>
#include <cstdio>
#include "ThreadPool.h"
using namespace boost::filesystem;
using namespace boost::program_options;
using namespace Transport;
#define STR(x) (std::string("(") + x.from + ", " + x.to + ", " + x.message + ")")
class TwitterPlugin;
extern TwitterPlugin *np;
extern Swift::SimpleEventLoop *loop_; // Event Loop
class TwitterPlugin : public NetworkPlugin {
public:
Swift::BoostNetworkFactories *m_factories;
Swift::BoostIOServiceThread m_boostIOServiceThread;
boost::shared_ptr<Swift::Connection> m_conn;
Swift::Timer::ref tweet_timer;
Swift::Timer::ref message_timer;
StorageBackend *storagebackend;
TwitterPlugin(Config *config, Swift::SimpleEventLoop *loop, StorageBackend *storagebackend, const std::string &host, int port);
~TwitterPlugin();
// Send data to NetworkPlugin server
void sendData(const std::string &string);
// Receive date from the NetworkPlugin server and invoke the appropirate payload handler (implement in the NetworkPlugin class)
void _handleDataRead(boost::shared_ptr<Swift::SafeByteArray> data);
// User trying to login into his twitter account
void handleLoginRequest(const std::string &user, const std::string &legacyName, const std::string &password);
// User logging out
void handleLogoutRequest(const std::string &user, const std::string &legacyName);
void handleMessageSendRequest(const std::string &user, const std::string &legacyName, const std::string &message, const std::string &xhtml = "");
void handleBuddyUpdatedRequest(const std::string &user, const std::string &buddyName, const std::string &alias, const std::vector<std::string> &groups);
void handleBuddyRemovedRequest(const std::string &user, const std::string &buddyName, const std::vector<std::string> &groups);
void pollForTweets();
void pollForDirectMessages();
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);
void initUserSession(const std::string user, const std::string password);
void OAuthFlowComplete(const std::string user, twitCurl *obj);
void pinExchangeComplete(const std::string user, const std::string OAuthAccessTokenKey, const std::string OAuthAccessTokenSecret);
void updateLastTweetID(const std::string user, const std::string ID);
std::string getMostRecentTweetID(const std::string user);
void updateLastDMID(const std::string user, const std::string ID);
std::string getMostRecentDMID(const std::string user);
/****************** Twitter Response handlers **************************************/
void populateRoster(std::string &user, std::vector<User> &friends, std::string &errMsg);
void displayFriendlist(std::string &user, std::vector<User> &friends, std::string &errMsg);
void displayTweets(std::string &user, std::string &userRequested, std::vector<Status> &tweets , std::string &errMsg);
void directMessageResponse(std::string &user, std::vector<DirectMessage> &messages, std::string &errMsg);
void createFriendResponse(std::string &user, std::string &frnd, std::string &errMsg);
void deleteFriendResponse(std::string &user, std::string &frnd, std::string &errMsg);
void RetweetResponse(std::string &user, std::string &errMsg);
/***********************************************************************************/
private:
enum status {NEW, WAITING_FOR_PIN, CONNECTED, DISCONNECTED};
enum mode {SINGLECONTACT, MULTIPLECONTACT, CHATROOM};
Config *config;
std::string consumerKey;
std::string consumerSecret;
std::string OAUTH_KEY;
std::string OAUTH_SECRET;
boost::mutex dblock, userlock;
ThreadPool *tp;
std::map<std::string, twitCurl*> sessions;
std::map<std::string, status> connectionState;
std::map<std::string, std::string> mostRecentTweetID;
std::map<std::string, std::string> mostRecentDirectMessageID;
std::set<std::string> onlineUsers;
mode twitterMode;
};
#endif
|