diff --git a/src/twister.cpp b/src/twister.cpp index 3a3f14f3..96e59b65 100644 --- a/src/twister.cpp +++ b/src/twister.cpp @@ -1127,7 +1127,7 @@ void storeGroupDM(const string &groupAlias, const StoredDirectMsg &stoDM) GroupChat &group = m_groups[groupAlias]; BOOST_FOREACH(string const &member, group.m_members) { - if( m_users.count(member) ) { + if( m_users.count(member) && !m_users.at(member).m_ignoreGroups.count(groupAlias) ) { storeNewDM(member,groupAlias,stoDM); } } @@ -3579,10 +3579,10 @@ Value newgroupdescription(const Array& params, bool fHelp) Value leavegroup(const Array& params, bool fHelp) { - if (fHelp || params.size() != 4 ) + if (fHelp || params.size() != 2 ) throw runtime_error( "leavegroup \n" - "Stop receive chats from group"); + "Stop receiving chats from group"); string strUser = params[0].get_str(); string strGroupAlias = params[1].get_str(); @@ -3594,12 +3594,8 @@ Value leavegroup(const Array& params, bool fHelp) if (!m_users.count(strUser)) throw JSONRPCError(RPC_INTERNAL_ERROR, "unknown user"); - throw JSONRPCError(RPC_INTERNAL_ERROR, "not implemented"); - /* - * The idea is to remove strGroupAlias from m_users[strUser].m_directmsg and - * also add strGroupAlias to a m_users[strUser].m_ignoreGroups list to prevent - * being invited again. however how would one revert a leavegroup? - */ + m_users[strUser].m_directmsg.erase(strGroupAlias); + m_users[strUser].m_ignoreGroups.insert(strGroupAlias); return Value(); } diff --git a/src/twister_utils.cpp b/src/twister_utils.cpp index 90e8efec..810abacb 100644 --- a/src/twister_utils.cpp +++ b/src/twister_utils.cpp @@ -174,6 +174,14 @@ int saveUserData(std::string const& filename, std::map con } } } + + if( udata.m_ignoreGroups.size() ) { + entry &userData = userDict[i->first]; + entry &ignoreGroupsList = userData["ignore_groups"]; + BOOST_FOREACH( std::string const &n, udata.m_ignoreGroups) { + ignoreGroupsList.list().push_back(n); + } + } } std::vector buf; @@ -252,6 +260,16 @@ int loadUserData(std::string const& filename, std::map &us } } } + + const lazy_entry *ignoreGroupsList = userData->dict_find("ignore_groups"); + if( ignoreGroupsList ) { + if( ignoreGroupsList->type() != lazy_entry::list_t ) goto data_error; + + for( int j = 0; j < ignoreGroupsList->list_size(); j++ ) { + udata.m_ignoreGroups.insert( ignoreGroupsList->list_string_value_at(j) ); + } + } + users[userDict.dict_at(i).first] = udata; } return 0; diff --git a/src/twister_utils.h b/src/twister_utils.h index 3c8688f6..a542e698 100644 --- a/src/twister_utils.h +++ b/src/twister_utils.h @@ -33,6 +33,8 @@ struct UserData { std::set m_mentionsKeys; // known posts mentioning this user (by users in m_following) std::vector m_mentionsPosts; + // group chats to ignore + std::set m_ignoreGroups; };