added collection of older posts versions.

This commit is contained in:
csoler 2017-02-09 14:49:43 +01:00
parent 6681985634
commit f8056e5751
5 changed files with 112 additions and 4 deletions

View File

@ -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<RsGxsMessageId,QVector<QPair<time_t,RsGxsMessageId> > >::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);

View File

@ -1,6 +1,8 @@
#ifndef GXSFORUMTHREADWIDGET_H
#define GXSFORUMTHREADWIDGET_H
#include <QMap>
#include "gui/gxs/GxsMessageFrameWidget.h"
#include <retroshare/rsgxsforums.h>
#include "gui/gxs/GxsIdDetails.h"
@ -197,6 +199,8 @@ private:
RsGxsMessageId mNavigatePendingMsgId;
QList<RsGxsMessageId> mIgnoredMsgId;
QMap<RsGxsMessageId,QVector<QPair<time_t,RsGxsMessageId> > > mPostVersions ; // holds older versions of posts
Ui::GxsForumThreadWidget *ui;
};

View File

@ -479,7 +479,7 @@
</widget>
</item>
<item row="0" column="9">
<widget class="QSpinBox" name="version_SB"/>
<widget class="QComboBox" name="versions_CB"/>
</item>
</layout>
</item>
@ -565,8 +565,8 @@
</customwidget>
</customwidgets>
<resources>
<include location="../images.qrc"/>
<include location="../icons.qrc"/>
<include location="../images.qrc"/>
</resources>
<connections/>
</ui>

View File

@ -31,7 +31,7 @@
#include <iostream>
#include <algorithm>
//#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<RsGxsMessageId,std::list<RsGxsMessageId> > kids_array ;
std::set<RsGxsMessageId> 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<RsGxsMessageId> msg_stack ;
for ( std::map<RsGxsMessageId,RsGxsForumMsg>::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<time_t,RsGxsMessageId>(msgIt->second.mMeta.mPublishTs,msgIt->second.mMeta.mMsgId)) ;
}
for(QMap<RsGxsMessageId,QVector<QPair<time_t,RsGxsMessageId> > >::iterator it(mPostVersions.begin());it!=mPostVersions.end();++it)
{
QVector<QPair<time_t,RsGxsMessageId> >& v(*it) ;
for(int32_t i=0;i<v.size();++i)
{
RsGxsMessageId sub_msg_id = v[i].second ;
// move the post in first position if it is more recent.
if(v[0].first < v[i].first) // works if i==0
{
QPair<time_t,RsGxsMessageId> tmp(v[0]) ;
v[0] = v[i] ;
v[i] = tmp ;
}
QMap<RsGxsMessageId,QVector<QPair<time_t,RsGxsMessageId> > >::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<RsGxsMessageId,QVector<QPair<time_t,RsGxsMessageId> > >::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<RsGxsMessageId,RsGxsForumMsg> kept_msgs;
for ( std::map<RsGxsMessageId,RsGxsForumMsg>::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<RsGxsMessageId>::const_iterator it(missing_parents.begin());it!=missing_parents.end();++it)

View File

@ -2,6 +2,8 @@
#define GXSFORUMSFILLTHREAD_H
#include <QThread>
#include <QMap>
#include <QPair>
#include "retroshare/rsgxsifacetypes.h"
class GxsForumThreadWidget;
@ -39,6 +41,7 @@ public:
QList<QTreeWidgetItem*> mItems;
QList<QTreeWidgetItem*> mItemToExpand;
QMap<RsGxsMessageId,QVector<QPair<time_t,RsGxsMessageId> > > mPostVersions ;
private:
void calculateExpand(const RsGxsForumMsg &msg, QTreeWidgetItem *item);