From 52a0aea0dc2eb45ee5f9486ed68981b76fdea91f Mon Sep 17 00:00:00 2001 From: csoler Date: Tue, 9 May 2017 21:33:02 +0200 Subject: [PATCH] fixed bug causing edited posts to turn into missing messages when they have submessages --- .../src/gui/gxsforums/GxsForumsFillThread.cpp | 27 ++++++++++++++++--- 1 file changed, 23 insertions(+), 4 deletions(-) diff --git a/retroshare-gui/src/gui/gxsforums/GxsForumsFillThread.cpp b/retroshare-gui/src/gui/gxsforums/GxsForumsFillThread.cpp index 199748346..16a813bd4 100644 --- a/retroshare-gui/src/gui/gxsforums/GxsForumsFillThread.cpp +++ b/retroshare-gui/src/gui/gxsforums/GxsForumsFillThread.cpp @@ -247,6 +247,7 @@ void GxsForumsFillThread::run() } } + // Now remove from msg ids, all posts except the most recent one. And make the mPostVersion be indexed by the most recent version of the post, // which corresponds to the item in the tree widget. @@ -254,6 +255,7 @@ void GxsForumsFillThread::run() std::cerr << "Final post versions: " << std::endl; #endif QMap > > mTmp; + std::map most_recent_versions ; for(QMap > >::iterator it(mPostVersions.begin());it!=mPostVersions.end();++it) { @@ -277,10 +279,16 @@ void GxsForumsFillThread::run() } mTmp[(*it)[0].second] = *it ; // index the versions map by the ID of the most recent post. + + // Now make sure that message parents are consistent. Indeed, an old post may have the old version of a post as parent. So we need to change that parent + // to the newest version. So we create a map of which is the most recent version of each message, so that parent messages can be searched in it. + + for(uint32_t i=1;i<(*it).size();++i) + most_recent_versions[(*it)[i].second] = (*it)[0].second ; } mPostVersions = mTmp ; - // The first step is to find the top level thread messages. These are defined as the messages without + // The next step is to find the top level thread messages. These are defined as the messages without // any parent message ID. // this trick is needed because while we remove messages, the parents a given msg may already have been removed @@ -325,10 +333,21 @@ void GxsForumsFillThread::run() #endif // The same missing parent may appear multiple times, so we first store them into a unique container. - if(msgs.find(msgIt->second.mMeta.mParentId) == msgs.end()) - missing_parents.insert(msgIt->second.mMeta.mParentId); + RsGxsMessageId parent_msg = msgIt->second.mMeta.mParentId; - kids_array[msgIt->second.mMeta.mParentId].push_back(msgIt->first) ; + if(msgs.find(parent_msg) == msgs.end()) + { + // also check that the message is not versionned + + std::map::const_iterator mrit = most_recent_versions.find(parent_msg) ; + + if(mrit != most_recent_versions.end()) + parent_msg = mrit->second ; + else + missing_parents.insert(parent_msg); + } + + kids_array[parent_msg].push_back(msgIt->first) ; kept_msgs.insert(*msgIt) ; } }