From ac4b9b297131df19a21f9489a5b9c2df2d5b49a6 Mon Sep 17 00:00:00 2001 From: csoler Date: Sat, 9 Jul 2022 22:33:42 +0200 Subject: [PATCH] removed token system from GxsCommentDialog --- .../gui/Posted/PostedListWidgetWithModel.cpp | 2 +- .../src/gui/feeds/BoardsCommentsItem.cpp | 16 ++- .../src/gui/feeds/ChannelsCommentsItem.cpp | 2 +- .../src/gui/feeds/GxsChannelPostItem.cpp | 2 +- .../src/gui/feeds/GxsForumMsgItem.cpp | 19 +-- .../src/gui/gxs/GxsCommentContainer.cpp | 2 +- .../src/gui/gxs/GxsCommentDialog.cpp | 8 +- retroshare-gui/src/gui/gxs/GxsCommentDialog.h | 4 +- .../src/gui/gxs/GxsCommentTreeWidget.cpp | 123 +----------------- .../src/gui/gxs/GxsCommentTreeWidget.h | 13 +- .../src/gui/gxs/GxsGroupFrameDialog.cpp | 2 +- .../gui/gxschannels/GxsChannelPostsModel.cpp | 4 +- .../GxsChannelPostsWidgetWithModel.cpp | 4 +- 13 files changed, 42 insertions(+), 159 deletions(-) diff --git a/retroshare-gui/src/gui/Posted/PostedListWidgetWithModel.cpp b/retroshare-gui/src/gui/Posted/PostedListWidgetWithModel.cpp index 1eae122fe..9a46b65f0 100644 --- a/retroshare-gui/src/gui/Posted/PostedListWidgetWithModel.cpp +++ b/retroshare-gui/src/gui/Posted/PostedListWidgetWithModel.cpp @@ -795,7 +795,7 @@ void PostedListWidgetWithModel::openComments(const RsGxsMessageId& msgId) ui->idChooser->getChosenId(current_author); RsPostedPost post = index.data(Qt::UserRole).value() ; - auto *commentDialog = new GxsCommentDialog(this,current_author,rsPosted->getTokenService(),rsPosted); + auto *commentDialog = new GxsCommentDialog(this,current_author,rsPosted); std::set msg_versions({post.mMeta.mMsgId}); commentDialog->commentLoad(post.mMeta.mGroupId, msg_versions, post.mMeta.mMsgId); diff --git a/retroshare-gui/src/gui/feeds/BoardsCommentsItem.cpp b/retroshare-gui/src/gui/feeds/BoardsCommentsItem.cpp index 814a915d9..02af1afc3 100644 --- a/retroshare-gui/src/gui/feeds/BoardsCommentsItem.cpp +++ b/retroshare-gui/src/gui/feeds/BoardsCommentsItem.cpp @@ -28,6 +28,7 @@ #include "gui/feeds/FeedHolder.h" #include "gui/RetroShareLink.h" #include "gui/gxs/GxsIdDetails.h" +#include "util/qtthreadsutils.h" #include "util/DateTime.h" #include "util/misc.h" #include "util/stringutil.h" @@ -286,12 +287,15 @@ void BaseBoardsCommentsItem::readToggled(bool checked) return; } - RsGxsGrpMsgIdPair msgPair = std::make_pair(groupId(), messageId()); - - uint32_t token; - rsPosted->setMessageReadStatus(token, msgPair, !checked); - - setReadStatus(false, checked); + RsThread::async( [this,checked]() { + RsGxsGrpMsgIdPair msgPair = std::make_pair(groupId(), messageId()); + + rsPosted->setCommentReadStatus(msgPair, !checked); + + RsQThreadUtils::postToObject( [this,checked]() { + setReadStatus(false, checked); + } ); + }); } void BaseBoardsCommentsItem::readAndClearItem() diff --git a/retroshare-gui/src/gui/feeds/ChannelsCommentsItem.cpp b/retroshare-gui/src/gui/feeds/ChannelsCommentsItem.cpp index 7f1b23a92..296f3f173 100644 --- a/retroshare-gui/src/gui/feeds/ChannelsCommentsItem.cpp +++ b/retroshare-gui/src/gui/feeds/ChannelsCommentsItem.cpp @@ -617,7 +617,7 @@ void ChannelsCommentsItem::readToggled(bool /*checked*/) RsGxsGrpMsgIdPair msgPair = std::make_pair(groupId(), messageId()); - rsGxsChannels->markRead(msgPair, isUnread()); + rsGxsChannels->setCommentReadStatus(msgPair, isUnread()); //setReadStatus(false, checked); // Updated by events } diff --git a/retroshare-gui/src/gui/feeds/GxsChannelPostItem.cpp b/retroshare-gui/src/gui/feeds/GxsChannelPostItem.cpp index 962ee5327..102dfb637 100644 --- a/retroshare-gui/src/gui/feeds/GxsChannelPostItem.cpp +++ b/retroshare-gui/src/gui/feeds/GxsChannelPostItem.cpp @@ -850,7 +850,7 @@ void GxsChannelPostItem::readToggled(bool /*checked*/) RsGxsGrpMsgIdPair msgPair = std::make_pair(groupId(), messageId()); - rsGxsChannels->markRead(msgPair, isUnread()); + rsGxsChannels->setMessageReadStatus(msgPair, isUnread()); //setReadStatus(false, checked); // Updated by events } diff --git a/retroshare-gui/src/gui/feeds/GxsForumMsgItem.cpp b/retroshare-gui/src/gui/feeds/GxsForumMsgItem.cpp index 5c33b4f13..8bf4899f1 100644 --- a/retroshare-gui/src/gui/feeds/GxsForumMsgItem.cpp +++ b/retroshare-gui/src/gui/feeds/GxsForumMsgItem.cpp @@ -475,18 +475,21 @@ void GxsForumMsgItem::unsubscribeForum() void GxsForumMsgItem::setAsRead() { - if (mInFill) { - return; - } + if (mInFill) { + return; + } - mCloseOnRead = false; + mCloseOnRead = false; - RsGxsGrpMsgIdPair msgPair = std::make_pair(groupId(), messageId()); + RsThread::async( [this]() { + RsGxsGrpMsgIdPair msgPair = std::make_pair(groupId(), messageId()); - uint32_t token; - rsGxsForums->setMessageReadStatus(token, msgPair, true); + rsGxsForums->markRead(msgPair, true); - setReadStatus(false, false); + RsQThreadUtils::postToObject( [this]() { + setReadStatus(false, true); + } ); + }); } void GxsForumMsgItem::on_linkActivated(QString link) diff --git a/retroshare-gui/src/gui/gxs/GxsCommentContainer.cpp b/retroshare-gui/src/gui/gxs/GxsCommentContainer.cpp index b80539cea..5d899104e 100644 --- a/retroshare-gui/src/gui/gxs/GxsCommentContainer.cpp +++ b/retroshare-gui/src/gui/gxs/GxsCommentContainer.cpp @@ -60,7 +60,7 @@ void GxsCommentContainer::commentLoad(const RsGxsGroupId &grpId, const std::set< comments += "..."; } - GxsCommentDialog *commentDialog = new GxsCommentDialog(this, RsGxsId(),getTokenService(), getCommentService()); + GxsCommentDialog *commentDialog = new GxsCommentDialog(this, RsGxsId(),getCommentService()); QWidget *commentHeader = createHeaderWidget(grpId, msgId); commentDialog->setCommentHeader(commentHeader); diff --git a/retroshare-gui/src/gui/gxs/GxsCommentDialog.cpp b/retroshare-gui/src/gui/gxs/GxsCommentDialog.cpp index b610f9dd3..80d7c9739 100644 --- a/retroshare-gui/src/gui/gxs/GxsCommentDialog.cpp +++ b/retroshare-gui/src/gui/gxs/GxsCommentDialog.cpp @@ -30,13 +30,13 @@ #include /** Constructor */ -GxsCommentDialog::GxsCommentDialog(QWidget *parent, const RsGxsId &default_author, RsTokenService *token_service, RsGxsCommentService *comment_service) +GxsCommentDialog::GxsCommentDialog(QWidget *parent, const RsGxsId &default_author, RsGxsCommentService *comment_service) : QWidget(parent), ui(new Ui::GxsCommentDialog) { /* Invoke the Qt Designer generated QObject setup routine */ ui->setupUi(this); - setTokenService(token_service,comment_service); + setTokenService(comment_service); init(default_author); } @@ -67,9 +67,9 @@ void GxsCommentDialog::init(const RsGxsId& default_author) ui->sortBox->setIconSize(QSize(S*1.5,S*1.5)); } -void GxsCommentDialog::setTokenService(RsTokenService *token_service, RsGxsCommentService *comment_service) +void GxsCommentDialog::setTokenService(RsGxsCommentService *comment_service) { - ui->treeWidget->setup(token_service, comment_service); + ui->treeWidget->setup(comment_service); } GxsCommentDialog::GxsCommentDialog(QWidget *parent,const RsGxsId &default_author) diff --git a/retroshare-gui/src/gui/gxs/GxsCommentDialog.h b/retroshare-gui/src/gui/gxs/GxsCommentDialog.h index 4be6edede..ed3c048e6 100644 --- a/retroshare-gui/src/gui/gxs/GxsCommentDialog.h +++ b/retroshare-gui/src/gui/gxs/GxsCommentDialog.h @@ -33,10 +33,10 @@ class GxsCommentDialog: public QWidget public: GxsCommentDialog(QWidget *parent=nullptr,const RsGxsId& default_author=RsGxsId()); - GxsCommentDialog(QWidget *parent,const RsGxsId& default_author, RsTokenService *token_service, RsGxsCommentService *comment_service); + GxsCommentDialog(QWidget *parent, const RsGxsId& default_author, RsGxsCommentService *comment_service); virtual ~GxsCommentDialog(); - void setTokenService(RsTokenService *token_service, RsGxsCommentService *comment_service); + void setTokenService(RsGxsCommentService *comment_service); void setCommentHeader(QWidget *header); void commentLoad(const RsGxsGroupId &grpId, const std::set &msg_versions, const RsGxsMessageId &most_recent_msgId, bool use_cache=false); void commentClear(); diff --git a/retroshare-gui/src/gui/gxs/GxsCommentTreeWidget.cpp b/retroshare-gui/src/gui/gxs/GxsCommentTreeWidget.cpp index 4d5fd4708..0b65b7c3d 100644 --- a/retroshare-gui/src/gui/gxs/GxsCommentTreeWidget.cpp +++ b/retroshare-gui/src/gui/gxs/GxsCommentTreeWidget.cpp @@ -249,7 +249,7 @@ void GxsCommentTreeWidget::mouseMoveEvent(QMouseEvent *e) } GxsCommentTreeWidget::GxsCommentTreeWidget(QWidget *parent) - :QTreeWidget(parent), mTokenQueue(NULL), mRsTokenService(NULL), mCommentService(NULL) + :QTreeWidget(parent), mCommentService(NULL) { setVerticalScrollMode(ScrollPerPixel); setContextMenuPolicy(Qt::CustomContextMenu); @@ -299,9 +299,6 @@ void GxsCommentTreeWidget::updateContent() } GxsCommentTreeWidget::~GxsCommentTreeWidget() { - if (mTokenQueue) { - delete(mTokenQueue); - } } void GxsCommentTreeWidget::setCurrentCommentMsgId(QTreeWidgetItem *current, QTreeWidgetItem *previous) @@ -420,10 +417,6 @@ void GxsCommentTreeWidget::vote(const RsGxsGroupId &groupId, const RsGxsMessageI QMessageBox::critical(nullptr,tr("Cannot vote"),tr("Error while voting: ")+QString::fromStdString(error_string)); }); }); - - // uint32_t token; - // mCommentService->createNewVote(token, vote); - // mTokenQueue->queueRequest(token, TOKENREQ_MSGINFO, RS_TOKREQ_ANSTYPE_ACK, COMMENT_VOTE_ACK); } @@ -478,12 +471,10 @@ void GxsCommentTreeWidget::copyComment() clipboard->setMimeData(mimeData, QClipboard::Clipboard); } -void GxsCommentTreeWidget::setup(RsTokenService *token_service, RsGxsCommentService *comment_service) +void GxsCommentTreeWidget::setup(RsGxsCommentService *comment_service) { - mRsTokenService = token_service; mCommentService = comment_service; - mTokenQueue = new TokenQueue(token_service, this); - connect(this, SIGNAL(customContextMenuRequested(QPoint)), this, SLOT(customPopUpMenu(QPoint))); + connect(this, SIGNAL(customContextMenuRequested(QPoint)), this, SLOT(customPopUpMenu(QPoint))); connect(this, SIGNAL(currentItemChanged(QTreeWidgetItem*,QTreeWidgetItem*)), this, SLOT(setCurrentCommentMsgId(QTreeWidgetItem*, QTreeWidgetItem*))); return; @@ -743,36 +734,6 @@ int GxsCommentTreeWidget::treeCount(QTreeWidget *tree, QTreeWidgetItem *parent) } return count; } -// void GxsCommentTreeWidget::loadThread(const uint32_t &token) -// { -// clearItems(); -// -// service_loadThread(token); -// -// completeItems(); -// -// emit commentsLoaded(treeCount(this)); -// } - -void GxsCommentTreeWidget::acknowledgeComment(const uint32_t &token) -{ - RsGxsGrpMsgIdPair msgId; - mCommentService->acknowledgeComment(token, msgId); - - // simply reload data - service_requestComments(mGroupId,mMsgVersions); -} - - -void GxsCommentTreeWidget::acknowledgeVote(const uint32_t &token) -{ - RsGxsGrpMsgIdPair msgId; - if (mCommentService->acknowledgeVote(token, msgId)) - { - // reload data if vote was added. - service_requestComments(mGroupId,mMsgVersions); - } -} void GxsCommentTreeWidget::service_loadThread(const std::vector& comments) { @@ -796,32 +757,6 @@ void GxsCommentTreeWidget::service_loadThread(const std::vector& c 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; @@ -892,10 +827,7 @@ void GxsCommentTreeWidget::insertComments(const std::vector& comme // now set all loaded comments as not new, since they have been loaded. for(auto cid:new_comments) - { - uint32_t token=0; - mCommentService->setCommentAsRead(token,mGroupId,cid); - } + mCommentService->setCommentReadStatus(RsGxsGrpMsgIdPair(mGroupId,cid),true); } QTreeWidgetItem *GxsCommentTreeWidget::service_createMissingItem(const RsGxsMessageId& parent) @@ -923,50 +855,3 @@ QTreeWidgetItem *GxsCommentTreeWidget::service_createMissingItem(const RsGxsMess return item; } - - -void GxsCommentTreeWidget::loadRequest(const TokenQueue *queue, const TokenRequest &req) -{ -#ifdef DEBUG_GXSCOMMENT_TREEWIDGET - std::cerr << "GxsCommentTreeWidget::loadRequest() UserType: " << req.mUserType; - std::cerr << std::endl; -#endif - - if (queue != mTokenQueue) - { - std::cerr << "GxsCommentTreeWidget::loadRequest() Queue ERROR"; - std::cerr << std::endl; - return; - } - - /* now switch on req */ - switch(req.mType) - { - - case TOKENREQ_MSGINFO: - { - switch(req.mAnsType) - { - case RS_TOKREQ_ANSTYPE_ACK: - if (req.mUserType == COMMENT_VOTE_ACK) - { - acknowledgeVote(req.mToken); - } - else - { - acknowledgeComment(req.mToken); - } - break; -// case RS_TOKREQ_ANSTYPE_DATA: -// loadThread(req.mToken); -// break; - } - } - break; - default: - std::cerr << "GxsCommentTreeWidget::loadRequest() UNKNOWN UserType "; - std::cerr << std::endl; - break; - - } -} diff --git a/retroshare-gui/src/gui/gxs/GxsCommentTreeWidget.h b/retroshare-gui/src/gui/gxs/GxsCommentTreeWidget.h index c750b1fcd..43a6f55a5 100644 --- a/retroshare-gui/src/gui/gxs/GxsCommentTreeWidget.h +++ b/retroshare-gui/src/gui/gxs/GxsCommentTreeWidget.h @@ -24,26 +24,24 @@ #include #include -#include "util/TokenQueue.h" #include #include class RSTreeWidgetItemCompareRole; -class GxsCommentTreeWidget : public QTreeWidget, public TokenResponse +class GxsCommentTreeWidget : public QTreeWidget { Q_OBJECT public: GxsCommentTreeWidget(QWidget *parent = 0); ~GxsCommentTreeWidget(); - void setup(RsTokenService *token_service, RsGxsCommentService *comment_service); + void setup(RsGxsCommentService *comment_service); void requestComments(const RsGxsGroupId& group, const std::set &message_versions, const RsGxsMessageId &most_recent_message); void getCurrentMsgId(RsGxsMessageId& parentId); void applyRankings(std::map& positions); - void loadRequest(const TokenQueue *queue, const TokenRequest &req); void setVoteId(const RsGxsId &voterId); void setUseCache(bool b) { mUseCache = b ;} @@ -63,11 +61,6 @@ protected: void clearItems(); void completeItems(); - void acknowledgeComment(const uint32_t& token); - void acknowledgeVote(const uint32_t &token); - - //void loadThread(const uint32_t &token); - void insertComments(const std::vector& comments); void addItem(RsGxsMessageId itemId, RsGxsMessageId parentId, QTreeWidgetItem *item); @@ -114,8 +107,6 @@ protected: RSTreeWidgetItemCompareRole *commentsRole; - TokenQueue *mTokenQueue; - RsTokenService *mRsTokenService; RsGxsCommentService *mCommentService; bool mUseCache; diff --git a/retroshare-gui/src/gui/gxs/GxsGroupFrameDialog.cpp b/retroshare-gui/src/gui/gxs/GxsGroupFrameDialog.cpp index 425b87faf..283d1f48f 100644 --- a/retroshare-gui/src/gui/gxs/GxsGroupFrameDialog.cpp +++ b/retroshare-gui/src/gui/gxs/GxsGroupFrameDialog.cpp @@ -724,7 +724,7 @@ void GxsGroupFrameDialog::loadComment(const RsGxsGroupId &grpId, const QVectorgetTokenService(), commentService); + commentDialog = new GxsCommentDialog(this,RsGxsId(), commentService); QWidget *commentHeader = createCommentHeaderWidget(grpId, most_recent_msgId); if (commentHeader) { diff --git a/retroshare-gui/src/gui/gxschannels/GxsChannelPostsModel.cpp b/retroshare-gui/src/gui/gxschannels/GxsChannelPostsModel.cpp index 31eef8242..06b671532 100644 --- a/retroshare-gui/src/gui/gxschannels/GxsChannelPostsModel.cpp +++ b/retroshare-gui/src/gui/gxschannels/GxsChannelPostsModel.cpp @@ -798,7 +798,7 @@ void RsGxsChannelPostsModel::setAllMsgReadStatus(bool read_status) for(uint32_t i=0;imarkRead(p,read_status)) + if(!rsGxsChannels->setMessageReadStatus(p,read_status)) RsErr() << "setAllMsgReadStatus: failed to change status of msg " << p.first << " in group " << p.second << " to status " << read_status << std::endl; }); } @@ -816,7 +816,7 @@ void RsGxsChannelPostsModel::setMsgReadStatus(const QModelIndex& i,bool read_sta if(!convertRefPointerToTabEntry(ref,entry) || entry >= mFilteredPosts.size()) return ; - rsGxsChannels->markRead(RsGxsGrpMsgIdPair(mPosts[mFilteredPosts[entry]].mMeta.mGroupId,mPosts[mFilteredPosts[entry]].mMeta.mMsgId),read_status); + rsGxsChannels->setMessageReadStatus(RsGxsGrpMsgIdPair(mPosts[mFilteredPosts[entry]].mMeta.mGroupId,mPosts[mFilteredPosts[entry]].mMeta.mMsgId),read_status); } QModelIndex RsGxsChannelPostsModel::getIndexOfMessage(const RsGxsMessageId& mid) const diff --git a/retroshare-gui/src/gui/gxschannels/GxsChannelPostsWidgetWithModel.cpp b/retroshare-gui/src/gui/gxschannels/GxsChannelPostsWidgetWithModel.cpp index 129a6a1bf..9fe8e830e 100644 --- a/retroshare-gui/src/gui/gxschannels/GxsChannelPostsWidgetWithModel.cpp +++ b/retroshare-gui/src/gui/gxschannels/GxsChannelPostsWidgetWithModel.cpp @@ -487,7 +487,7 @@ GxsChannelPostsWidgetWithModel::GxsChannelPostsWidgetWithModel(const RsGxsGroupI setAutoDownload(false); #endif - ui->commentsDialog->setTokenService(rsGxsChannels->getTokenService(),rsGxsChannels); + ui->commentsDialog->setTokenService(rsGxsChannels); /* Initialize GUI */ settingsChanged(); @@ -852,7 +852,7 @@ void GxsChannelPostsWidgetWithModel::showPostDetails() postId.second = post.mMeta.mMsgId; postId.first = post.mMeta.mGroupId; - RsThread::async([postId]() { rsGxsChannels->markRead(postId, true) ; } ); + RsThread::async([postId]() { rsGxsChannels->setMessageReadStatus(postId, true) ; } ); } updateDAll_PB();