From 7dc7065d07a62d658dbbea67a712f577bf38d99c Mon Sep 17 00:00:00 2001 From: Miguel Freitas Date: Thu, 23 Apr 2015 22:01:55 -0300 Subject: [PATCH] implement group_members splitting to fit max post size (conservative estimate) --- src/twister.cpp | 18 +++++++++++------- 1 file changed, 11 insertions(+), 7 deletions(-) diff --git a/src/twister.cpp b/src/twister.cpp index 3df1b5de..3a3f14f3 100644 --- a/src/twister.cpp +++ b/src/twister.cpp @@ -1109,7 +1109,7 @@ void storeNewDM(const string &localuser, const string &dmUser, const StoredDirec stoDM.m_text == (*it).m_text ) { break; } - if( stoDM.m_utcTime < (*it).m_utcTime ) { + if( stoDM.m_utcTime <= (*it).m_utcTime ) { dmsFromToUser.insert(it, stoDM); break; } @@ -3508,15 +3508,19 @@ Value newgroupinvite(const Array& params, bool fHelp) } /* create group_members DM and send it to group */ - { - /* FIXME: if we have too many members, this code will break! - * we must check byteCounter and split in multiple DMs as needed to not exceed max size. - */ + while( !membersList.empty() ) { entry groupMembers; int byteCounter = 0; - BOOST_FOREACH( string const &member, membersList) { + while( !membersList.empty() ) { + std::set::iterator it = membersList.begin(); + std::string member=*it; groupMembers.list().push_back(member); - byteCounter += member.length() + 3; + membersList.erase(it); + + // estimate bencoded size. split in multiple DMs. + byteCounter += member.length() + 2 + member.length()/10; + if( byteCounter > 150 ) + break; } entry payloadMsg; payloadMsg["group_members"] = groupMembers;