Browse Source

getlocaldirectmessages: get decrypted direct messages sent/received by user

miguelfreitas
Miguel Freitas 11 years ago
parent
commit
f75fc11274
  1. 3
      TODO
  2. 4
      src/bitcoinrpc.cpp
  3. 1
      src/bitcoinrpc.h
  4. 2
      src/rpcmining.cpp
  5. 2
      src/rpcwallet.cpp
  6. 65
      src/twister.cpp
  7. 2
      src/twister_utils.cpp
  8. 2
      src/twister_utils.h

3
TODO

@ -37,6 +37,7 @@ registration for obvious reasons (no block yet, other nodes wouldn't accept the @@ -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.

4
src/bitcoinrpc.cpp

@ -246,6 +246,7 @@ static const CRPCCommand vRPCCommands[] = @@ -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<std::stri @@ -1238,6 +1239,9 @@ Array RPCConvertValues(const std::string &strMethod, const std::vector<std::stri
if (strMethod == "newrtmsg" && n > 2) ConvertTo<Object>(params[2]);
if (strMethod == "getposts" && n > 0) ConvertTo<boost::int64_t>(params[0]);
if (strMethod == "getposts" && n > 1) ConvertTo<Array>(params[1]);
if (strMethod == "getposts" && n > 2) ConvertTo<boost::int64_t>(params[2]);
if (strMethod == "getlocaldirectmessages" && n > 1) ConvertTo<boost::int64_t>(params[1]);
if (strMethod == "getlocaldirectmessages" && n > 2) ConvertTo<Array>(params[2]);
if (strMethod == "follow" && n > 1) ConvertTo<Array>(params[1]);
if (strMethod == "unfollow" && n > 1) ConvertTo<Array>(params[1]);
if (strMethod == "listusernamespartial" && n > 1) ConvertTo<boost::int64_t>(params[1]);

1
src/bitcoinrpc.h

@ -198,6 +198,7 @@ extern json_spirit::Value newpostmsg(const json_spirit::Array& params, bool fHel @@ -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);

2
src/rpcmining.cpp

@ -325,7 +325,7 @@ Value getblocktemplate(const Array& params, bool fHelp) @@ -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);
}

2
src/rpcwallet.cpp

@ -287,7 +287,7 @@ Value verifymessage(const Array& params, bool fHelp) @@ -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))

65
src/twister.cpp

@ -592,8 +592,8 @@ bool processReceivedDM(lazy_entry const* post) @@ -592,8 +592,8 @@ bool processReceivedDM(lazy_entry const* post)
LOCK(cs_twister);
// store this dm in memory list, but prevent duplicates
std::list<StoredDirectMsg> &dmsFromToUser = m_users[item.second.username].m_directmsg[n];
std::list<StoredDirectMsg>::const_iterator it;
std::vector<StoredDirectMsg> &dmsFromToUser = m_users[item.second.username].m_directmsg[n];
std::vector<StoredDirectMsg>::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) @@ -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 <count> [{\"username\":username,\"max_id\":max_id,\"since_id\":since_id},...]\n"
"getposts <count> '[{\"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<int64,entry> postsByTime;
@ -1108,11 +1109,12 @@ Value getposts(const Array& params, bool fHelp) @@ -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<std::string> 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) @@ -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 <localuser> <count_per_user> '[{\"username\":username,\"max_id\":max_id,\"since_id\":since_id},...]'\n"
"get decrypted direct messages sent/received by user <localuser>\n"
"max_id and since_id may be omited. up to <count_per_user> 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<int>::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<StoredDirectMsg> &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))

2
src/twister_utils.cpp

@ -148,7 +148,7 @@ int saveUserData(std::string const& filename, std::map<std::string,UserData> con @@ -148,7 +148,7 @@ int saveUserData(std::string const& filename, std::map<std::string,UserData> con
if( udata.m_directmsg.size() ) {
entry &dmDict = userData["dm"];
std::map<std::string, std::list<StoredDirectMsg> >::const_iterator j;
std::map<std::string, std::vector<StoredDirectMsg> >::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) {

2
src/twister_utils.h

@ -19,7 +19,7 @@ struct StoredDirectMsg { @@ -19,7 +19,7 @@ struct StoredDirectMsg {
struct UserData {
std::set<std::string> m_following;
// m_directmsg key is the other username
std::map<std::string, std::list<StoredDirectMsg> > m_directmsg;
std::map<std::string, std::vector<StoredDirectMsg> > m_directmsg;
};

Loading…
Cancel
Save