fixed blocking API for votes

This commit is contained in:
csoler 2022-06-30 14:43:04 +02:00
parent cf61cb3780
commit 54fd77822d
2 changed files with 24 additions and 32 deletions

View File

@ -1204,7 +1204,12 @@ void PostedListWidgetWithModel::voteMsg(RsGxsGrpMsgIdPair msg,bool up_or_down)
return; 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 #ifdef TODO

View File

@ -32,6 +32,7 @@
#include <QTextEdit> #include <QTextEdit>
#include <QHeaderView> #include <QHeaderView>
#include <QClipboard> #include <QClipboard>
#include <QMessageBox>
#include <QDateTime> #include <QDateTime>
#include <QMenu> #include <QMenu>
#include <QMimeData> #include <QMimeData>
@ -402,35 +403,27 @@ void GxsCommentTreeWidget::setVoteId(const RsGxsId &voterId)
void GxsCommentTreeWidget::vote(const RsGxsGroupId &groupId, const RsGxsMessageId &threadId, void GxsCommentTreeWidget::vote(const RsGxsGroupId &groupId, const RsGxsMessageId &threadId,
const RsGxsMessageId &parentId, const RsGxsId &authorId, bool up) const RsGxsMessageId &parentId, const RsGxsId &authorId, bool up)
{ {
RsGxsVote vote; RsThread::async([this,groupId,threadId,parentId,authorId,up]()
vote.mMeta.mGroupId = groupId;
vote.mMeta.mThreadId = threadId;
vote.mMeta.mParentId = parentId;
vote.mMeta.mAuthorId = authorId;
if (up)
{ {
vote.mVoteType = GXS_VOTE_UP; std::string error_string;
} RsGxsMessageId vote_id;
RsGxsVoteType tvote = up?(RsGxsVoteType::UP):(RsGxsVoteType::DOWN);
bool res = mCommentService->voteForComment(groupId, threadId, parentId, authorId,tvote,vote_id, error_string);
RsQThreadUtils::postToObject( [this,res,error_string]()
{
if(res)
service_requestComments(mGroupId,mMsgVersions);
else else
{ QMessageBox::critical(nullptr,tr("Cannot vote"),tr("Error while voting: ")+QString::fromStdString(error_string));
vote.mVoteType = GXS_VOTE_DOWN; });
} });
#ifdef DEBUG_GXSCOMMENT_TREEWIDGET // uint32_t token;
std::cerr << "GxsCommentTreeWidget::vote()"; // mCommentService->createNewVote(token, vote);
std::cerr << std::endl; // mTokenQueue->queueRequest(token, TOKENREQ_MSGINFO, RS_TOKREQ_ANSTYPE_ACK, COMMENT_VOTE_ACK);
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);
} }
@ -558,12 +551,6 @@ void GxsCommentTreeWidget::service_requestComments(const RsGxsGroupId& group_id,
}, 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 #ifdef TODO