Browse Source

prevent duplicates when adding dm to the list of decrypted messages (in memory) - untested

miguelfreitas
Miguel Freitas 11 years ago
parent
commit
b803734915
  1. 14
      src/twister.cpp
  2. 4
      src/twister_utils.cpp

14
src/twister.cpp

@ -1010,7 +1010,19 @@ Value newdirectmsg(const Array& params, bool fHelp)
stoDM.m_utcTime = v["userpost"]["time"].integer(); stoDM.m_utcTime = v["userpost"]["time"].integer();
{ {
LOCK(cs_twister); LOCK(cs_twister);
m_users[strFrom].m_directmsg[strTo].push_back(stoDM);
std::list<StoredDirectMsg> &dmsFromToUser = m_users[strFrom].m_directmsg[strTo];
std::list<StoredDirectMsg>::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); return entryToJson(v);

4
src/twister_utils.cpp

@ -150,10 +150,8 @@ int saveUserData(std::string const& filename, std::map<std::string,UserData> con
std::map<std::string, std::list<StoredDirectMsg> >::const_iterator j; std::map<std::string, std::list<StoredDirectMsg> >::const_iterator j;
for (j = udata.m_directmsg.begin(); j != udata.m_directmsg.end(); ++j) { for (j = udata.m_directmsg.begin(); j != udata.m_directmsg.end(); ++j) {
std::list<StoredDirectMsg> const &dmsToFromUser = j->second;
entry &dmList = dmDict[j->first]; entry &dmList = dmDict[j->first];
BOOST_FOREACH( StoredDirectMsg const &stoDm, dmsToFromUser) { BOOST_FOREACH( StoredDirectMsg const &stoDm, j->second) {
entry dmElem; entry dmElem;
dmElem["time"] = stoDm.m_utcTime; dmElem["time"] = stoDm.m_utcTime;
dmElem["text"] = stoDm.m_text; dmElem["text"] = stoDm.m_text;

Loading…
Cancel
Save