From e5b21d6810751f7b4c43fb77f429772fc065055a Mon Sep 17 00:00:00 2001 From: Miguel Freitas Date: Thu, 10 Oct 2013 23:25:44 -0300 Subject: [PATCH] fix dm store duplicate checking. i did it completely wrong before. --- src/twister.cpp | 44 ++++++++++++++++++++++---------------------- 1 file changed, 22 insertions(+), 22 deletions(-) diff --git a/src/twister.cpp b/src/twister.cpp index ad4624d2..a653bb66 100644 --- a/src/twister.cpp +++ b/src/twister.cpp @@ -593,7 +593,18 @@ bool processReceivedDM(lazy_entry const* post) stoDM.m_utcTime = post->dict_find_int_value("time");; LOCK(cs_twister); - m_users[item.second.username].m_directmsg[n].push_back(stoDM); + // store this dm in memory list, but prevent duplicates + std::list &dmsFromToUser = m_users[item.second.username].m_directmsg[n]; + std::list::const_iterator it; + 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 true; } @@ -1002,30 +1013,19 @@ Value newdirectmsg(const Array& params, bool fHelp) if( !acceptSignedPost(buf.data(),buf.size(),strFrom,k,errmsg,NULL) ) throw JSONRPCError(RPC_INVALID_PARAMS,errmsg); + { + StoredDirectMsg stoDM; + stoDM.m_fromMe = true; + stoDM.m_text = strMsg; + stoDM.m_utcTime = v["userpost"]["time"].integer(); + + LOCK(cs_twister); + m_users[strFrom].m_directmsg[strTo].push_back(stoDM); + } + torrent_handle h = startTorrentUser(strFrom); h.add_piece(k,buf.data(),buf.size()); - StoredDirectMsg stoDM; - stoDM.m_fromMe = true; - stoDM.m_text = strMsg; - stoDM.m_utcTime = v["userpost"]["time"].integer(); - { - LOCK(cs_twister); - - 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); }