diff --git a/libretroshare/src/gxs/rsgenexchange.cc b/libretroshare/src/gxs/rsgenexchange.cc index c3417d186..fbece7319 100644 --- a/libretroshare/src/gxs/rsgenexchange.cc +++ b/libretroshare/src/gxs/rsgenexchange.cc @@ -1014,6 +1014,27 @@ void RsGenExchange::receiveChanges(std::vector& changes) } +static void addMessageChanged(std::map > &msgs, const std::map > &msgChanged) +{ + if (msgs.empty()) { + msgs = msgChanged; + } else { + std::map >::const_iterator mapIt; + for (mapIt = msgChanged.begin(); mapIt != msgChanged.end(); ++mapIt) { + const RsGxsGroupId &grpId = mapIt->first; + const std::vector &srcMsgIds = mapIt->second; + std::vector &destMsgIds = msgs[grpId]; + + std::vector::const_iterator msgIt; + for (msgIt = srcMsgIds.begin(); msgIt != srcMsgIds.end(); ++msgIt) { + if (std::find(destMsgIds.begin(), destMsgIds.end(), *msgIt) == destMsgIds.end()) { + destMsgIds.push_back(*msgIt); + } + } + } + } +} + void RsGenExchange::msgsChanged(std::map >& msgs, std::map >& msgsMeta) { if(mGenMtx.trylock()) @@ -1023,11 +1044,11 @@ void RsGenExchange::msgsChanged(std::mapmetaChange()) { - msgsMeta = mc->msgChangeMap; + addMessageChanged(msgsMeta, mc->msgChangeMap); } else { - msgs = mc->msgChangeMap; + addMessageChanged(msgs, mc->msgChangeMap); } mMsgChange.pop_back(); delete mc;