insert directmsgs into vector ordered by time

This commit is contained in:
Miguel Freitas 2013-10-28 23:15:19 -02:00
parent 2cd0b0a881
commit d16d50313a

View File

@ -653,10 +653,11 @@ bool processReceivedDM(lazy_entry const* post)
} else { } else {
std::string textOut; std::string textOut;
if( key.Decrypt(sec, textOut) ) { if( key.Decrypt(sec, textOut) ) {
// this printf is good for debug, but bad for security. /* this printf is good for debug, but bad for security.
printf("Received DM for user '%s' text = '%s'\n", printf("Received DM for user '%s' text = '%s'\n",
item.second.username.c_str(), item.second.username.c_str(),
textOut.c_str()); textOut.c_str());
*/
std::string n = post->dict_find_string_value("n"); std::string n = post->dict_find_string_value("n");
@ -668,12 +669,16 @@ bool processReceivedDM(lazy_entry const* post)
LOCK(cs_twister); LOCK(cs_twister);
// store this dm in memory list, but prevent duplicates // store this dm in memory list, but prevent duplicates
std::vector<StoredDirectMsg> &dmsFromToUser = m_users[item.second.username].m_directmsg[n]; std::vector<StoredDirectMsg> &dmsFromToUser = m_users[item.second.username].m_directmsg[n];
std::vector<StoredDirectMsg>::const_iterator it; std::vector<StoredDirectMsg>::iterator it;
for( it = dmsFromToUser.begin(); it != dmsFromToUser.end(); ++it ) { for( it = dmsFromToUser.begin(); it != dmsFromToUser.end(); ++it ) {
if( stoDM.m_utcTime == (*it).m_utcTime && if( stoDM.m_utcTime == (*it).m_utcTime &&
stoDM.m_text == (*it).m_text ) { stoDM.m_text == (*it).m_text ) {
break; break;
} }
if( stoDM.m_utcTime < (*it).m_utcTime ) {
dmsFromToUser.insert(it, stoDM);
break;
}
} }
if( it == dmsFromToUser.end() ) { if( it == dmsFromToUser.end() ) {
dmsFromToUser.push_back(stoDM); dmsFromToUser.push_back(stoDM);