removed most of the token queue system from GxsFeedItems

This commit is contained in:
csoler 2020-02-16 20:57:36 +01:00
parent d1b26c9d36
commit 7e08d24b64
No known key found for this signature in database
GPG key ID: 7BCA522266C0804C
18 changed files with 607 additions and 491 deletions

View file

@ -28,6 +28,7 @@
#include "gui/feeds/FeedHolder.h"
#include "gui/gxs/GxsIdDetails.h"
#include "util/misc.h"
#include "util/qtthreadsutils.h"
#include "util/HandleRichText.h"
#include "ui_PostedCardView.h"
@ -158,88 +159,143 @@ bool PostedCardView::setPost(const RsPostedPost &post, bool doFill)
return true;
}
void PostedCardView::loadGroup(const uint32_t &token)
void PostedCardView::loadGroup()
{
std::vector<RsPostedGroup> groups;
if (!rsPosted->getGroupData(token, groups))
RsThread::async([this]()
{
std::cerr << "PostedCardView::loadGroup() ERROR getting data";
std::cerr << std::endl;
return;
}
// 1 - get group data
if (groups.size() != 1)
{
std::cerr << "PostedCardView::loadGroup() Wrong number of Items";
std::cerr << std::endl;
return;
}
#ifdef DEBUG_FORUMS
std::cerr << "Retrieving post data for post " << mThreadId << std::endl;
#endif
setGroup(groups[0]);
std::vector<RsPostedGroup> groups;
const std::list<RsGxsGroupId> groupIds = { groupId() };
#warning Code needed in rsPosted
#ifdef TODO
if(!rsPosted->getPostedGroupInfo(groupIds,groups))
#endif
{
RsErr() << "GxsPostedGroupItem::loadGroup() ERROR getting data" << std::endl;
return;
}
if (groups.size() != 1)
{
std::cerr << "GxsPostedGroupItem::loadGroup() Wrong number of Items";
std::cerr << std::endl;
return;
}
RsPostedGroup group(groups[0]);
RsQThreadUtils::postToObject( [group,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 */
setGroup(group);
}, this );
});
}
void PostedCardView::loadMessage(const uint32_t &token)
void PostedCardView::loadMessage()
{
std::vector<RsPostedPost> posts;
std::vector<RsGxsComment> cmts;
if (!rsPosted->getPostData(token, posts, cmts))
RsThread::async([this]()
{
std::cerr << "GxsChannelPostItem::loadMessage() ERROR getting data";
std::cerr << std::endl;
return;
}
// 1 - get group data
if (posts.size() == 1)
{
setPost(posts[0]);
}
else if (cmts.size() == 1)
{
RsGxsComment cmt = cmts[0];
std::vector<RsPostedPost> posts;
std::vector<RsGxsComment> comments;
//ui->newCommentLabel->show();
//ui->commLabel->show();
//ui->commLabel->setText(QString::fromUtf8(cmt.mComment.c_str()));
#warning Code needed in rsPosted
#ifdef TODO
if(! rsPosted->getPostedContent( groupId(), std::set<RsGxsMessageId>( { messageId() } ),posts,comments))
#endif
{
RsErr() << "PostedItem::loadMessage() ERROR getting data" << std::endl;
return;
}
if (posts.size() == 1)
{
std::cerr << (void*)this << ": Obtained post, with msgId = " << posts[0].mMeta.mMsgId << std::endl;
const RsPostedPost& post(posts[0]);
RsQThreadUtils::postToObject( [post,this]() { setPost(post); }, this );
}
else if(comments.size() == 1)
{
const RsGxsComment& cmt = comments[0];
std::cerr << (void*)this << ": Obtained comment, setting messageId to threadID = " << cmt.mMeta.mThreadId << std::endl;
RsQThreadUtils::postToObject( [cmt,this]()
{
//Change this item to be uploaded with thread element.
setMessageId(cmt.mMeta.mThreadId);
requestMessage();
}, this );
}
else
{
std::cerr << "GxsChannelPostItem::loadMessage() Wrong number of Items. Remove It.";
std::cerr << std::endl;
RsQThreadUtils::postToObject( [this]() { removeItem(); }, this );
}
});
//Change this item to be uploaded with thread element.
setMessageId(cmt.mMeta.mThreadId);
requestMessage();
}
else
{
std::cerr << "GxsChannelPostItem::loadMessage() Wrong number of Items. Remove It.";
std::cerr << std::endl;
removeItem();
return;
}
}
void PostedCardView::loadComment(const uint32_t &token)
void PostedCardView::loadComment()
{
std::vector<RsGxsComment> cmts;
if (!rsPosted->getRelatedComments(token, cmts))
RsThread::async([this]()
{
std::cerr << "GxsChannelPostItem::loadComment() ERROR getting data";
std::cerr << std::endl;
return;
}
// 1 - get group data
size_t comNb = cmts.size();
QString sComButText = tr("Comment");
if (comNb == 1) {
sComButText = sComButText.append("(1)");
} else if (comNb > 1) {
sComButText = " " + tr("Comments").append(" (%1)").arg(comNb);
}
ui->commentButton->setText(sComButText);
std::set<RsGxsMessageId> msgIds;
for(auto MsgId: messageVersions())
msgIds.insert(MsgId);
std::vector<RsPostedPost> posts;
std::vector<RsGxsComment> comments;
#warning Code needed in rsPosted
#ifdef TODO
if(! rsPosted->getPostedContent( groupId(),msgIds,posts,comments))
#endif
{
RsErr() << "PostedCardView::loadGroup() ERROR getting data" << std::endl;
return;
}
int comNb = comments.size();
RsQThreadUtils::postToObject( [comNb,this]()
{
QString sComButText = tr("Comment");
if (comNb == 1)
sComButText = sComButText.append("(1)");
else if(comNb > 1)
sComButText = tr("Comments ").append("(%1)").arg(comNb);
ui->commentButton->setText(sComButText);
}, this );
});
}
void PostedCardView::fill()
{
if (isLoading()) {
/* Wait for all requests */
return;
}
// if (isLoading()) {
// /* Wait for all requests */
// return;
// }
QPixmap sqpixmap2 = QPixmap(":/images/thumb-default.png");