mirror of
https://github.com/twisterarmy/twister-core.git
synced 2025-01-10 23:07:52 +00:00
follow/unfollow rpc
This commit is contained in:
parent
a32bfec78f
commit
ac55203421
@ -242,6 +242,10 @@ static const CRPCCommand vRPCCommands[] =
|
||||
{ "newrtmsg", &newrtmsg, false, true },
|
||||
{ "getposts", &getposts, false, true },
|
||||
{ "setspammsg", &setspammsg, false, true },
|
||||
{ "getspammsg", &getspammsg, false, true },
|
||||
{ "follow", &follow, false, true },
|
||||
{ "unfollow", &unfollow, false, true },
|
||||
{ "getfollowing", &getfollowing, false, true },
|
||||
};
|
||||
|
||||
CRPCTable::CRPCTable()
|
||||
@ -1188,6 +1192,8 @@ 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 == "follow" && n > 0) ConvertTo<Array>(params[0]);
|
||||
if (strMethod == "unfollow" && n > 0) ConvertTo<Array>(params[0]);
|
||||
|
||||
return params;
|
||||
}
|
||||
|
@ -199,5 +199,9 @@ extern json_spirit::Value newdirectmsg(const json_spirit::Array& params, bool fH
|
||||
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 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);
|
||||
extern json_spirit::Value unfollow(const json_spirit::Array& params, bool fHelp);
|
||||
extern json_spirit::Value getfollowing(const json_spirit::Array& params, bool fHelp);
|
||||
|
||||
#endif
|
||||
|
@ -38,6 +38,7 @@ static CCriticalSection cs_dhtgetMap;
|
||||
static map<sha1_hash, alert_manager*> m_dhtgetMap;
|
||||
static map<std::string, bool> m_specialResources;
|
||||
static map<std::string, torrent_handle> m_userTorrent;
|
||||
static std::set<std::string> m_following;
|
||||
|
||||
sha1_hash dhtTargetHash(std::string const &username, std::string const &resource, std::string const &type)
|
||||
{
|
||||
@ -1153,3 +1154,81 @@ Value setspammsg(const Array& params, bool fHelp)
|
||||
|
||||
return Value();
|
||||
}
|
||||
|
||||
Value getspammsg(const Array& params, bool fHelp)
|
||||
{
|
||||
if (fHelp || (params.size() != 0))
|
||||
throw runtime_error(
|
||||
"getspammsg\n"
|
||||
"get spam message attached to generated blocks");
|
||||
|
||||
Array ret;
|
||||
ret.push_back(strSpamUser);
|
||||
ret.push_back(strSpamMessage);
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
||||
Value follow(const Array& params, bool fHelp)
|
||||
{
|
||||
if (fHelp || (params.size() != 1))
|
||||
throw runtime_error(
|
||||
"follow [username1,username2,...]\n"
|
||||
"start following users");
|
||||
|
||||
Array users = params[0].get_array();
|
||||
|
||||
for( unsigned int u = 0; u < users.size(); u++ ) {
|
||||
string username = users[u].get_str();
|
||||
|
||||
if( !m_following.count(username) ) {
|
||||
if( m_userTorrent.count(username) ) {
|
||||
// perhaps torrent is already initialized due to neighborhood
|
||||
m_following.insert(username);
|
||||
} else {
|
||||
torrent_handle h = startTorrentUser(username);
|
||||
if( h.is_valid() ) {
|
||||
m_following.insert(username);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return Value();
|
||||
}
|
||||
|
||||
Value unfollow(const Array& params, bool fHelp)
|
||||
{
|
||||
if (fHelp || (params.size() != 1))
|
||||
throw runtime_error(
|
||||
"unfollow [username1,username2,...]\n"
|
||||
"stop following users");
|
||||
|
||||
Array users = params[0].get_array();
|
||||
|
||||
for( unsigned int u = 0; u < users.size(); u++ ) {
|
||||
string username = users[u].get_str();
|
||||
|
||||
if( m_following.count(username) ) {
|
||||
m_following.erase(username);
|
||||
}
|
||||
}
|
||||
|
||||
return Value();
|
||||
}
|
||||
|
||||
Value getfollowing(const Array& params, bool fHelp)
|
||||
{
|
||||
if (fHelp || (params.size() != 0))
|
||||
throw runtime_error(
|
||||
"getfollowing\n"
|
||||
"get list of users we follow");
|
||||
|
||||
Array ret;
|
||||
BOOST_FOREACH(string username, m_following) {
|
||||
ret.push_back(username);
|
||||
}
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user