diff --git a/src/bitcoinrpc.cpp b/src/bitcoinrpc.cpp index 042217ed..392be102 100644 --- a/src/bitcoinrpc.cpp +++ b/src/bitcoinrpc.cpp @@ -1350,6 +1350,7 @@ Array RPCConvertValues(const std::string &strMethod, const std::vector 2) ConvertTo(params[2]); if (strMethod == "search" && n > 2) ConvertTo(params[2]); if (strMethod == "search" && n > 3) ConvertTo(params[3]); + if (strMethod == "listgroups" && n > 1) ConvertTo(params[1]); if (strMethod == "newgroupinvite" && n > 1) ConvertTo(params[1]); if (strMethod == "newgroupinvite" && n > 3) ConvertTo(params[3]); if (strMethod == "newgroupdescription" && n > 1) ConvertTo(params[1]); diff --git a/src/twister.cpp b/src/twister.cpp index f9cde0f5..e1f73964 100644 --- a/src/twister.cpp +++ b/src/twister.cpp @@ -3650,17 +3650,35 @@ Value creategroup(const Array& params, bool fHelp) Value listgroups(const Array& params, bool fHelp) { - if (fHelp || params.size() != 0) + if (fHelp || params.size() > 2 ) throw runtime_error( - "listgroups\n" - "get list of group chats"); + "listgroups [username] [list_only_ignored=false]\n" + "get list of group chats\n" + "if username is given, it will return list of user's groups."); + + string strUsername = (params.size() > 0 ? params[0].get_str() : ""); + bool onlyIgnored = (params.size() > 1 ? params[1].get_bool() : false); Array ret; - LOCK(cs_twister); - map::const_iterator i; - for (i = m_groups.begin(); i != m_groups.end(); ++i) { - ret.push_back(i->first); + if (strUsername.size() && !m_users.count(strUsername)) + throw JSONRPCError(RPC_INTERNAL_ERROR, "unknown user"); + + if (onlyIgnored) + { + LOCK(cs_twister); + BOOST_FOREACH(string const &strGroup, m_users[strUsername].m_ignoreGroups) + ret.push_back(strGroup); + } + else + { + LOCK(cs_twister); + map::const_iterator i; + for (i = m_groups.begin(); i != m_groups.end(); ++i) { + if (strUsername.size() && !i->second.m_members.count(strUsername)) + continue; + ret.push_back(i->first); + } } return ret; @@ -3850,6 +3868,7 @@ Value leavegroup(const Array& params, bool fHelp) m_users[strUser].m_directmsg.erase(strGroupAlias); m_users[strUser].m_ignoreGroups.insert(strGroupAlias); + m_groups[strGroupAlias].m_members.erase(strUser); return Value(); }