From b8037349150c2f96515bd666f54725d080d2176f Mon Sep 17 00:00:00 2001 From: Miguel Freitas Date: Thu, 10 Oct 2013 19:44:44 -0300 Subject: [PATCH] prevent duplicates when adding dm to the list of decrypted messages (in memory) - untested --- src/twister.cpp | 14 +++++++++++++- src/twister_utils.cpp | 4 +--- 2 files changed, 14 insertions(+), 4 deletions(-) diff --git a/src/twister.cpp b/src/twister.cpp index 49a868db..d4b7df92 100644 --- a/src/twister.cpp +++ b/src/twister.cpp @@ -1010,7 +1010,19 @@ Value newdirectmsg(const Array& params, bool fHelp) stoDM.m_utcTime = v["userpost"]["time"].integer(); { LOCK(cs_twister); - m_users[strFrom].m_directmsg[strTo].push_back(stoDM); + + std::list &dmsFromToUser = m_users[strFrom].m_directmsg[strTo]; + std::list::const_iterator it; + // prevent duplicates + for( it = dmsFromToUser.begin(); it != dmsFromToUser.end(); ++it ) { + if( stoDM.m_utcTime == (*it).m_utcTime && + stoDM.m_text == (*it).m_text ) { + break; + } + } + if( it != dmsFromToUser.end() ) { + dmsFromToUser.push_back(stoDM); + } } return entryToJson(v); diff --git a/src/twister_utils.cpp b/src/twister_utils.cpp index 128e57cc..7fb9ec47 100644 --- a/src/twister_utils.cpp +++ b/src/twister_utils.cpp @@ -150,10 +150,8 @@ int saveUserData(std::string const& filename, std::map con std::map >::const_iterator j; for (j = udata.m_directmsg.begin(); j != udata.m_directmsg.end(); ++j) { - std::list const &dmsToFromUser = j->second; - entry &dmList = dmDict[j->first]; - BOOST_FOREACH( StoredDirectMsg const &stoDm, dmsToFromUser) { + BOOST_FOREACH( StoredDirectMsg const &stoDm, j->second) { entry dmElem; dmElem["time"] = stoDm.m_utcTime; dmElem["text"] = stoDm.m_text;