From 299ad1b1e1acafd480d2664d8a86bdb9a540caae Mon Sep 17 00:00:00 2001 From: csoler Date: Wed, 22 Jun 2022 19:07:35 +0200 Subject: [PATCH] removed TokenQueue in CommentsTreeWidget for the display of comments --- .../src/gui/gxs/GxsCommentTreeWidget.cpp | 147 ++++++++++++++---- .../src/gui/gxs/GxsCommentTreeWidget.h | 6 +- 2 files changed, 125 insertions(+), 28 deletions(-) diff --git a/retroshare-gui/src/gui/gxs/GxsCommentTreeWidget.cpp b/retroshare-gui/src/gui/gxs/GxsCommentTreeWidget.cpp index 343f88c91..f12c238bd 100644 --- a/retroshare-gui/src/gui/gxs/GxsCommentTreeWidget.cpp +++ b/retroshare-gui/src/gui/gxs/GxsCommentTreeWidget.cpp @@ -25,6 +25,7 @@ #include "gui/common/RSTreeWidgetItem.h" #include "gui/gxs/GxsCreateCommentDialog.h" #include "gui/gxs/GxsIdTreeWidgetItem.h" +#include "util/qtthreadsutils.h" #include #include @@ -540,14 +541,86 @@ void GxsCommentTreeWidget::service_requestComments(const RsGxsGroupId& group_id, ids_to_ask.push_back(std::make_pair(group_id,*it)); } - RsTokReqOptions opts; - opts.mReqType = GXS_REQUEST_TYPE_MSG_RELATED_DATA; - opts.mOptions = RS_TOKREQOPT_MSG_THREAD | RS_TOKREQOPT_MSG_LATEST; + RsThread::async([this,group_id,msgIds]() + { + std::vector comments; - uint32_t token; - mTokenQueue->requestMsgRelatedInfo(token, RS_TOKREQ_ANSTYPE_DATA, opts, ids_to_ask, GXSCOMMENTS_LOADTHREAD); + if(!mCommentService->getRelatedComments(group_id,msgIds,comments)) + { + std::cerr << __PRETTY_FUNCTION__ << " failed to get circles summaries " << std::endl; + return; + } + + RsQThreadUtils::postToObject( [this,comments]() + { + /* Here it goes any code you want to be executed on the Qt Gui + * thread, for example to update the data model with new information + * after a blocking call to RetroShare API complete, note that + * Qt::QueuedConnection is important! + */ + + clearItems(); + + service_loadThread(comments); + + completeItems(); + + emit commentsLoaded(treeCount(this)); + + }, this ); + }); + // RsTokReqOptions opts; + // opts.mReqType = GXS_REQUEST_TYPE_MSG_RELATED_DATA; + // opts.mOptions = RS_TOKREQOPT_MSG_THREAD | RS_TOKREQOPT_MSG_LATEST; + + // uint32_t token; + // mTokenQueue->requestMsgRelatedInfo(token, RS_TOKREQ_ANSTYPE_DATA, opts, ids_to_ask, GXSCOMMENTS_LOADTHREAD); } +#ifdef TODO +void GxsCommentTreeWidget::async_msg_action(const CmtMethod &action) +{ + RsThread::async([this,action]() + { + // 1 - get message data from p3GxsForums + + std::set msgs_to_request ; + std::vector msgs; + + msgs_to_request.insert(mThreadId); + + if(!rsGxsForums->getForumContent(groupId(),msgs_to_request,msgs)) + { + std::cerr << __PRETTY_FUNCTION__ << " failed to retrieve forum message info for forum " << groupId() << " and thread " << mThreadId << std::endl; + return; + } + + if(msgs.size() != 1) + { + std::cerr << __PRETTY_FUNCTION__ << " more than 1 or no msgs selected in forum " << groupId() << std::endl; + return; + } + + // 2 - sort the messages into a proper hierarchy + + RsGxsForumMsg msg = msgs[0]; + + // 3 - update the model in the UI thread. + + RsQThreadUtils::postToObject( [msg,action,this]() + { + /* Here it goes any code you want to be executed on the Qt Gui + * thread, for example to update the data model with new information + * after a blocking call to RetroShare API complete */ + + (this->*action)(msg); + + }, this ); + + }); +} +#endif + /* Generic Handling */ void GxsCommentTreeWidget::clearItems() @@ -673,7 +746,7 @@ void GxsCommentTreeWidget::addItem(RsGxsMessageId itemId, RsGxsMessageId parentI } } -int treeCount(QTreeWidget *tree, QTreeWidgetItem *parent = 0) +int GxsCommentTreeWidget::treeCount(QTreeWidget *tree, QTreeWidgetItem *parent) { int count = 0; if (parent == 0) @@ -694,16 +767,16 @@ int treeCount(QTreeWidget *tree, QTreeWidgetItem *parent = 0) } return count; } -void GxsCommentTreeWidget::loadThread(const uint32_t &token) -{ - clearItems(); - - service_loadThread(token); - - completeItems(); - - emit commentsLoaded(treeCount(this)); -} +// void GxsCommentTreeWidget::loadThread(const uint32_t &token) +// { +// clearItems(); +// +// service_loadThread(token); +// +// completeItems(); +// +// emit commentsLoaded(treeCount(this)); +// } void GxsCommentTreeWidget::acknowledgeComment(const uint32_t &token) { @@ -725,14 +798,10 @@ void GxsCommentTreeWidget::acknowledgeVote(const uint32_t &token) } } - -void GxsCommentTreeWidget::service_loadThread(const uint32_t &token) +void GxsCommentTreeWidget::service_loadThread(const std::vector& comments) { - std::cerr << "GxsCommentTreeWidget::service_loadThread() ERROR must be overloaded!"; - std::cerr << std::endl; - - std::vector comments; - mCommentService->getRelatedComments(token, comments); + std::cerr << "GxsCommentTreeWidget::service_loadThread() ERROR must be overloaded!"; + std::cerr << std::endl; // This is inconsistent since we cannot know here that all comments are for the same thread. However they are only // requested in requestComments() where a single MsgId is used. @@ -751,6 +820,32 @@ void GxsCommentTreeWidget::service_loadThread(const uint32_t &token) insertComments(comments); } + +// void GxsCommentTreeWidget::service_loadThread(const uint32_t &token) +// { +// std::cerr << "GxsCommentTreeWidget::service_loadThread() ERROR must be overloaded!"; +// std::cerr << std::endl; +// +// std::vector comments; +// mCommentService->getRelatedComments(token, comments); +// +// // This is inconsistent since we cannot know here that all comments are for the same thread. However they are only +// // requested in requestComments() where a single MsgId is used. +// +// if(mUseCache) +// { +// QMutexLocker lock(&mCacheMutex); +// +// if(!comments.empty()) +// { +// std::cerr << "Updating cache with " << comments.size() << " for thread " << comments[0].mMeta.mThreadId << std::endl; +// mCommentsCache[comments[0].mMeta.mThreadId] = comments; +// } +// } +// +// insertComments(comments); +// } + void GxsCommentTreeWidget::insertComments(const std::vector& comments) { std::list new_comments; @@ -886,9 +981,9 @@ void GxsCommentTreeWidget::loadRequest(const TokenQueue *queue, const TokenReque acknowledgeComment(req.mToken); } break; - case RS_TOKREQ_ANSTYPE_DATA: - loadThread(req.mToken); - break; +// case RS_TOKREQ_ANSTYPE_DATA: +// loadThread(req.mToken); +// break; } } break; diff --git a/retroshare-gui/src/gui/gxs/GxsCommentTreeWidget.h b/retroshare-gui/src/gui/gxs/GxsCommentTreeWidget.h index c4840eb46..c750b1fcd 100644 --- a/retroshare-gui/src/gui/gxs/GxsCommentTreeWidget.h +++ b/retroshare-gui/src/gui/gxs/GxsCommentTreeWidget.h @@ -56,7 +56,7 @@ protected: /* to be overloaded */ virtual void service_requestComments(const RsGxsGroupId &group_id, const std::set &msgIds); - virtual void service_loadThread(const uint32_t &token); + virtual void service_loadThread(const std::vector& comments); virtual QTreeWidgetItem *service_createMissingItem(const RsGxsMessageId& parent); @@ -66,10 +66,12 @@ protected: void acknowledgeComment(const uint32_t& token); void acknowledgeVote(const uint32_t &token); - void loadThread(const uint32_t &token); + //void loadThread(const uint32_t &token); void insertComments(const std::vector& comments); void addItem(RsGxsMessageId itemId, RsGxsMessageId parentId, QTreeWidgetItem *item); + + static int treeCount(QTreeWidget *tree, QTreeWidgetItem *parent = 0); public slots: void customPopUpMenu(const QPoint& point); void setCurrentCommentMsgId(QTreeWidgetItem* current, QTreeWidgetItem* previous);