removed TokenQueue in CommentsTreeWidget for the display of comments

This commit is contained in:
csoler 2022-06-22 19:07:35 +02:00
parent 819dc173e0
commit 299ad1b1e1
2 changed files with 125 additions and 28 deletions

View File

@ -25,6 +25,7 @@
#include "gui/common/RSTreeWidgetItem.h" #include "gui/common/RSTreeWidgetItem.h"
#include "gui/gxs/GxsCreateCommentDialog.h" #include "gui/gxs/GxsCreateCommentDialog.h"
#include "gui/gxs/GxsIdTreeWidgetItem.h" #include "gui/gxs/GxsIdTreeWidgetItem.h"
#include "util/qtthreadsutils.h"
#include <QAbstractTextDocumentLayout> #include <QAbstractTextDocumentLayout>
#include <QApplication> #include <QApplication>
@ -540,14 +541,86 @@ void GxsCommentTreeWidget::service_requestComments(const RsGxsGroupId& group_id,
ids_to_ask.push_back(std::make_pair(group_id,*it)); ids_to_ask.push_back(std::make_pair(group_id,*it));
} }
RsTokReqOptions opts; RsThread::async([this,group_id,msgIds]()
opts.mReqType = GXS_REQUEST_TYPE_MSG_RELATED_DATA; {
opts.mOptions = RS_TOKREQOPT_MSG_THREAD | RS_TOKREQOPT_MSG_LATEST; std::vector<RsGxsComment> comments;
uint32_t token; if(!mCommentService->getRelatedComments(group_id,msgIds,comments))
mTokenQueue->requestMsgRelatedInfo(token, RS_TOKREQ_ANSTYPE_DATA, opts, ids_to_ask, GXSCOMMENTS_LOADTHREAD); {
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<RsGxsMessageId> msgs_to_request ;
std::vector<RsGxsForumMsg> 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 */ /* Generic Handling */
void GxsCommentTreeWidget::clearItems() 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; int count = 0;
if (parent == 0) if (parent == 0)
@ -694,16 +767,16 @@ int treeCount(QTreeWidget *tree, QTreeWidgetItem *parent = 0)
} }
return count; return count;
} }
void GxsCommentTreeWidget::loadThread(const uint32_t &token) // void GxsCommentTreeWidget::loadThread(const uint32_t &token)
{ // {
clearItems(); // clearItems();
//
service_loadThread(token); // service_loadThread(token);
//
completeItems(); // completeItems();
//
emit commentsLoaded(treeCount(this)); // emit commentsLoaded(treeCount(this));
} // }
void GxsCommentTreeWidget::acknowledgeComment(const uint32_t &token) void GxsCommentTreeWidget::acknowledgeComment(const uint32_t &token)
{ {
@ -725,14 +798,10 @@ void GxsCommentTreeWidget::acknowledgeVote(const uint32_t &token)
} }
} }
void GxsCommentTreeWidget::service_loadThread(const std::vector<RsGxsComment>& comments)
void GxsCommentTreeWidget::service_loadThread(const uint32_t &token)
{ {
std::cerr << "GxsCommentTreeWidget::service_loadThread() ERROR must be overloaded!"; std::cerr << "GxsCommentTreeWidget::service_loadThread() ERROR must be overloaded!";
std::cerr << std::endl; std::cerr << std::endl;
std::vector<RsGxsComment> 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 // 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. // requested in requestComments() where a single MsgId is used.
@ -751,6 +820,32 @@ void GxsCommentTreeWidget::service_loadThread(const uint32_t &token)
insertComments(comments); 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<RsGxsComment> 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<RsGxsComment>& comments) void GxsCommentTreeWidget::insertComments(const std::vector<RsGxsComment>& comments)
{ {
std::list<RsGxsMessageId> new_comments; std::list<RsGxsMessageId> new_comments;
@ -886,9 +981,9 @@ void GxsCommentTreeWidget::loadRequest(const TokenQueue *queue, const TokenReque
acknowledgeComment(req.mToken); acknowledgeComment(req.mToken);
} }
break; break;
case RS_TOKREQ_ANSTYPE_DATA: // case RS_TOKREQ_ANSTYPE_DATA:
loadThread(req.mToken); // loadThread(req.mToken);
break; // break;
} }
} }
break; break;

View File

@ -56,7 +56,7 @@ protected:
/* to be overloaded */ /* to be overloaded */
virtual void service_requestComments(const RsGxsGroupId &group_id, const std::set<RsGxsMessageId> &msgIds); virtual void service_requestComments(const RsGxsGroupId &group_id, const std::set<RsGxsMessageId> &msgIds);
virtual void service_loadThread(const uint32_t &token); virtual void service_loadThread(const std::vector<RsGxsComment>& comments);
virtual QTreeWidgetItem *service_createMissingItem(const RsGxsMessageId& parent); virtual QTreeWidgetItem *service_createMissingItem(const RsGxsMessageId& parent);
@ -66,10 +66,12 @@ protected:
void acknowledgeComment(const uint32_t& token); void acknowledgeComment(const uint32_t& token);
void acknowledgeVote(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<RsGxsComment>& comments); void insertComments(const std::vector<RsGxsComment>& comments);
void addItem(RsGxsMessageId itemId, RsGxsMessageId parentId, QTreeWidgetItem *item); void addItem(RsGxsMessageId itemId, RsGxsMessageId parentId, QTreeWidgetItem *item);
static int treeCount(QTreeWidget *tree, QTreeWidgetItem *parent = 0);
public slots: public slots:
void customPopUpMenu(const QPoint& point); void customPopUpMenu(const QPoint& point);
void setCurrentCommentMsgId(QTreeWidgetItem* current, QTreeWidgetItem* previous); void setCurrentCommentMsgId(QTreeWidgetItem* current, QTreeWidgetItem* previous);