mirror of
https://github.com/twisterarmy/twister-core.git
synced 2025-02-08 21:04:14 +00:00
getlocaldirectmessages: get decrypted direct messages sent/received by user
This commit is contained in:
parent
2e9ac3d58a
commit
f75fc11274
3
TODO
3
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).
|
- 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.
|
||||||
|
|
||||||
|
|
||||||
|
@ -246,6 +246,7 @@ static const CRPCCommand vRPCCommands[] =
|
|||||||
{ "newdirectmsg", &newdirectmsg, false, true },
|
{ "newdirectmsg", &newdirectmsg, false, true },
|
||||||
{ "newrtmsg", &newrtmsg, false, true },
|
{ "newrtmsg", &newrtmsg, false, true },
|
||||||
{ "getposts", &getposts, false, true },
|
{ "getposts", &getposts, false, true },
|
||||||
|
{ "getlocaldirectmessages", &getlocaldirectmessages, false, true },
|
||||||
{ "setspammsg", &setspammsg, false, true },
|
{ "setspammsg", &setspammsg, false, true },
|
||||||
{ "getspammsg", &getspammsg, false, true },
|
{ "getspammsg", &getspammsg, false, true },
|
||||||
{ "follow", &follow, false, true },
|
{ "follow", &follow, false, true },
|
||||||
@ -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 == "newrtmsg" && n > 2) ConvertTo<Object>(params[2]);
|
||||||
if (strMethod == "getposts" && n > 0) ConvertTo<boost::int64_t>(params[0]);
|
if (strMethod == "getposts" && n > 0) ConvertTo<boost::int64_t>(params[0]);
|
||||||
if (strMethod == "getposts" && n > 1) ConvertTo<Array>(params[1]);
|
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 == "follow" && n > 1) ConvertTo<Array>(params[1]);
|
||||||
if (strMethod == "unfollow" && 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]);
|
if (strMethod == "listusernamespartial" && n > 1) ConvertTo<boost::int64_t>(params[1]);
|
||||||
|
@ -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 newdirectmsg(const json_spirit::Array& params, bool fHelp);
|
||||||
extern json_spirit::Value newrtmsg(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 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 setspammsg(const json_spirit::Array& params, bool fHelp);
|
||||||
extern json_spirit::Value getspammsg(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);
|
extern json_spirit::Value follow(const json_spirit::Array& params, bool fHelp);
|
||||||
|
@ -325,7 +325,7 @@ Value getblocktemplate(const Array& params, bool fHelp)
|
|||||||
*/
|
*/
|
||||||
entry.push_back(Pair("depends", deps));
|
entry.push_back(Pair("depends", deps));
|
||||||
|
|
||||||
int index_in_template = i - 1;
|
//int index_in_template = i - 1;
|
||||||
|
|
||||||
transactions.push_back(entry);
|
transactions.push_back(entry);
|
||||||
}
|
}
|
||||||
|
@ -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)
|
void ListTransactions(const CWalletTx& wtx, const string& strAccount, int nMinDepth, bool fLong, Array& ret)
|
||||||
{
|
{
|
||||||
bool fAllAccounts = (strAccount == string("*"));
|
//bool fAllAccounts = (strAccount == string("*"));
|
||||||
|
|
||||||
// Sent
|
// Sent
|
||||||
//if ((fAllAccounts || strAccount == strSentAccount))
|
//if ((fAllAccounts || strAccount == strSentAccount))
|
||||||
|
@ -592,8 +592,8 @@ bool processReceivedDM(lazy_entry const* post)
|
|||||||
|
|
||||||
LOCK(cs_twister);
|
LOCK(cs_twister);
|
||||||
// store this dm in memory list, but prevent duplicates
|
// store this dm in memory list, but prevent duplicates
|
||||||
std::list<StoredDirectMsg> &dmsFromToUser = m_users[item.second.username].m_directmsg[n];
|
std::vector<StoredDirectMsg> &dmsFromToUser = m_users[item.second.username].m_directmsg[n];
|
||||||
std::list<StoredDirectMsg>::const_iterator it;
|
std::vector<StoredDirectMsg>::const_iterator it;
|
||||||
for( it = dmsFromToUser.begin(); it != dmsFromToUser.end(); ++it ) {
|
for( it = dmsFromToUser.begin(); it != dmsFromToUser.end(); ++it ) {
|
||||||
if( stoDM.m_utcTime == (*it).m_utcTime &&
|
if( stoDM.m_utcTime == (*it).m_utcTime &&
|
||||||
stoDM.m_text == (*it).m_text ) {
|
stoDM.m_text == (*it).m_text ) {
|
||||||
@ -1085,14 +1085,15 @@ Value newrtmsg(const Array& params, bool fHelp)
|
|||||||
|
|
||||||
Value getposts(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(
|
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"
|
"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();
|
int count = params[0].get_int();
|
||||||
Array users = params[1].get_array();
|
Array users = params[1].get_array();
|
||||||
|
int flags = (params.size() > 2) ? params[2].get_int() : USERPOST_FLAG_RT;
|
||||||
|
|
||||||
std::multimap<int64,entry> postsByTime;
|
std::multimap<int64,entry> postsByTime;
|
||||||
|
|
||||||
@ -1108,11 +1109,12 @@ Value getposts(const Array& params, bool fHelp)
|
|||||||
if( i->name_ == "since_id" ) since_id = i->value_.get_int();
|
if( i->name_ == "since_id" ) since_id = i->value_.get_int();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
LOCK(cs_twister);
|
||||||
if( strUsername.size() && m_userTorrent.count(strUsername) &&
|
if( strUsername.size() && m_userTorrent.count(strUsername) &&
|
||||||
m_userTorrent[strUsername].is_valid() ){
|
m_userTorrent[strUsername].is_valid() ){
|
||||||
|
|
||||||
std::vector<std::string> pieces;
|
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) {
|
BOOST_FOREACH(string const& piece, pieces) {
|
||||||
lazy_entry v;
|
lazy_entry v;
|
||||||
@ -1164,6 +1166,57 @@ Value getposts(const Array& params, bool fHelp)
|
|||||||
return ret;
|
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)
|
Value setspammsg(const Array& params, bool fHelp)
|
||||||
{
|
{
|
||||||
if (fHelp || (params.size() != 2))
|
if (fHelp || (params.size() != 2))
|
||||||
|
@ -148,7 +148,7 @@ int saveUserData(std::string const& filename, std::map<std::string,UserData> con
|
|||||||
if( udata.m_directmsg.size() ) {
|
if( udata.m_directmsg.size() ) {
|
||||||
entry &dmDict = userData["dm"];
|
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) {
|
for (j = udata.m_directmsg.begin(); j != udata.m_directmsg.end(); ++j) {
|
||||||
entry &dmList = dmDict[j->first];
|
entry &dmList = dmDict[j->first];
|
||||||
BOOST_FOREACH( StoredDirectMsg const &stoDm, j->second) {
|
BOOST_FOREACH( StoredDirectMsg const &stoDm, j->second) {
|
||||||
|
@ -19,7 +19,7 @@ struct StoredDirectMsg {
|
|||||||
struct UserData {
|
struct UserData {
|
||||||
std::set<std::string> m_following;
|
std::set<std::string> m_following;
|
||||||
// m_directmsg key is the other username
|
// 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…
x
Reference in New Issue
Block a user