diff --git a/TODO b/TODO index 73635382..27e2fd7b 100644 --- a/TODO +++ b/TODO @@ -37,6 +37,7 @@ registration for obvious reasons (no block yet, other nodes wouldn't accept the - Discuss and implement the acceptable level of spam per day (priorizing localization). -- +- Implement the mention forwarding mechanism discussed in the paper so user don't need to do polling +and can also be sure to receive all mentions. diff --git a/src/bitcoinrpc.cpp b/src/bitcoinrpc.cpp index e8218fdb..1279fbf5 100644 --- a/src/bitcoinrpc.cpp +++ b/src/bitcoinrpc.cpp @@ -246,6 +246,7 @@ static const CRPCCommand vRPCCommands[] = { "newdirectmsg", &newdirectmsg, false, true }, { "newrtmsg", &newrtmsg, false, true }, { "getposts", &getposts, false, true }, + { "getlocaldirectmessages", &getlocaldirectmessages, false, true }, { "setspammsg", &setspammsg, false, true }, { "getspammsg", &getspammsg, false, true }, { "follow", &follow, false, true }, @@ -1238,6 +1239,9 @@ Array RPCConvertValues(const std::string &strMethod, const std::vector 2) ConvertTo(params[2]); if (strMethod == "getposts" && n > 0) ConvertTo(params[0]); if (strMethod == "getposts" && n > 1) ConvertTo(params[1]); + if (strMethod == "getposts" && n > 2) ConvertTo(params[2]); + if (strMethod == "getlocaldirectmessages" && n > 1) ConvertTo(params[1]); + if (strMethod == "getlocaldirectmessages" && n > 2) ConvertTo(params[2]); if (strMethod == "follow" && n > 1) ConvertTo(params[1]); if (strMethod == "unfollow" && n > 1) ConvertTo(params[1]); if (strMethod == "listusernamespartial" && n > 1) ConvertTo(params[1]); diff --git a/src/bitcoinrpc.h b/src/bitcoinrpc.h index 60db29e3..2e40f9b3 100644 --- a/src/bitcoinrpc.h +++ b/src/bitcoinrpc.h @@ -198,6 +198,7 @@ extern json_spirit::Value newpostmsg(const json_spirit::Array& params, bool fHel extern json_spirit::Value newdirectmsg(const json_spirit::Array& params, bool fHelp); extern json_spirit::Value newrtmsg(const json_spirit::Array& params, bool fHelp); extern json_spirit::Value getposts(const json_spirit::Array& params, bool fHelp); +extern json_spirit::Value getlocaldirectmessages(const json_spirit::Array& params, bool fHelp); extern json_spirit::Value setspammsg(const json_spirit::Array& params, bool fHelp); extern json_spirit::Value getspammsg(const json_spirit::Array& params, bool fHelp); extern json_spirit::Value follow(const json_spirit::Array& params, bool fHelp); diff --git a/src/rpcmining.cpp b/src/rpcmining.cpp index 1caacd09..347825be 100644 --- a/src/rpcmining.cpp +++ b/src/rpcmining.cpp @@ -325,7 +325,7 @@ Value getblocktemplate(const Array& params, bool fHelp) */ entry.push_back(Pair("depends", deps)); - int index_in_template = i - 1; + //int index_in_template = i - 1; transactions.push_back(entry); } diff --git a/src/rpcwallet.cpp b/src/rpcwallet.cpp index ba6b9de3..7cde6dab 100644 --- a/src/rpcwallet.cpp +++ b/src/rpcwallet.cpp @@ -287,7 +287,7 @@ Value verifymessage(const Array& params, bool fHelp) void ListTransactions(const CWalletTx& wtx, const string& strAccount, int nMinDepth, bool fLong, Array& ret) { - bool fAllAccounts = (strAccount == string("*")); + //bool fAllAccounts = (strAccount == string("*")); // Sent //if ((fAllAccounts || strAccount == strSentAccount)) diff --git a/src/twister.cpp b/src/twister.cpp index 2d948d55..7c238d5b 100644 --- a/src/twister.cpp +++ b/src/twister.cpp @@ -592,8 +592,8 @@ bool processReceivedDM(lazy_entry const* post) LOCK(cs_twister); // store this dm in memory list, but prevent duplicates - std::list &dmsFromToUser = m_users[item.second.username].m_directmsg[n]; - std::list::const_iterator it; + std::vector &dmsFromToUser = m_users[item.second.username].m_directmsg[n]; + std::vector::const_iterator it; for( it = dmsFromToUser.begin(); it != dmsFromToUser.end(); ++it ) { if( stoDM.m_utcTime == (*it).m_utcTime && stoDM.m_text == (*it).m_text ) { @@ -1085,14 +1085,15 @@ Value newrtmsg(const Array& params, bool fHelp) Value getposts(const Array& params, bool fHelp) { - if (fHelp || (params.size() != 2)) + if (fHelp || params.size() < 2 || params.size() > 3) throw runtime_error( - "getposts [{\"username\":username,\"max_id\":max_id,\"since_id\":since_id},...]\n" + "getposts '[{\"username\":username,\"max_id\":max_id,\"since_id\":since_id},...]' [flags]\n" "get posts from users\n" - "max_id and since_id may be omited or -1"); + "max_id and since_id may be omited"); int count = params[0].get_int(); Array users = params[1].get_array(); + int flags = (params.size() > 2) ? params[2].get_int() : USERPOST_FLAG_RT; std::multimap postsByTime; @@ -1108,11 +1109,12 @@ Value getposts(const Array& params, bool fHelp) if( i->name_ == "since_id" ) since_id = i->value_.get_int(); } + LOCK(cs_twister); if( strUsername.size() && m_userTorrent.count(strUsername) && m_userTorrent[strUsername].is_valid() ){ std::vector pieces; - m_userTorrent[strUsername].get_pieces(pieces, count, max_id, since_id, USERPOST_FLAG_RT); + m_userTorrent[strUsername].get_pieces(pieces, count, max_id, since_id, flags); BOOST_FOREACH(string const& piece, pieces) { lazy_entry v; @@ -1164,6 +1166,57 @@ Value getposts(const Array& params, bool fHelp) return ret; } +Value getlocaldirectmessages(const Array& params, bool fHelp) +{ + if (fHelp || params.size() < 2 || params.size() > 3) + throw runtime_error( + "getlocaldirectmessages '[{\"username\":username,\"max_id\":max_id,\"since_id\":since_id},...]'\n" + "get decrypted direct messages sent/received by user \n" + "max_id and since_id may be omited. up to are returned for each remote user."); + + string strUsername = params[0].get_str(); + int count = params[1].get_int(); + Array remoteusers = params[2].get_array(); + + Object ret; + for( unsigned int u = 0; u < remoteusers.size(); u++ ) { + Object remoteUser = remoteusers[u].get_obj(); + string remoteUsername; + int max_id = std::numeric_limits::max(); + int since_id = -1; + + for (Object::const_iterator i = remoteUser.begin(); i != remoteUser.end(); ++i) { + if( i->name_ == "username" ) remoteUsername = i->value_.get_str(); + if( i->name_ == "max_id" ) max_id = i->value_.get_int(); + if( i->name_ == "since_id" ) since_id = i->value_.get_int(); + } + + LOCK(cs_twister); + if( remoteUsername.size() && m_users.count(strUsername) && + m_users[strUsername].m_directmsg.count(remoteUsername) ){ + std::vector &dmsFromToUser = m_users[strUsername].m_directmsg[remoteUsername]; + max_id = std::min( max_id, (int)dmsFromToUser.size()-1); + since_id = std::max( since_id, max_id - count ); + + Array userMsgs; + for( int i = std::max(since_id+1,0); i <= max_id; i++) { + Object dmObj; + dmObj.push_back(Pair("id",i)); + dmObj.push_back(Pair("time",dmsFromToUser.at(i).m_utcTime)); + dmObj.push_back(Pair("text",dmsFromToUser.at(i).m_text)); + dmObj.push_back(Pair("fromMe",dmsFromToUser.at(i).m_fromMe)); + userMsgs.push_back(dmObj); + } + if( userMsgs.size() ) { + ret.push_back(Pair(remoteUsername,userMsgs)); + } + } + } + + return ret; +} + + Value setspammsg(const Array& params, bool fHelp) { if (fHelp || (params.size() != 2)) diff --git a/src/twister_utils.cpp b/src/twister_utils.cpp index 7fb9ec47..9e066b71 100644 --- a/src/twister_utils.cpp +++ b/src/twister_utils.cpp @@ -148,7 +148,7 @@ int saveUserData(std::string const& filename, std::map con if( udata.m_directmsg.size() ) { entry &dmDict = userData["dm"]; - std::map >::const_iterator j; + std::map >::const_iterator j; for (j = udata.m_directmsg.begin(); j != udata.m_directmsg.end(); ++j) { entry &dmList = dmDict[j->first]; BOOST_FOREACH( StoredDirectMsg const &stoDm, j->second) { diff --git a/src/twister_utils.h b/src/twister_utils.h index 7eaa9945..462f3e75 100644 --- a/src/twister_utils.h +++ b/src/twister_utils.h @@ -19,7 +19,7 @@ struct StoredDirectMsg { struct UserData { std::set m_following; // m_directmsg key is the other username - std::map > m_directmsg; + std::map > m_directmsg; };