From beab81e1341bb6e8b19bd603293c7a477e16b943 Mon Sep 17 00:00:00 2001 From: Phenom Date: Sat, 6 Aug 2016 11:57:20 +0200 Subject: [PATCH] Fix Forum Item sort on LastPost View. msg.mMeta.mChildTs Was not updated when received new child so do it when creating GxsIdRSTreeWidgetItem. --- libretroshare/src/gxs/rsgxsdata.cc | 22 +++---- .../gui/gxsforums/GxsForumThreadWidget.cpp | 61 +++++++++++-------- .../src/gui/gxsforums/GxsForumThreadWidget.h | 2 +- .../src/gui/gxsforums/GxsForumsFillThread.cpp | 3 +- 4 files changed, 49 insertions(+), 39 deletions(-) diff --git a/libretroshare/src/gxs/rsgxsdata.cc b/libretroshare/src/gxs/rsgxsdata.cc index a078f1d6b..090a7b602 100644 --- a/libretroshare/src/gxs/rsgxsdata.cc +++ b/libretroshare/src/gxs/rsgxsdata.cc @@ -39,20 +39,20 @@ uint32_t RsGxsGrpMetaData::serial_size(uint32_t api_version) s += mGroupId.serial_size(); s += mOrigGrpId.serial_size(); - s += mParentGrpId.serial_size(); + s += mParentGrpId.serial_size(); s += GetTlvStringSize(mGroupName); - s += 4; // mGroupFlags - s += 4; // mPublishTs - s += 4; // mCircleType - s += 4; // mAuthenFlag + s += 4; // mGroupFlags + s += 4; // mPublishTs + s += 4; // mCircleType + s += 4; // mAuthenFlag s += mAuthorId.serial_size(); s += GetTlvStringSize(mServiceString); - s += mCircleId.serial_size(); + s += mCircleId.serial_size(); s += signSet.TlvSize(); s += keys.TlvSize(); if(api_version == RS_GXS_GRP_META_DATA_VERSION_ID_0002) - s += 4; // mSignFlag + s += 4; // mSignFlag else if(api_version != RS_GXS_GRP_META_DATA_VERSION_ID_0001) std::cerr << "(EE) wrong/unknown API version " << api_version << " requested in RsGxsGrpMetaData::serial_size()" << std::endl; @@ -203,7 +203,7 @@ bool RsGxsGrpMetaData::deserialise(void *data, uint32_t &pktsize) int RsGxsMsgMetaData::refcount = 0; RsGxsMsgMetaData::RsGxsMsgMetaData(){ - + clear(); //std::cout << "\nrefcount++ : " << ++refcount << std::endl; return; } @@ -227,8 +227,8 @@ uint32_t RsGxsMsgMetaData::serial_size() s += signSet.TlvSize(); s += GetTlvStringSize(mMsgName); - s += 4; // mPublishTS - s += 4; // mMsgFlags + s += 4; // mPublishTS + s += 4; // mMsgFlags return s; } @@ -311,7 +311,7 @@ bool RsGxsMsgMetaData::deserialise(void *data, uint32_t *size) ok &= signSet.GetTlv(data, *size, &offset); ok &= GetTlvString(data, *size, &offset, 0, mMsgName); - uint32_t t=0; + uint32_t t=0; ok &= getRawUInt32(data, *size, &offset, &t); mPublishTs = t; ok &= getRawUInt32(data, *size, &offset, &mMsgFlags); diff --git a/retroshare-gui/src/gui/gxsforums/GxsForumThreadWidget.cpp b/retroshare-gui/src/gui/gxsforums/GxsForumThreadWidget.cpp index 4aacf3485..29033ae09 100644 --- a/retroshare-gui/src/gui/gxsforums/GxsForumThreadWidget.cpp +++ b/retroshare-gui/src/gui/gxsforums/GxsForumThreadWidget.cpp @@ -973,44 +973,54 @@ void GxsForumThreadWidget::fillThreadStatus(QString text) ui->progressText->setText(text); } -QTreeWidgetItem *GxsForumThreadWidget::convertMsgToThreadWidget(const RsGxsForumMsg &msg, bool useChildTS, uint32_t filterColumn) +QTreeWidgetItem *GxsForumThreadWidget::convertMsgToThreadWidget(const RsGxsForumMsg &msg, bool useChildTS, uint32_t filterColumn, QTreeWidgetItem *parent) { - // Early check for a message that should be hidden because its author - // is flagged with a bad reputation - - - bool redacted = rsIdentity->isBanned(msg.mMeta.mAuthorId) ; - - GxsIdRSTreeWidgetItem *item = new GxsIdRSTreeWidgetItem(mThreadCompareRole,GxsIdDetails::ICON_TYPE_ALL || (redacted?(GxsIdDetails::ICON_TYPE_REDACTED):0)); + // Early check for a message that should be hidden because its author + // is flagged with a bad reputation + + + bool redacted = rsIdentity->isBanned(msg.mMeta.mAuthorId) ; + + GxsIdRSTreeWidgetItem *item = new GxsIdRSTreeWidgetItem(mThreadCompareRole,GxsIdDetails::ICON_TYPE_ALL || (redacted?(GxsIdDetails::ICON_TYPE_REDACTED):0)); item->moveToThread(ui->threadTreeWidget->thread()); - QString text; - if(redacted) + if(redacted) item->setText(COLUMN_THREAD_TITLE, tr("[ ... Redacted message ... ]")); else item->setText(COLUMN_THREAD_TITLE, QString::fromUtf8(msg.mMeta.mMsgName.c_str())); + + //msg.mMeta.mChildTs Was not updated when received new child + // so do it here. QDateTime qtime; - QString sort; + qtime.setTime_t(msg.mMeta.mPublishTs); - if (useChildTS) - qtime.setTime_t(msg.mMeta.mChildTs); - else - qtime.setTime_t(msg.mMeta.mPublishTs); - - text = DateTime::formatDateTime(qtime); - sort = qtime.toString("yyyyMMdd_hhmmss"); + QString itemText = DateTime::formatDateTime(qtime); + QString itemSort = QString::number(msg.mMeta.mPublishTs);//Don't need to format it as for sort. if (useChildTS) { - qtime.setTime_t(msg.mMeta.mPublishTs); - text += " / "; - text += DateTime::formatDateTime(qtime); - sort += "_" + qtime.toString("yyyyMMdd_hhmmss"); + for(QTreeWidgetItem *grandParent = parent; grandParent!=NULL; grandParent = grandParent->parent()) + { + //Update Parent Child TimeStamp + QString oldTSText = grandParent->text(COLUMN_THREAD_DATE); + QString oldTSSort = grandParent->data(COLUMN_THREAD_DATE, ROLE_THREAD_SORT).toString(); + + QString oldCTSText = oldTSText.split("|").at(0); + QString oldPTSText = oldTSText.contains("|") ? oldTSText.split(" | ").at(1) : oldCTSText;//If first time parent get only its mPublishTs + QString oldCTSSort = oldTSSort.split("|").at(0); + QString oldPTSSort = oldTSSort.contains("|") ? oldTSSort.split(" | ").at(1) : oldCTSSort; + if (oldCTSSort.toDouble() < itemSort.toDouble()) + { + grandParent->setText(COLUMN_THREAD_DATE, DateTime::formatDateTime(qtime) + " | " + oldPTSText); + grandParent->setData(COLUMN_THREAD_DATE, ROLE_THREAD_SORT, itemSort + " | " + oldPTSSort); + } + } } - item->setText(COLUMN_THREAD_DATE, text); - item->setData(COLUMN_THREAD_DATE, ROLE_THREAD_SORT, sort); + + item->setText(COLUMN_THREAD_DATE, itemText); + item->setData(COLUMN_THREAD_DATE, ROLE_THREAD_SORT, itemSort); // Set later with GxsIdRSTreeWidgetItem::setId item->setData(COLUMN_THREAD_DATA, ROLE_THREAD_AUTHOR, QString::fromStdString(msg.mMeta.mAuthorId.toStdString())); @@ -1061,7 +1071,8 @@ QTreeWidgetItem *GxsForumThreadWidget::convertMsgToThreadWidget(const RsGxsForum #endif item->setData(COLUMN_THREAD_DATA, ROLE_THREAD_STATUS, msg.mMeta.mMsgStatus); item->setData(COLUMN_THREAD_DATA, ROLE_THREAD_MISSING, false); - + + if (parent) parent->addChild(item); return item; } diff --git a/retroshare-gui/src/gui/gxsforums/GxsForumThreadWidget.h b/retroshare-gui/src/gui/gxsforums/GxsForumThreadWidget.h index ea18e3c0f..1cf109a81 100644 --- a/retroshare-gui/src/gui/gxsforums/GxsForumThreadWidget.h +++ b/retroshare-gui/src/gui/gxsforums/GxsForumThreadWidget.h @@ -51,7 +51,7 @@ public: unsigned int newCount() { return mNewCount; } unsigned int unreadCount() { return mUnreadCount; } - QTreeWidgetItem *convertMsgToThreadWidget(const RsGxsForumMsg &msg, bool useChildTS, uint32_t filterColumn); + QTreeWidgetItem *convertMsgToThreadWidget(const RsGxsForumMsg &msg, bool useChildTS, uint32_t filterColumn, QTreeWidgetItem *parent = NULL); QTreeWidgetItem *generateMissingItem(const RsGxsMessageId &msgId); // Callback for all Loads. diff --git a/retroshare-gui/src/gui/gxsforums/GxsForumsFillThread.cpp b/retroshare-gui/src/gui/gxsforums/GxsForumsFillThread.cpp index 0b1a06a82..045495bd7 100644 --- a/retroshare-gui/src/gui/gxsforums/GxsForumsFillThread.cpp +++ b/retroshare-gui/src/gui/gxsforums/GxsForumsFillThread.cpp @@ -218,8 +218,7 @@ void GxsForumsFillThread::run() std::cerr << "GxsForumsFillThread::run() adding " << msg.mMeta.mMsgId << std::endl; #endif - QTreeWidgetItem *item = mParent->convertMsgToThreadWidget(msg, mUseChildTS, mFilterColumn); - threadPair.second->addChild(item); + QTreeWidgetItem *item = mParent->convertMsgToThreadWidget(msg, mUseChildTS, mFilterColumn, threadPair.second); calculateExpand(msg, item);