From 54fd77822d6810936841c4d7b8e9f209703a07c6 Mon Sep 17 00:00:00 2001 From: csoler Date: Thu, 30 Jun 2022 14:43:04 +0200 Subject: [PATCH] fixed blocking API for votes --- .../gui/Posted/PostedListWidgetWithModel.cpp | 7 ++- .../src/gui/gxs/GxsCommentTreeWidget.cpp | 49 +++++++------------ 2 files changed, 24 insertions(+), 32 deletions(-) diff --git a/retroshare-gui/src/gui/Posted/PostedListWidgetWithModel.cpp b/retroshare-gui/src/gui/Posted/PostedListWidgetWithModel.cpp index 7c55931fa..0db786c01 100644 --- a/retroshare-gui/src/gui/Posted/PostedListWidgetWithModel.cpp +++ b/retroshare-gui/src/gui/Posted/PostedListWidgetWithModel.cpp @@ -1204,7 +1204,12 @@ void PostedListWidgetWithModel::voteMsg(RsGxsGrpMsgIdPair msg,bool up_or_down) return; } - rsPosted->voteForPost(up_or_down,msg.first,msg.second,voter_id); + RsGxsVoteType tvote = up_or_down?(RsGxsVoteType::UP):(RsGxsVoteType::DOWN); + + std::string error_str; + RsGxsMessageId vote_id; + if(!rsPosted->voteForPost(msg.first,msg.second,voter_id,tvote,vote_id,error_str)) + QMessageBox::critical(nullptr,tr("Could not vote"), tr("Error occured while voting: ")+QString::fromStdString(error_str)); } #ifdef TODO diff --git a/retroshare-gui/src/gui/gxs/GxsCommentTreeWidget.cpp b/retroshare-gui/src/gui/gxs/GxsCommentTreeWidget.cpp index 481ad0e81..4d5fd4708 100644 --- a/retroshare-gui/src/gui/gxs/GxsCommentTreeWidget.cpp +++ b/retroshare-gui/src/gui/gxs/GxsCommentTreeWidget.cpp @@ -32,6 +32,7 @@ #include #include #include +#include #include #include #include @@ -402,35 +403,27 @@ void GxsCommentTreeWidget::setVoteId(const RsGxsId &voterId) void GxsCommentTreeWidget::vote(const RsGxsGroupId &groupId, const RsGxsMessageId &threadId, const RsGxsMessageId &parentId, const RsGxsId &authorId, bool up) { - RsGxsVote vote; + RsThread::async([this,groupId,threadId,parentId,authorId,up]() + { + std::string error_string; + RsGxsMessageId vote_id; + RsGxsVoteType tvote = up?(RsGxsVoteType::UP):(RsGxsVoteType::DOWN); - vote.mMeta.mGroupId = groupId; - vote.mMeta.mThreadId = threadId; - vote.mMeta.mParentId = parentId; - vote.mMeta.mAuthorId = authorId; + bool res = mCommentService->voteForComment(groupId, threadId, parentId, authorId,tvote,vote_id, error_string); - if (up) - { - vote.mVoteType = GXS_VOTE_UP; - } - else - { - vote.mVoteType = GXS_VOTE_DOWN; - } + RsQThreadUtils::postToObject( [this,res,error_string]() + { -#ifdef DEBUG_GXSCOMMENT_TREEWIDGET - std::cerr << "GxsCommentTreeWidget::vote()"; - std::cerr << std::endl; + if(res) + service_requestComments(mGroupId,mMsgVersions); + else + QMessageBox::critical(nullptr,tr("Cannot vote"),tr("Error while voting: ")+QString::fromStdString(error_string)); + }); + }); - std::cerr << "GroupId : " << vote.mMeta.mGroupId << std::endl; - std::cerr << "ThreadId : " << vote.mMeta.mThreadId << std::endl; - std::cerr << "ParentId : " << vote.mMeta.mParentId << std::endl; - std::cerr << "AuthorId : " << vote.mMeta.mAuthorId << std::endl; -#endif - - uint32_t token; - mCommentService->createNewVote(token, vote); - mTokenQueue->queueRequest(token, TOKENREQ_MSGINFO, RS_TOKREQ_ANSTYPE_ACK, COMMENT_VOTE_ACK); + // uint32_t token; + // mCommentService->createNewVote(token, vote); + // mTokenQueue->queueRequest(token, TOKENREQ_MSGINFO, RS_TOKREQ_ANSTYPE_ACK, COMMENT_VOTE_ACK); } @@ -558,12 +551,6 @@ void GxsCommentTreeWidget::service_requestComments(const RsGxsGroupId& group_id, }, 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