diff --git a/backends/twitter/Requests/DirectMessageRequest.cpp b/backends/twitter/Requests/DirectMessageRequest.cpp index cfbf210e..c9779ef0 100644 --- a/backends/twitter/Requests/DirectMessageRequest.cpp +++ b/backends/twitter/Requests/DirectMessageRequest.cpp @@ -19,11 +19,11 @@ void DirectMessageRequest::finalize() if(!success) { LOG4CXX_ERROR(logger, user << ": Error while sending directed message to " << username ); twitObj->getLastCurlError( replyMsg ); - callBack(user, messages, replyMsg); + callBack(user, username, messages, replyMsg); } else { std::string error = getErrorMessage(replyMsg); if(error.length()) LOG4CXX_ERROR(logger, user << " - " << error) else LOG4CXX_INFO(logger, user << " - " << replyMsg) - callBack(user, messages, error); + callBack(user, username, messages, error); } } diff --git a/backends/twitter/Requests/DirectMessageRequest.h b/backends/twitter/Requests/DirectMessageRequest.h index 5eb1d774..6ae27f5c 100644 --- a/backends/twitter/Requests/DirectMessageRequest.h +++ b/backends/twitter/Requests/DirectMessageRequest.h @@ -18,13 +18,13 @@ class DirectMessageRequest : public Thread std::string user; std::string username; std::string replyMsg; - boost::function< void (std::string&, std::vector&, std::string&) > callBack; + boost::function< void (std::string&, std::string &, std::vector&, std::string&) > callBack; std::vector messages; bool success; public: DirectMessageRequest(twitCurl *obj, const std::string &_user, const std::string & _username, const std::string &_data, - boost::function< void (std::string&, std::vector&, std::string&) > cb) { + boost::function< void (std::string&, std::string &, std::vector&, std::string&) > cb) { twitObj = obj->clone(); data = _data; user = _user; diff --git a/backends/twitter/Requests/OAuthFlow.cpp b/backends/twitter/Requests/OAuthFlow.cpp index 83ded843..8b77437d 100644 --- a/backends/twitter/Requests/OAuthFlow.cpp +++ b/backends/twitter/Requests/OAuthFlow.cpp @@ -9,6 +9,7 @@ void OAuthFlow::finalize() { if (!success) { LOG4CXX_ERROR(logger, "Error creating twitter authorization url!"); + np->handleMessage(user, "twitter-account", "Error creating twitter authorization url!"); np->handleLogoutRequest(user, username); } else { np->handleMessage(user, "twitter-account", std::string("Please visit the following link and authorize this application: ") + authUrl); diff --git a/backends/twitter/Requests/PINExchangeProcess.cpp b/backends/twitter/Requests/PINExchangeProcess.cpp index 66c6e5b8..e1b031bc 100644 --- a/backends/twitter/Requests/PINExchangeProcess.cpp +++ b/backends/twitter/Requests/PINExchangeProcess.cpp @@ -12,6 +12,7 @@ void PINExchangeProcess::finalize() { if(!success) { LOG4CXX_ERROR(logger, user << ": Error while exchanging PIN for Access Token!") + np->handleMessage(user, "twitter-account", "Error while exchanging PIN for Access Token!"); np->handleLogoutRequest(user, ""); } else { std::string replyMsg; diff --git a/backends/twitter/TwitterPlugin.cpp b/backends/twitter/TwitterPlugin.cpp index 75fd0834..d8a1af28 100644 --- a/backends/twitter/TwitterPlugin.cpp +++ b/backends/twitter/TwitterPlugin.cpp @@ -191,7 +191,7 @@ void TwitterPlugin::handleMessageSendRequest(const std::string &user, const std: else if(cmd[0] == '@') { std::string username = cmd.substr(1); tp->runAsThread(new DirectMessageRequest(sessions[user], user, username, data, - boost::bind(&TwitterPlugin::directMessageResponse, this, _1, _2, _3))); + boost::bind(&TwitterPlugin::directMessageResponse, this, _1, _2, _3, _4))); } else if(cmd == "#status") tp->runAsThread(new StatusUpdateRequest(sessions[user], user, data, boost::bind(&TwitterPlugin::statusUpdateResponse, this, _1, _2))); @@ -207,13 +207,14 @@ void TwitterPlugin::handleMessageSendRequest(const std::string &user, const std: boost::bind(&TwitterPlugin::RetweetResponse, this, _1, _2))); else if(twitterMode == CHATROOM) { std::string buddy = message.substr(0, message.find(":")); - if(buddy == "") { - handleMessage(user, adminLegacyName, "Unknown command! Type #help for a list of available commands.", adminNickName); - return; + if(chatroomBuddies[user].count(buddy) == 0) { + tp->runAsThread(new StatusUpdateRequest(sessions[user], user, message, + boost::bind(&TwitterPlugin::statusUpdateResponse, this, _1, _2))); + } else { + data = message.substr(message.find(":")+1); + tp->runAsThread(new DirectMessageRequest(sessions[user], user, buddy, data, + boost::bind(&TwitterPlugin::directMessageResponse, this, _1, _2, _3, _4))); } - data = message.substr(message.find(":")+1); - tp->runAsThread(new DirectMessageRequest(sessions[user], user, buddy, data, - boost::bind(&TwitterPlugin::directMessageResponse, this, _1, _2, _3))); } else handleMessage(user, adminLegacyName, "Unknown command! Type #help for a list of available commands.", adminNickName); } @@ -223,7 +224,7 @@ void TwitterPlugin::handleMessageSendRequest(const std::string &user, const std: if(twitterMode == CHATROOM) buddy = legacyName.substr(legacyName.find("/") + 1); if(legacyName != "twitter") { tp->runAsThread(new DirectMessageRequest(sessions[user], user, buddy, message, - boost::bind(&TwitterPlugin::directMessageResponse, this, _1, _2, _3))); + boost::bind(&TwitterPlugin::directMessageResponse, this, _1, _2, _3, _4))); } } } @@ -271,7 +272,7 @@ void TwitterPlugin::pollForDirectMessages() while(it != onlineUsers.end()) { std::string user = *it; tp->runAsThread(new DirectMessageRequest(sessions[user], user, "", mostRecentDirectMessageID[user], - boost::bind(&TwitterPlugin::directMessageResponse, this, _1, _2, _3))); + boost::bind(&TwitterPlugin::directMessageResponse, this, _1, _2, _3, _4))); it++; } message_timer->start(); @@ -423,8 +424,10 @@ void TwitterPlugin::populateRoster(std::string &user, std::vector &friends for(int i=0 ; i(), pbnetwork::STATUS_ONLINE); - else + else { handleParticipantChanged(user, friends[i].getScreenName(), adminLegacyName, 0, pbnetwork::STATUS_ONLINE); + chatroomBuddies[user].insert(friends[i].getScreenName()); + } } } else handleMessage(user, adminLegacyName, std::string("Error populating roster - ") + errMsg, adminNickName); @@ -451,25 +454,34 @@ void TwitterPlugin::displayTweets(std::string &user, std::string &userRequested, std::string timeline = ""; for(int i=0 ; i &messages, std::string &errMsg) +void TwitterPlugin::directMessageResponse(std::string &user, std::string &username, std::vector &messages, std::string &errMsg) { if(errMsg.length()) { handleMessage(user, adminLegacyName, std::string("Error while sending direct message! - ") + errMsg, adminNickName); return; } + + if(username != "") { + handleMessage(user, adminLegacyName, "Message delivered!", adminNickName); + return; + } if(!messages.size()) return; @@ -489,14 +501,17 @@ void TwitterPlugin::directMessageResponse(std::string &user, std::vector(), pbnetwork::STATUS_ONLINE); + } else if(twitterMode == CHATROOM) { + handleParticipantChanged(user, frnd, adminLegacyName, 0, pbnetwork::STATUS_ONLINE); + chatroomBuddies[user].insert(frnd); } } @@ -526,11 +542,14 @@ void TwitterPlugin::deleteFriendResponse(std::string &user, std::string &frnd, s if(errMsg.length()) { handleMessage(user, adminLegacyName, errMsg, adminNickName); return; - } if(twitterMode == SINGLECONTACT) { - handleMessage(user, adminLegacyName, std::string("You are not following ") + frnd + " anymore", adminNickName); - } else if(twitterMode == MULTIPLECONTACT) { - handleMessage(user, adminLegacyName, std::string("You are not following ") + frnd + " anymore", adminNickName); + } + + handleMessage(user, adminLegacyName, std::string("You are not following ") + frnd + " anymore", adminNickName); + if(twitterMode == MULTIPLECONTACT) { handleBuddyRemoved(user, frnd); + } else if (twitterMode == CHATROOM) { + handleParticipantChanged(user, frnd, adminLegacyName, 0, pbnetwork::STATUS_NONE); + chatroomBuddies[user].erase(frnd); } } diff --git a/backends/twitter/TwitterPlugin.h b/backends/twitter/TwitterPlugin.h index 13819a4f..8b378ac3 100644 --- a/backends/twitter/TwitterPlugin.h +++ b/backends/twitter/TwitterPlugin.h @@ -105,7 +105,7 @@ class TwitterPlugin : public NetworkPlugin { void populateRoster(std::string &user, std::vector &friends, std::string &errMsg); void displayFriendlist(std::string &user, std::vector &friends, std::string &errMsg); void displayTweets(std::string &user, std::string &userRequested, std::vector &tweets , std::string &errMsg); - void directMessageResponse(std::string &user, std::vector &messages, std::string &errMsg); + void directMessageResponse(std::string &user, std::string &username, std::vector &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); @@ -134,6 +134,7 @@ class TwitterPlugin : public NetworkPlugin { std::map mostRecentDirectMessageID; std::set onlineUsers; std::map nickName; + std::map< std::string,std::set > chatroomBuddies; mode twitterMode; };