mirror of
https://github.com/RetroShare/RetroShare.git
synced 2024-10-01 02:35:48 -04:00
fixed a few bugs in post version collecting
This commit is contained in:
parent
f8056e5751
commit
b93130ac77
@ -200,7 +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->versions_CB, SIGNAL(currentIndexChanged(int)), this, SLOT(changedThread()));
|
||||
connect(ui->threadTreeWidget, SIGNAL(customContextMenuRequested(QPoint)), this, SLOT(threadListCustomPopupMenu(QPoint)));
|
||||
connect(ui->postText, SIGNAL(customContextMenuRequested(QPoint)), this, SLOT(contextMenuTextBrowser(QPoint)));
|
||||
|
||||
@ -698,7 +698,13 @@ void GxsForumThreadWidget::changedThread()
|
||||
if (!item || !item->isSelected()) {
|
||||
mThreadId.clear();
|
||||
} else {
|
||||
mThreadId = RsGxsMessageId(item->data(COLUMN_THREAD_MSGID, Qt::DisplayRole).toString().toStdString());
|
||||
mThreadId.clear();
|
||||
|
||||
if(ui->versions_CB->count() > 0)
|
||||
mThreadId = RsGxsMessageId(ui->versions_CB->itemData(ui->versions_CB->currentIndex()).toString().toStdString()) ;
|
||||
|
||||
if(mThreadId.isNull())
|
||||
mThreadId = RsGxsMessageId(item->data(COLUMN_THREAD_MSGID, Qt::DisplayRole).toString().toStdString());
|
||||
}
|
||||
|
||||
if (mFillThread) {
|
||||
@ -1024,13 +1030,13 @@ void GxsForumThreadWidget::fillThreadFinished()
|
||||
mLastViewType = thread->mViewType;
|
||||
mLastForumID = groupId();
|
||||
ui->threadTreeWidget->insertTopLevelItems(0, thread->mItems);
|
||||
mPostVersions = thread->mPostVersions;
|
||||
|
||||
// clear list
|
||||
thread->mItems.clear();
|
||||
} else {
|
||||
fillThreads(thread->mItems, thread->mExpandNewMessages, thread->mItemToExpand);
|
||||
|
||||
mPostVersions = thread->mPostVersions;
|
||||
fillThreads(thread->mItems, thread->mExpandNewMessages, thread->mItemToExpand);
|
||||
|
||||
// cleanup list
|
||||
cleanupItems(thread->mItems);
|
||||
@ -1520,6 +1526,7 @@ void GxsForumThreadWidget::insertMessage()
|
||||
mStateHelper->clear(mTokenTypeMessageData);
|
||||
|
||||
ui->versions_CB->hide();
|
||||
ui->time_label->show();
|
||||
|
||||
ui->postText->clear();
|
||||
//ui->threadTitle->clear();
|
||||
@ -1532,6 +1539,7 @@ void GxsForumThreadWidget::insertMessage()
|
||||
mStateHelper->clear(mTokenTypeMessageData);
|
||||
|
||||
ui->versions_CB->hide();
|
||||
ui->time_label->show();
|
||||
|
||||
//ui->threadTitle->setText(tr("Forum Description"));
|
||||
ui->postText->setText(mForumDescription);
|
||||
@ -1552,6 +1560,7 @@ void GxsForumThreadWidget::insertMessage()
|
||||
mStateHelper->setWidgetEnabled(ui->previousButton, false);
|
||||
mStateHelper->setWidgetEnabled(ui->nextButton, false);
|
||||
ui->versions_CB->hide();
|
||||
ui->time_label->show();
|
||||
return;
|
||||
}
|
||||
|
||||
@ -1568,19 +1577,33 @@ void GxsForumThreadWidget::insertMessage()
|
||||
|
||||
// add/show combobox for versions, if applicable, and enable it. If no older versions of the post available, hide the combobox.
|
||||
|
||||
std::cerr << "Looking into existing versions for post " << mThreadId << ", thread history: " << mPostVersions.size() << std::endl;
|
||||
|
||||
QMap<RsGxsMessageId,QVector<QPair<time_t,RsGxsMessageId> > >::const_iterator it = mPostVersions.find(mThreadId) ;
|
||||
ui->versions_CB->clear();
|
||||
|
||||
if(it != mPostVersions.end())
|
||||
{
|
||||
std::cerr << (*it).size() << " versions found " << std::endl;
|
||||
|
||||
ui->versions_CB->setVisible(true) ;
|
||||
ui->time_label->hide();
|
||||
|
||||
ui->versions_CB->blockSignals(true) ;
|
||||
|
||||
for(uint32_t i=0;i<(*it).size();++i)
|
||||
ui->versions_CB->insertItem(i,QDateTime::fromTime_t( (*it)[i].first).toString()) ;
|
||||
{
|
||||
ui->versions_CB->insertItem(i,DateTime::formatLongDateTime( (*it)[i].first));
|
||||
ui->versions_CB->setItemData(i,QString::fromStdString((*it)[i].second.toStdString()));
|
||||
|
||||
std::cerr << " added new post version " << (*it)[i].first << " " << (*it)[i].second << std::endl;
|
||||
}
|
||||
ui->versions_CB->blockSignals(false) ;
|
||||
}
|
||||
else
|
||||
{
|
||||
ui->versions_CB->hide();
|
||||
ui->time_label->show();
|
||||
}
|
||||
|
||||
/* request Post */
|
||||
@ -2137,7 +2160,7 @@ void GxsForumThreadWidget::editForumMessageData(const RsGxsForumMsg& msg)
|
||||
|
||||
if (!msg.mMeta.mAuthorId.isNull())
|
||||
{
|
||||
CreateGxsForumMsg *cfm = new CreateGxsForumMsg(groupId(), mThreadId, msg.mMeta.mMsgId);
|
||||
CreateGxsForumMsg *cfm = new CreateGxsForumMsg(groupId(), msg.mMeta.mParentId, msg.mMeta.mMsgId);
|
||||
|
||||
cfm->insertPastedText(QString::fromUtf8(msg.mMsg.c_str())) ;
|
||||
cfm->show();
|
||||
|
@ -89,6 +89,8 @@ void GxsForumsFillThread::calculateExpand(const RsGxsForumMsg &msg, QTreeWidgetI
|
||||
}
|
||||
}
|
||||
|
||||
static bool decreasing_time_comp(const QPair<time_t,RsGxsMessageId>& e1,const QPair<time_t,RsGxsMessageId>& e2) { return e2.first < e1.first ; }
|
||||
|
||||
void GxsForumsFillThread::run()
|
||||
{
|
||||
RsTokenService *service = rsGxsForums->getTokenService();
|
||||
@ -200,61 +202,75 @@ void GxsForumsFillThread::run()
|
||||
#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)) ;
|
||||
std::map<RsGxsMessageId,RsGxsForumMsg>::iterator msgIt2 = msgs.find(msgIt->second.mMeta.mOrigMsgId);
|
||||
|
||||
// always add the post a a self version
|
||||
|
||||
if(msgIt2 != msgs.end())
|
||||
{
|
||||
// Ensuring that the post exists allows to only collect the existing data.
|
||||
|
||||
mPostVersions[msgIt->second.mMeta.mOrigMsgId].push_back(QPair<time_t,RsGxsMessageId>(msgIt2->second.mMeta.mPublishTs,msgIt2->second.mMeta.mMsgId)) ;
|
||||
mPostVersions[msgIt->second.mMeta.mOrigMsgId].push_back(QPair<time_t,RsGxsMessageId>(msgIt->second.mMeta.mPublishTs,msgIt->second.mMeta.mMsgId)) ;
|
||||
}
|
||||
}
|
||||
|
||||
// The following code assembles all new versions of a given post into the same array, indexed by the oldest version of the post.
|
||||
|
||||
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 ;
|
||||
if(v[i].second != it.key())
|
||||
{
|
||||
RsGxsMessageId sub_msg_id = v[i].second ;
|
||||
|
||||
// move the post in first position if it is more recent.
|
||||
QMap<RsGxsMessageId,QVector<QPair<time_t,RsGxsMessageId> > >::iterator it2 = mPostVersions.find(sub_msg_id);
|
||||
|
||||
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 ;
|
||||
}
|
||||
if(it2 != mPostVersions.end())
|
||||
{
|
||||
for(uint32_t j=0;j<(*it2).size();++j)
|
||||
if((*it2)[j].second != sub_msg_id) // dont copy it, since it is already present at slot i
|
||||
v.append((*it2)[j]) ;
|
||||
|
||||
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
|
||||
}
|
||||
}
|
||||
mPostVersions.erase(it2) ; // it2 is never equal to it
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Now remove from msg ids, all posts except the most recent one.
|
||||
// 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.
|
||||
|
||||
#ifdef DEBUG_FORUMS
|
||||
std::cerr << "Final post versions: " << std::endl;
|
||||
#endif
|
||||
QMap<RsGxsMessageId,QVector<QPair<time_t,RsGxsMessageId> > > mTmp;
|
||||
|
||||
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()) ;
|
||||
// Finally, sort the posts from newer to older
|
||||
|
||||
for(uint32_t i=0;i<(*it).size();++i)
|
||||
{
|
||||
if(i > 0)
|
||||
msgs.erase((*it)[i].second) ;
|
||||
qSort((*it).begin(),(*it).end(),decreasing_time_comp) ;
|
||||
|
||||
#ifdef DEBUG_FORUMS
|
||||
std::cerr << " new version " << (*it)[i].first << " " << (*it)[i].second << std::endl;
|
||||
std::cerr << " most recent version " << (*it)[0].first << " " << (*it)[0].second << std::endl;
|
||||
#endif
|
||||
for(uint32_t i=1;i<(*it).size();++i)
|
||||
{
|
||||
msgs.erase((*it)[i].second) ;
|
||||
|
||||
#ifdef DEBUG_FORUMS
|
||||
std::cerr << " older version " << (*it)[i].first << " " << (*it)[i].second << std::endl;
|
||||
#endif
|
||||
}
|
||||
|
||||
mTmp[(*it)[0].second] = *it ; // index the versions map by the ID of the most recent post.
|
||||
}
|
||||
mPostVersions = mTmp ;
|
||||
|
||||
// The first step is to find the top level thread messages. These are defined as the messages without
|
||||
// any parent message ID.
|
||||
|
Loading…
Reference in New Issue
Block a user