mirror of
https://github.com/RetroShare/RetroShare.git
synced 2025-07-26 07:55:44 -04:00
added collection of older posts versions.
This commit is contained in:
parent
6681985634
commit
f8056e5751
5 changed files with 112 additions and 4 deletions
|
@ -200,6 +200,7 @@ GxsForumThreadWidget::GxsForumThreadWidget(const RsGxsGroupId &forumId, QWidget
|
||||||
|
|
||||||
ui->threadTreeWidget->setItemDelegateForColumn(COLUMN_THREAD_DISTRIBUTION,new DistributionItemDelegate()) ;
|
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->threadTreeWidget, SIGNAL(customContextMenuRequested(QPoint)), this, SLOT(threadListCustomPopupMenu(QPoint)));
|
||||||
connect(ui->postText, SIGNAL(customContextMenuRequested(QPoint)), this, SLOT(contextMenuTextBrowser(QPoint)));
|
connect(ui->postText, SIGNAL(customContextMenuRequested(QPoint)), this, SLOT(contextMenuTextBrowser(QPoint)));
|
||||||
|
|
||||||
|
@ -1029,6 +1030,8 @@ void GxsForumThreadWidget::fillThreadFinished()
|
||||||
} else {
|
} else {
|
||||||
fillThreads(thread->mItems, thread->mExpandNewMessages, thread->mItemToExpand);
|
fillThreads(thread->mItems, thread->mExpandNewMessages, thread->mItemToExpand);
|
||||||
|
|
||||||
|
mPostVersions = thread->mPostVersions;
|
||||||
|
|
||||||
// cleanup list
|
// cleanup list
|
||||||
cleanupItems(thread->mItems);
|
cleanupItems(thread->mItems);
|
||||||
}
|
}
|
||||||
|
@ -1516,6 +1519,8 @@ void GxsForumThreadWidget::insertMessage()
|
||||||
mStateHelper->setActive(mTokenTypeMessageData, false);
|
mStateHelper->setActive(mTokenTypeMessageData, false);
|
||||||
mStateHelper->clear(mTokenTypeMessageData);
|
mStateHelper->clear(mTokenTypeMessageData);
|
||||||
|
|
||||||
|
ui->versions_CB->hide();
|
||||||
|
|
||||||
ui->postText->clear();
|
ui->postText->clear();
|
||||||
//ui->threadTitle->clear();
|
//ui->threadTitle->clear();
|
||||||
return;
|
return;
|
||||||
|
@ -1526,6 +1531,8 @@ void GxsForumThreadWidget::insertMessage()
|
||||||
mStateHelper->setActive(mTokenTypeMessageData, false);
|
mStateHelper->setActive(mTokenTypeMessageData, false);
|
||||||
mStateHelper->clear(mTokenTypeMessageData);
|
mStateHelper->clear(mTokenTypeMessageData);
|
||||||
|
|
||||||
|
ui->versions_CB->hide();
|
||||||
|
|
||||||
//ui->threadTitle->setText(tr("Forum Description"));
|
//ui->threadTitle->setText(tr("Forum Description"));
|
||||||
ui->postText->setText(mForumDescription);
|
ui->postText->setText(mForumDescription);
|
||||||
return;
|
return;
|
||||||
|
@ -1544,6 +1551,7 @@ void GxsForumThreadWidget::insertMessage()
|
||||||
// there is something wrong
|
// there is something wrong
|
||||||
mStateHelper->setWidgetEnabled(ui->previousButton, false);
|
mStateHelper->setWidgetEnabled(ui->previousButton, false);
|
||||||
mStateHelper->setWidgetEnabled(ui->nextButton, false);
|
mStateHelper->setWidgetEnabled(ui->nextButton, false);
|
||||||
|
ui->versions_CB->hide();
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1558,6 +1566,23 @@ void GxsForumThreadWidget::insertMessage()
|
||||||
ui->by_text_label->hide();
|
ui->by_text_label->hide();
|
||||||
ui->by_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 */
|
/* request Post */
|
||||||
RsGxsGrpMsgIdPair msgId = std::make_pair(groupId(), mThreadId);
|
RsGxsGrpMsgIdPair msgId = std::make_pair(groupId(), mThreadId);
|
||||||
requestMessageData(msgId);
|
requestMessageData(msgId);
|
||||||
|
|
|
@ -1,6 +1,8 @@
|
||||||
#ifndef GXSFORUMTHREADWIDGET_H
|
#ifndef GXSFORUMTHREADWIDGET_H
|
||||||
#define GXSFORUMTHREADWIDGET_H
|
#define GXSFORUMTHREADWIDGET_H
|
||||||
|
|
||||||
|
#include <QMap>
|
||||||
|
|
||||||
#include "gui/gxs/GxsMessageFrameWidget.h"
|
#include "gui/gxs/GxsMessageFrameWidget.h"
|
||||||
#include <retroshare/rsgxsforums.h>
|
#include <retroshare/rsgxsforums.h>
|
||||||
#include "gui/gxs/GxsIdDetails.h"
|
#include "gui/gxs/GxsIdDetails.h"
|
||||||
|
@ -197,6 +199,8 @@ private:
|
||||||
RsGxsMessageId mNavigatePendingMsgId;
|
RsGxsMessageId mNavigatePendingMsgId;
|
||||||
QList<RsGxsMessageId> mIgnoredMsgId;
|
QList<RsGxsMessageId> mIgnoredMsgId;
|
||||||
|
|
||||||
|
QMap<RsGxsMessageId,QVector<QPair<time_t,RsGxsMessageId> > > mPostVersions ; // holds older versions of posts
|
||||||
|
|
||||||
Ui::GxsForumThreadWidget *ui;
|
Ui::GxsForumThreadWidget *ui;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
|
@ -479,7 +479,7 @@
|
||||||
</widget>
|
</widget>
|
||||||
</item>
|
</item>
|
||||||
<item row="0" column="9">
|
<item row="0" column="9">
|
||||||
<widget class="QSpinBox" name="version_SB"/>
|
<widget class="QComboBox" name="versions_CB"/>
|
||||||
</item>
|
</item>
|
||||||
</layout>
|
</layout>
|
||||||
</item>
|
</item>
|
||||||
|
@ -565,8 +565,8 @@
|
||||||
</customwidget>
|
</customwidget>
|
||||||
</customwidgets>
|
</customwidgets>
|
||||||
<resources>
|
<resources>
|
||||||
<include location="../images.qrc"/>
|
|
||||||
<include location="../icons.qrc"/>
|
<include location="../icons.qrc"/>
|
||||||
|
<include location="../images.qrc"/>
|
||||||
</resources>
|
</resources>
|
||||||
<connections/>
|
<connections/>
|
||||||
</ui>
|
</ui>
|
||||||
|
|
|
@ -31,7 +31,7 @@
|
||||||
#include <iostream>
|
#include <iostream>
|
||||||
#include <algorithm>
|
#include <algorithm>
|
||||||
|
|
||||||
//#define DEBUG_FORUMS
|
#define DEBUG_FORUMS
|
||||||
|
|
||||||
#define PROGRESSBAR_MAX 100
|
#define PROGRESSBAR_MAX 100
|
||||||
|
|
||||||
|
@ -185,6 +185,77 @@ void GxsForumsFillThread::run()
|
||||||
std::map<RsGxsMessageId,std::list<RsGxsMessageId> > kids_array ;
|
std::map<RsGxsMessageId,std::list<RsGxsMessageId> > kids_array ;
|
||||||
std::set<RsGxsMessageId> missing_parents;
|
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
|
// The first step is to find the top level thread messages. These are defined as the messages without
|
||||||
// any parent message ID.
|
// any parent message ID.
|
||||||
|
|
||||||
|
@ -194,6 +265,8 @@ void GxsForumsFillThread::run()
|
||||||
std::map<RsGxsMessageId,RsGxsForumMsg> kept_msgs;
|
std::map<RsGxsMessageId,RsGxsForumMsg> kept_msgs;
|
||||||
|
|
||||||
for ( std::map<RsGxsMessageId,RsGxsForumMsg>::iterator msgIt = msgs.begin(); msgIt != msgs.end();++msgIt)
|
for ( std::map<RsGxsMessageId,RsGxsForumMsg>::iterator msgIt = msgs.begin(); msgIt != msgs.end();++msgIt)
|
||||||
|
{
|
||||||
|
|
||||||
if(mFlatView || msgIt->second.mMeta.mParentId.isNull())
|
if(mFlatView || msgIt->second.mMeta.mParentId.isNull())
|
||||||
{
|
{
|
||||||
|
|
||||||
|
@ -234,9 +307,12 @@ void GxsForumsFillThread::run()
|
||||||
kids_array[msgIt->second.mMeta.mParentId].push_back(msgIt->first) ;
|
kids_array[msgIt->second.mMeta.mParentId].push_back(msgIt->first) ;
|
||||||
kept_msgs.insert(*msgIt) ;
|
kept_msgs.insert(*msgIt) ;
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
msgs = kept_msgs;
|
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.
|
// 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)
|
for(std::set<RsGxsMessageId>::const_iterator it(missing_parents.begin());it!=missing_parents.end();++it)
|
||||||
|
|
|
@ -2,6 +2,8 @@
|
||||||
#define GXSFORUMSFILLTHREAD_H
|
#define GXSFORUMSFILLTHREAD_H
|
||||||
|
|
||||||
#include <QThread>
|
#include <QThread>
|
||||||
|
#include <QMap>
|
||||||
|
#include <QPair>
|
||||||
#include "retroshare/rsgxsifacetypes.h"
|
#include "retroshare/rsgxsifacetypes.h"
|
||||||
|
|
||||||
class GxsForumThreadWidget;
|
class GxsForumThreadWidget;
|
||||||
|
@ -39,6 +41,7 @@ public:
|
||||||
QList<QTreeWidgetItem*> mItems;
|
QList<QTreeWidgetItem*> mItems;
|
||||||
QList<QTreeWidgetItem*> mItemToExpand;
|
QList<QTreeWidgetItem*> mItemToExpand;
|
||||||
|
|
||||||
|
QMap<RsGxsMessageId,QVector<QPair<time_t,RsGxsMessageId> > > mPostVersions ;
|
||||||
private:
|
private:
|
||||||
void calculateExpand(const RsGxsForumMsg &msg, QTreeWidgetItem *item);
|
void calculateExpand(const RsGxsForumMsg &msg, QTreeWidgetItem *item);
|
||||||
|
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue