added blocking API for createComment() in GxsCommentService and removed token queue from GxsCreateCommentDialog

This commit is contained in:
csoler 2020-03-09 21:01:55 +01:00
parent ab2c1f23e9
commit dc3c3488df
No known key found for this signature in database
GPG Key ID: 7BCA522266C0804C
11 changed files with 26 additions and 31 deletions

View File

@ -157,7 +157,9 @@ struct RsGxsCommentService
virtual bool getRelatedComments( uint32_t token,
std::vector<RsGxsComment> &comments ) = 0;
virtual bool createNewComment(uint32_t &token, RsGxsComment &comment) = 0;
virtual bool createNewComment(uint32_t &token, const RsGxsComment &comment) = 0; // async API
virtual bool createComment(RsGxsComment& comment) = 0; // blocking API. Updates comment with new metadata.
virtual bool createNewVote(uint32_t &token, RsGxsVote &vote) = 0;
virtual bool acknowledgeComment(

View File

@ -140,7 +140,7 @@ virtual bool getChannelDownloadDirectory(const RsGxsGroupId &groupId, std::strin
std::vector<RsGxsComment> &msgs ) override
{ return mCommentService->getGxsRelatedComments(token, msgs); }
virtual bool createNewComment(uint32_t &token, RsGxsComment &msg) override
virtual bool createNewComment(uint32_t &token, const RsGxsComment &msg) override
{
return mCommentService->createGxsComment(token, msg);
}
@ -277,7 +277,7 @@ virtual bool ExtraFileRemove(const RsFileHash &hash);
/// @deprecated Implementation of @see RsGxsChannels::createComment
RS_DEPRECATED_FOR(createCommentV2)
bool createComment(RsGxsComment& comment) override;
bool createComment(RsGxsComment &comment) override;
/// @deprecated Implementation of @see RsGxsChannels::createVote
RS_DEPRECATED_FOR(createVoteV2)

View File

@ -425,7 +425,7 @@ double p3GxsCommentService::calculateBestScore(int upVotes, int downVotes)
/********************************************************************************************/
bool p3GxsCommentService::createGxsComment(uint32_t &token, RsGxsComment &msg)
bool p3GxsCommentService::createGxsComment(uint32_t &token, const RsGxsComment &msg)
{
#ifdef DEBUG_GXSCOMMON
std::cerr << "p3GxsCommentService::createGxsComment() GroupId: " << msg.mMeta.mGroupId;

View File

@ -66,7 +66,7 @@ class p3GxsCommentService: public GxsTokenQueue
bool getGxsCommentData(const uint32_t &token, std::vector<RsGxsComment> &msgs);
bool getGxsRelatedComments(const uint32_t &token, std::vector<RsGxsComment> &msgs);
bool createGxsComment(uint32_t &token, RsGxsComment &msg);
bool createGxsComment(uint32_t &token, const RsGxsComment &msg);
bool createGxsVote(uint32_t &token, RsGxsVote &msg);
// Special Acknowledge.

View File

@ -85,7 +85,7 @@ public:
return mCommentService->getGxsRelatedComments(token, msgs);
}
virtual bool createNewComment(uint32_t &token, RsGxsComment &msg) override
virtual bool createNewComment(uint32_t &token, const RsGxsComment &msg) override
{
return mCommentService->createGxsComment(token, msg);
}

View File

@ -96,10 +96,16 @@ virtual void setMessageReadStatus(uint32_t& token, const RsGxsGrpMsgIdPair& msgI
std::vector<RsGxsComment> &msgs )
{ return mCommentService->getGxsRelatedComments(token, msgs); }
virtual bool createNewComment(uint32_t &token, RsGxsComment &msg)
virtual bool createNewComment(uint32_t &token, const RsGxsComment &msg) override
{
return mCommentService->createGxsComment(token, msg);
}
virtual bool createComment(RsGxsComment& msg) override
{
uint32_t token;
return mCommentService->createGxsComment(token, msg) && waitToken(token) == RsTokenService::COMPLETE ;
}
virtual bool createNewVote(uint32_t &token, RsGxsVote &msg)
{

View File

@ -47,7 +47,7 @@
PostedCreatePostDialog::PostedCreatePostDialog(TokenQueue* tokenQ, RsPosted *posted, const RsGxsGroupId& grpId, QWidget *parent):
QDialog(parent, Qt::WindowSystemMenuHint | Qt::WindowTitleHint | Qt::WindowMinimizeButtonHint | Qt::WindowMaximizeButtonHint | Qt::WindowCloseButtonHint),
mTokenQueue(tokenQ), mPosted(posted), mGrpId(grpId),
mPosted(posted), mGrpId(grpId),
ui(new Ui::PostedCreatePostDialog)
{
ui->setupUi(this);
@ -176,7 +176,6 @@ void PostedCreatePostDialog::createPost()
uint32_t token;
mPosted->createPost(token, post);
// mTokenQueue->queueRequest(token, TOKENREQ_MSGINFO, RS_TOKREQ_ANSTYPE_ACK, TOKEN_USER_TYPE_POST);
accept();
}

View File

@ -62,7 +62,6 @@ private:
QString mLink;
QString mNotes;
TokenQueue* mTokenQueue;
RsPosted* mPosted;
RsGxsGroupId mGrpId;

View File

@ -307,7 +307,7 @@ void GxsCommentTreeWidget::banUser()
void GxsCommentTreeWidget::makeComment()
{
GxsCreateCommentDialog pcc(mTokenQueue, mCommentService, std::make_pair(mGroupId,mLatestMsgId), mLatestMsgId, this);
GxsCreateCommentDialog pcc(mCommentService, std::make_pair(mGroupId,mLatestMsgId), mLatestMsgId, this);
pcc.exec();
}
@ -316,7 +316,7 @@ void GxsCommentTreeWidget::replyToComment()
RsGxsGrpMsgIdPair msgId;
msgId.first = mGroupId;
msgId.second = mCurrentCommentMsgId;
GxsCreateCommentDialog pcc(mTokenQueue, mCommentService, msgId, mLatestMsgId, this);
GxsCreateCommentDialog pcc(mCommentService, msgId, mLatestMsgId, this);
pcc.loadComment(mCurrentCommentText, mCurrentCommentAuthor, mCurrentCommentAuthorId);
pcc.exec();

View File

@ -26,20 +26,16 @@
#include <QMessageBox>
#include <iostream>
GxsCreateCommentDialog::GxsCreateCommentDialog(TokenQueue *tokQ, RsGxsCommentService *service,
const RsGxsGrpMsgIdPair &parentId, const RsGxsMessageId& threadId, QWidget *parent) :
GxsCreateCommentDialog::GxsCreateCommentDialog(RsGxsCommentService *service, const RsGxsGrpMsgIdPair &parentId, const RsGxsMessageId& threadId, QWidget *parent) :
QDialog(parent),
ui(new Ui::GxsCreateCommentDialog), mTokenQueue(tokQ), mCommentService(service), mParentId(parentId), mThreadId(threadId)
ui(new Ui::GxsCreateCommentDialog), mCommentService(service), mParentId(parentId), mThreadId(threadId)
{
ui->setupUi(this);
connect(ui->buttonBox, SIGNAL(accepted()), this, SLOT(createComment()));
connect(ui->buttonBox, SIGNAL(rejected()), this, SLOT(close()));
/* fill in the available OwnIds for signing */
ui->idChooser->loadIds(IDCHOOSER_ID_REQUIRED, RsGxsId());
}
void GxsCreateCommentDialog::loadComment(const QString &msgText, const QString &msgAuthor, const RsGxsId &msgAuthorId)
@ -80,9 +76,9 @@ void GxsCreateCommentDialog::createComment()
std::cerr << "ThreadId : " << comment.mMeta.mThreadId << std::endl;
std::cerr << "ParentId : " << comment.mMeta.mParentId << std::endl;
RsGxsId authorId;
switch (ui->idChooser->getChosenId(authorId)) {
switch (ui->idChooser->getChosenId(authorId))
{
case GxsIdChooser::KnowId:
case GxsIdChooser::UnKnowId:
comment.mMeta.mAuthorId = authorId;
@ -96,17 +92,12 @@ void GxsCreateCommentDialog::createComment()
std::cerr << "GxsCreateCommentDialog::createComment() ERROR GETTING AuthorId!";
std::cerr << std::endl;
int ret = QMessageBox::information(this, tr("Comment Signing Error"),
tr("You need to create an Identity\n"
"before you can comment"),
QMessageBox::Ok);
Q_UNUSED(ret)
QMessageBox::information(this, tr("Comment Signing Error"), tr("You need to create an Identity\n" "before you can comment"), QMessageBox::Ok);
return;
}//switch (ui->idChooser->getChosenId(authorId))
}
uint32_t token;
mCommentService->createNewComment(token, comment);
mTokenQueue->queueRequest(token, TOKENREQ_MSGINFO, RS_TOKREQ_ANSTYPE_ACK, 0);
mCommentService->createComment(comment);
close();
}

View File

@ -36,8 +36,7 @@ class GxsCreateCommentDialog : public QDialog
Q_OBJECT
public:
explicit GxsCreateCommentDialog(TokenQueue* tokQ, RsGxsCommentService *service,
const RsGxsGrpMsgIdPair& parentId, const RsGxsMessageId& threadId, QWidget *parent = 0);
explicit GxsCreateCommentDialog(RsGxsCommentService *service, const RsGxsGrpMsgIdPair& parentId, const RsGxsMessageId& threadId, QWidget *parent = 0);
~GxsCreateCommentDialog();
void loadComment(const QString &msgText, const QString &msgAuthor, const RsGxsId &msgAuthorId);
@ -47,7 +46,6 @@ private slots:
private:
Ui::GxsCreateCommentDialog *ui;
TokenQueue *mTokenQueue;
RsGxsCommentService *mCommentService;
RsGxsGrpMsgIdPair mParentId;