diff --git a/retroshare-gui/src/gui/gxsforums/GxsForumThreadWidget.cpp b/retroshare-gui/src/gui/gxsforums/GxsForumThreadWidget.cpp index d2d6c2cc6..d143a70ba 100644 --- a/retroshare-gui/src/gui/gxsforums/GxsForumThreadWidget.cpp +++ b/retroshare-gui/src/gui/gxsforums/GxsForumThreadWidget.cpp @@ -200,6 +200,7 @@ GxsForumThreadWidget::GxsForumThreadWidget(const RsGxsGroupId &forumId, QWidget ui->threadTreeWidget->setItemDelegateForColumn(COLUMN_THREAD_DISTRIBUTION,new DistributionItemDelegate()) ; + connect(ui->versions_CB, SIGNAL(currentItemChanged(int)), this, SLOT(updateCurrentPostVersion(int))); connect(ui->threadTreeWidget, SIGNAL(customContextMenuRequested(QPoint)), this, SLOT(threadListCustomPopupMenu(QPoint))); connect(ui->postText, SIGNAL(customContextMenuRequested(QPoint)), this, SLOT(contextMenuTextBrowser(QPoint))); @@ -1029,6 +1030,8 @@ void GxsForumThreadWidget::fillThreadFinished() } else { fillThreads(thread->mItems, thread->mExpandNewMessages, thread->mItemToExpand); + mPostVersions = thread->mPostVersions; + // cleanup list cleanupItems(thread->mItems); } @@ -1516,6 +1519,8 @@ void GxsForumThreadWidget::insertMessage() mStateHelper->setActive(mTokenTypeMessageData, false); mStateHelper->clear(mTokenTypeMessageData); + ui->versions_CB->hide(); + ui->postText->clear(); //ui->threadTitle->clear(); return; @@ -1526,6 +1531,8 @@ void GxsForumThreadWidget::insertMessage() mStateHelper->setActive(mTokenTypeMessageData, false); mStateHelper->clear(mTokenTypeMessageData); + ui->versions_CB->hide(); + //ui->threadTitle->setText(tr("Forum Description")); ui->postText->setText(mForumDescription); return; @@ -1544,6 +1551,7 @@ void GxsForumThreadWidget::insertMessage() // there is something wrong mStateHelper->setWidgetEnabled(ui->previousButton, false); mStateHelper->setWidgetEnabled(ui->nextButton, false); + ui->versions_CB->hide(); return; } @@ -1558,6 +1566,23 @@ void GxsForumThreadWidget::insertMessage() ui->by_text_label->hide(); ui->by_label->hide(); + // add/show combobox for versions, if applicable, and enable it. If no older versions of the post available, hide the combobox. + + QMap > >::const_iterator it = mPostVersions.find(mThreadId) ; + ui->versions_CB->clear(); + + if(it != mPostVersions.end()) + { + ui->versions_CB->setVisible(true) ; + + for(uint32_t i=0;i<(*it).size();++i) + ui->versions_CB->insertItem(i,QDateTime::fromTime_t( (*it)[i].first).toString()) ; + } + else + { + ui->versions_CB->hide(); + } + /* request Post */ RsGxsGrpMsgIdPair msgId = std::make_pair(groupId(), mThreadId); requestMessageData(msgId); diff --git a/retroshare-gui/src/gui/gxsforums/GxsForumThreadWidget.h b/retroshare-gui/src/gui/gxsforums/GxsForumThreadWidget.h index d320324db..f6eaeb208 100644 --- a/retroshare-gui/src/gui/gxsforums/GxsForumThreadWidget.h +++ b/retroshare-gui/src/gui/gxsforums/GxsForumThreadWidget.h @@ -1,6 +1,8 @@ #ifndef GXSFORUMTHREADWIDGET_H #define GXSFORUMTHREADWIDGET_H +#include + #include "gui/gxs/GxsMessageFrameWidget.h" #include #include "gui/gxs/GxsIdDetails.h" @@ -197,6 +199,8 @@ private: RsGxsMessageId mNavigatePendingMsgId; QList mIgnoredMsgId; + QMap > > mPostVersions ; // holds older versions of posts + Ui::GxsForumThreadWidget *ui; }; diff --git a/retroshare-gui/src/gui/gxsforums/GxsForumThreadWidget.ui b/retroshare-gui/src/gui/gxsforums/GxsForumThreadWidget.ui index 8304dd0a9..bd0d92e9e 100644 --- a/retroshare-gui/src/gui/gxsforums/GxsForumThreadWidget.ui +++ b/retroshare-gui/src/gui/gxsforums/GxsForumThreadWidget.ui @@ -479,7 +479,7 @@ - + @@ -565,8 +565,8 @@ - + diff --git a/retroshare-gui/src/gui/gxsforums/GxsForumsFillThread.cpp b/retroshare-gui/src/gui/gxsforums/GxsForumsFillThread.cpp index 4c381ce42..9b8e0d6b0 100644 --- a/retroshare-gui/src/gui/gxsforums/GxsForumsFillThread.cpp +++ b/retroshare-gui/src/gui/gxsforums/GxsForumsFillThread.cpp @@ -31,7 +31,7 @@ #include #include -//#define DEBUG_FORUMS +#define DEBUG_FORUMS #define PROGRESSBAR_MAX 100 @@ -171,7 +171,7 @@ void GxsForumsFillThread::run() int pos = 0; int steps = count / PROGRESSBAR_MAX; int step = 0; - + // ThreadList contains the list of parent threads. The algorithm below iterates through all messages // and tries to establish parenthood relationships between them, given that we only know the // immediate parent of a message and now its children. Some messages have a missing parent and for them @@ -185,6 +185,77 @@ void GxsForumsFillThread::run() std::map > kids_array ; std::set missing_parents; + // First of all, remove all older versions of posts. This is done by first adding all posts into a hierarchy structure + // and then removing all posts which have a new versions available. The older versions are kept appart. + +#ifdef DEBUG_FORUMS + std::cerr << "GxsForumsFillThread::run() Collecting post versions" << std::endl; +#endif + mPostVersions.clear(); + std::list msg_stack ; + + for ( std::map::iterator msgIt = msgs.begin(); msgIt != msgs.end();++msgIt) + if(!msgIt->second.mMeta.mOrigMsgId.isNull() && msgIt->second.mMeta.mOrigMsgId != msgIt->second.mMeta.mMsgId) + { +#ifdef DEBUG_FORUMS + std::cerr << " Post " << msgIt->second.mMeta.mMsgId << " is a new version of " << msgIt->second.mMeta.mOrigMsgId << std::endl; +#endif + mPostVersions[msgIt->second.mMeta.mOrigMsgId].push_back(QPair(msgIt->second.mMeta.mPublishTs,msgIt->second.mMeta.mMsgId)) ; + } + + for(QMap > >::iterator it(mPostVersions.begin());it!=mPostVersions.end();++it) + { + QVector >& v(*it) ; + + for(int32_t i=0;i tmp(v[0]) ; + v[0] = v[i] ; + v[i] = tmp ; + } + + QMap > >::iterator it2 = mPostVersions.find(sub_msg_id); + + if(it2 != mPostVersions.end()) + { + for(uint32_t j=0;j<(*it2).size();++j) + v.append((*it2)[j]) ; + + mPostVersions.erase(it2) ; // it2 is never equal to it + } + } + } + + // Now remove from msg ids, all posts except the most recent one. + +#ifdef DEBUG_FORUMS + std::cerr << "Final post versions: " << std::endl; +#endif + for(QMap > >::iterator it(mPostVersions.begin());it!=mPostVersions.end();++it) + { +#ifdef DEBUG_FORUMS + std::cerr << "Original post: " << it.key() << std::endl; +#endif + if(!(*it).empty()) + msgs.erase(it.key()) ; + + for(uint32_t i=0;i<(*it).size();++i) + { + if(i > 0) + msgs.erase((*it)[i].second) ; + +#ifdef DEBUG_FORUMS + std::cerr << " new version " << (*it)[i].first << " " << (*it)[i].second << std::endl; +#endif + } + } + // The first step is to find the top level thread messages. These are defined as the messages without // any parent message ID. @@ -194,6 +265,8 @@ void GxsForumsFillThread::run() std::map kept_msgs; for ( std::map::iterator msgIt = msgs.begin(); msgIt != msgs.end();++msgIt) + { + if(mFlatView || msgIt->second.mMeta.mParentId.isNull()) { @@ -234,9 +307,12 @@ void GxsForumsFillThread::run() kids_array[msgIt->second.mMeta.mParentId].push_back(msgIt->first) ; kept_msgs.insert(*msgIt) ; } + } msgs = kept_msgs; + // Also create a list of posts by time, when they are new versions of existing posts. Only the last one will have an item created. + // Add a fake toplevel item for the parent IDs that we dont actually have. for(std::set::const_iterator it(missing_parents.begin());it!=missing_parents.end();++it) diff --git a/retroshare-gui/src/gui/gxsforums/GxsForumsFillThread.h b/retroshare-gui/src/gui/gxsforums/GxsForumsFillThread.h index 58a461607..2b5974855 100644 --- a/retroshare-gui/src/gui/gxsforums/GxsForumsFillThread.h +++ b/retroshare-gui/src/gui/gxsforums/GxsForumsFillThread.h @@ -2,6 +2,8 @@ #define GXSFORUMSFILLTHREAD_H #include +#include +#include #include "retroshare/rsgxsifacetypes.h" class GxsForumThreadWidget; @@ -39,6 +41,7 @@ public: QList mItems; QList mItemToExpand; + QMap > > mPostVersions ; private: void calculateExpand(const RsGxsForumMsg &msg, QTreeWidgetItem *item);