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");

View File

@ -69,13 +69,13 @@ signals:
protected:
/* GxsGroupFeedItem */
virtual QString groupName();
virtual void loadGroup(const uint32_t &token);
virtual void loadGroup() override;
virtual RetroShareLink::enumType getLinkType() { return RetroShareLink::TYPE_UNKNOWN; }
/* GxsFeedItem */
virtual QString messageName();
virtual void loadMessage(const uint32_t &token);
virtual void loadComment(const uint32_t &token);
virtual void loadMessage();
virtual void loadComment();
private:
void setup();

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 "PhotoView.h"
#include "ui_PostedItem.h"
@ -168,88 +169,151 @@ bool PostedItem::setPost(const RsPostedPost &post, bool doFill)
return true;
}
void PostedItem::loadGroup(const uint32_t &token)
void PostedItem::loadGroup()
{
std::vector<RsPostedGroup> groups;
if (!rsPosted->getGroupData(token, groups))
RsThread::async([this]()
{
std::cerr << "PostedItem::loadGroup() ERROR getting data";
std::cerr << std::endl;
return;
}
// 1 - get group data
if (groups.size() != 1)
{
std::cerr << "PostedItem::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 PostedItem::loadMessage(const uint32_t &token)
void PostedItem::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;
}
//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;
}
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]()
{
ui->newCommentLabel->show();
ui->commLabel->show();
ui->commLabel->setText(QString::fromUtf8(cmt.mComment.c_str()));
//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 );
}
});
}
void PostedItem::loadComment(const uint32_t &token)
void PostedItem::loadComment()
{
std::vector<RsGxsComment> cmts;
if (!rsPosted->getRelatedComments(token, cmts))
{
std::cerr << "GxsChannelPostItem::loadComment() ERROR getting data";
std::cerr << std::endl;
return;
}
#ifdef DEBUG_ITEM
std::cerr << "GxsChannelPostItem::loadComment()";
std::cerr << std::endl;
#endif
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);
RsThread::async([this]()
{
// 1 - get group data
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() << "GxsGxsChannelGroupItem::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 PostedItem::fill()
{
if (isLoading()) {
/* Wait for all requests */
return;
}
// if (isLoading()) {
// /* Wait for all requests */
// return;
// }
QPixmap sqpixmap2 = QPixmap(":/images/thumb-default.png");

View File

@ -46,7 +46,7 @@ public:
bool setGroup(const RsPostedGroup& group, bool doFill = true);
bool setPost(const RsPostedPost& post, bool doFill = true);
const RsPostedPost &getPost() const;
const RsPostedPost& getPost() const;
RsPostedPost &post();
uint64_t uniqueIdentifier() const override { return hash_64bits("PostedItem " + messageId().toStdString()); }
@ -71,13 +71,14 @@ signals:
protected:
/* GxsGroupFeedItem */
virtual QString groupName();
virtual void loadGroup(const uint32_t &token);
virtual void loadGroup() override;
virtual RetroShareLink::enumType getLinkType() { return RetroShareLink::TYPE_UNKNOWN; }
/* GxsFeedItem */
virtual QString messageName();
virtual void loadMessage(const uint32_t &token);
virtual void loadComment(const uint32_t &token);
virtual void loadMessage();
virtual void loadComment();
private:
void setup();

View File

@ -23,6 +23,7 @@
#include "ui_GxsChannelGroupItem.h"
#include "FeedHolder.h"
#include "util/qtthreadsutils.h"
#include "gui/NewsFeed.h"
#include "gui/RetroShareLink.h"
@ -89,29 +90,39 @@ bool GxsChannelGroupItem::setGroup(const RsGxsChannelGroup &group)
return true;
}
void GxsChannelGroupItem::loadGroup(const uint32_t &token)
void GxsChannelGroupItem::loadGroup()
{
#ifdef DEBUG_ITEM
std::cerr << "GxsChannelGroupItem::loadGroup()";
std::cerr << std::endl;
#endif
std::vector<RsGxsChannelGroup> groups;
if (!rsGxsChannels->getGroupData(token, groups))
RsThread::async([this]()
{
std::cerr << "GxsChannelGroupItem::loadGroup() ERROR getting data";
std::cerr << std::endl;
return;
}
// 1 - get group data
if (groups.size() != 1)
{
std::cerr << "GxsChannelGroupItem::loadGroup() Wrong number of Items";
std::cerr << std::endl;
return;
}
std::vector<RsGxsChannelGroup> groups;
const std::list<RsGxsGroupId> groupIds = { groupId() };
setGroup(groups[0]);
if(!rsGxsChannels->getChannelsInfo(groupIds,groups))
{
RsErr() << "GxsGxsChannelGroupItem::loadGroup() ERROR getting data" << std::endl;
return;
}
if (groups.size() != 1)
{
std::cerr << "GxsGxsChannelGroupItem::loadGroup() Wrong number of Items";
std::cerr << std::endl;
return;
}
RsGxsChannelGroup 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 );
});
}
QString GxsChannelGroupItem::groupName()

View File

@ -48,7 +48,7 @@ protected:
/* GxsGroupFeedItem */
virtual QString groupName();
virtual void loadGroup(const uint32_t &token);
virtual void loadGroup() override;
virtual RetroShareLink::enumType getLinkType() { return RetroShareLink::TYPE_CHANNEL; }
private slots:

View File

@ -30,6 +30,7 @@
#include "FeedHolder.h"
#include "SubFileItem.h"
#include "util/misc.h"
#include "util/qtthreadsutils.h"
#include "gui/RetroShareLink.h"
#include "util/HandleRichText.h"
#include "util/DateTime.h"
@ -230,107 +231,149 @@ void GxsChannelPostItem::loadComments()
comments(title);
}
void GxsChannelPostItem::loadGroup(const uint32_t &token)
void GxsChannelPostItem::loadGroup()
{
#ifdef DEBUG_ITEM
std::cerr << "GxsChannelGroupItem::loadGroup()";
std::cerr << std::endl;
#endif
std::vector<RsGxsChannelGroup> groups;
if (!rsGxsChannels->getGroupData(token, groups))
RsThread::async([this]()
{
std::cerr << "GxsChannelGroupItem::loadGroup() ERROR getting data";
std::cerr << std::endl;
return;
}
// 1 - get group data
if (groups.size() != 1)
{
std::cerr << "GxsChannelGroupItem::loadGroup() Wrong number of Items";
std::cerr << std::endl;
return;
}
std::vector<RsGxsChannelGroup> groups;
const std::list<RsGxsGroupId> groupIds = { groupId() };
setGroup(groups[0]);
if(!rsGxsChannels->getChannelsInfo(groupIds,groups))
{
RsErr() << "GxsGxsChannelGroupItem::loadGroup() ERROR getting data" << std::endl;
return;
}
if (groups.size() != 1)
{
std::cerr << "GxsGxsChannelGroupItem::loadGroup() Wrong number of Items";
std::cerr << std::endl;
return;
}
RsGxsChannelGroup 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 GxsChannelPostItem::loadMessage(const uint32_t &token)
void GxsChannelPostItem::loadMessage()
{
#ifdef DEBUG_ITEM
std::cerr << "GxsChannelPostItem::loadMessage()";
std::cerr << std::endl;
#endif
std::vector<RsGxsChannelPost> posts;
std::vector<RsGxsComment> cmts;
if (!rsGxsChannels->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)
{
std::cerr << (void*)this << ": Obtained post, with msgId = " << posts[0].mMeta.mMsgId << std::endl;
setPost(posts[0]);
}
else if (cmts.size() == 1)
{
RsGxsComment cmt = cmts[0];
std::vector<RsGxsChannelPost> posts;
std::vector<RsGxsComment> comments;
std::cerr << (void*)this << ": Obtained comment, setting messageId to threadID = " << cmt.mMeta.mThreadId << std::endl;
ui->newCommentLabel->show();
ui->commLabel->show();
ui->commLabel->setText(QString::fromUtf8(cmt.mComment.c_str()));
if(! rsGxsChannels->getChannelContent( groupId(), std::set<RsGxsMessageId>( { messageId() } ),posts,comments))
{
RsErr() << "GxsGxsChannelGroupItem::loadGroup() ERROR getting data" << std::endl;
return;
}
//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;
}
if (posts.size() == 1)
{
std::cerr << (void*)this << ": Obtained post, with msgId = " << posts[0].mMeta.mMsgId << std::endl;
const RsGxsChannelPost& 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]()
{
ui->newCommentLabel->show();
ui->commLabel->show();
ui->commLabel->setText(QString::fromUtf8(cmt.mComment.c_str()));
//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 );
}
});
}
void GxsChannelPostItem::loadComment(const uint32_t &token)
void GxsChannelPostItem::loadComment()
{
#ifdef DEBUG_ITEM
std::cerr << "GxsChannelPostItem::loadComment()";
std::cerr << std::endl;
#endif
std::vector<RsGxsComment> cmts;
if (!rsGxsChannels->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<RsGxsChannelPost> posts;
std::vector<RsGxsComment> comments;
if(! rsGxsChannels->getChannelContent( groupId(),msgIds,posts,comments))
{
RsErr() << "GxsGxsChannelGroupItem::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 GxsChannelPostItem::fill()
{
/* fill in */
if (isLoading()) {
/* Wait for all requests */
return;
}
// if (isLoading()) {
// /* Wait for all requests */
//return;
// }
#ifdef DEBUG_ITEM
std::cerr << "GxsChannelPostItem::fill()";

View File

@ -81,13 +81,13 @@ protected:
/* GxsGroupFeedItem */
virtual QString groupName();
virtual void loadGroup(const uint32_t &token);
virtual void loadGroup() override;
virtual RetroShareLink::enumType getLinkType() { return RetroShareLink::TYPE_CHANNEL; }
/* GxsFeedItem */
virtual QString messageName();
virtual void loadMessage(const uint32_t &token);
virtual void loadComment(const uint32_t &token);
virtual void loadMessage();
virtual void loadComment();
private slots:
/* default stuff */

View File

@ -23,6 +23,7 @@
#include "FeedHolder.h"
#include "gui/RetroShareLink.h"
#include "util/qtthreadsutils.h"
/****
* #define DEBUG_ITEM 1
@ -87,29 +88,43 @@ bool GxsForumGroupItem::setGroup(const RsGxsForumGroup &group)
return true;
}
void GxsForumGroupItem::loadGroup(const uint32_t &token)
void GxsForumGroupItem::loadGroup()
{
#ifdef DEBUG_ITEM
std::cerr << "GxsForumGroupItem::loadGroup()";
std::cerr << std::endl;
RsThread::async([this]()
{
// 1 - get group data
#ifdef DEBUG_FORUMS
std::cerr << "Retrieving post data for post " << mThreadId << std::endl;
#endif
std::vector<RsGxsForumGroup> groups;
if (!rsGxsForums->getGroupData(token, groups))
{
std::cerr << "GxsForumGroupItem::loadGroup() ERROR getting data";
std::cerr << std::endl;
return;
}
std::vector<RsGxsForumGroup> groups;
const std::list<RsGxsGroupId> forumIds = { groupId() };
if (groups.size() != 1)
{
std::cerr << "GxsForumGroupItem::loadGroup() Wrong number of Items";
std::cerr << std::endl;
return;
}
if(!rsGxsForums->getForumsInfo(forumIds,groups))
{
RsErr() << "GxsForumGroupItem::loadGroup() ERROR getting data" << std::endl;
return;
}
setGroup(groups[0]);
if (groups.size() != 1)
{
std::cerr << "GxsForumGroupItem::loadGroup() Wrong number of Items";
std::cerr << std::endl;
return;
}
const RsGxsForumGroup& 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 );
});
}
QString GxsForumGroupItem::groupName()

View File

@ -50,7 +50,7 @@ protected:
/* GxsGroupFeedItem */
virtual QString groupName();
virtual void loadGroup(const uint32_t &token);
virtual void loadGroup() override;
virtual RetroShareLink::enumType getLinkType() { return RetroShareLink::TYPE_FORUM; }
private slots:

View File

@ -30,6 +30,7 @@
#include "gui/RetroShareLink.h"
#include "gui/gxs/GxsIdDetails.h"
#include "util/HandleRichText.h"
#include "util/qtthreadsutils.h"
#include "util/DateTime.h"
#include <retroshare/rsidentity.h>
@ -94,7 +95,6 @@ void GxsForumMsgItem::setup()
mInFill = false;
mCloseOnRead = false;
mTokenTypeParentMessage = nextTokenType();
/* clear ui */
ui->titleLabel->setText(tr("Loading"));
@ -154,13 +154,10 @@ bool GxsForumMsgItem::setMessage(const RsGxsForumMsg &msg, bool doFill)
mMessage = msg;
if (!isTop()) {
requestParentMessage(mMessage.mMeta.mParentId);
} else {
if (doFill) {
fill();
}
}
if (!isTop())
loadParentMessage(mMessage.mMeta.mParentId);
else if(doFill)
fill();
return true;
}
@ -170,91 +167,144 @@ QString GxsForumMsgItem::groupName()
return QString::fromUtf8(mGroup.mMeta.mGroupName.c_str());
}
void GxsForumMsgItem::loadGroup(const uint32_t &token)
void GxsForumMsgItem::loadGroup()
{
#ifdef DEBUG_ITEM
std::cerr << "GxsForumGroupItem::loadGroup()";
std::cerr << std::endl;
RsThread::async([this]()
{
// 1 - get group data
#ifdef DEBUG_FORUMS
std::cerr << "Retrieving post data for post " << mThreadId << std::endl;
#endif
std::vector<RsGxsForumGroup> groups;
if (!rsGxsForums->getGroupData(token, groups))
{
std::cerr << "GxsForumGroupItem::loadGroup() ERROR getting data";
std::cerr << std::endl;
return;
}
std::vector<RsGxsForumGroup> groups;
const std::list<RsGxsGroupId> forumIds = { groupId() };
if (groups.size() != 1)
{
std::cerr << "GxsForumGroupItem::loadGroup() Wrong number of Items";
std::cerr << std::endl;
return;
}
if(!rsGxsForums->getForumsInfo(forumIds,groups))
{
RsErr() << "GxsForumGroupItem::loadGroup() ERROR getting data" << std::endl;
return;
}
setGroup(groups[0]);
if (groups.size() != 1)
{
std::cerr << "GxsForumGroupItem::loadGroup() Wrong number of Items";
std::cerr << std::endl;
return;
}
RsGxsForumGroup 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 GxsForumMsgItem::loadMessage(const uint32_t &token)
void GxsForumMsgItem::loadMessage()
{
#ifdef DEBUG_ITEM
std::cerr << "GxsForumMsgItem::loadMessage()";
std::cerr << std::endl;
#endif
std::vector<RsGxsForumMsg> msgs;
if (!rsGxsForums->getMsgData(token, msgs))
RsThread::async([this]()
{
std::cerr << "GxsForumMsgItem::loadMessage() ERROR getting data";
std::cerr << std::endl;
return;
}
if (msgs.size() != 1)
{
std::cerr << "GxsForumMsgItem::loadMessage() Wrong number of Items";
std::cerr << std::endl;
return;
}
// 1 - get group data
setMessage(msgs[0]);
#ifdef DEBUG_FORUMS
std::cerr << "Retrieving post data for post " << mThreadId << std::endl;
#endif
std::vector<RsGxsForumMsg> msgs;
const std::list<RsGxsGroupId> forumIds = { groupId() };
if(!rsGxsForums->getForumContent(groupId(),std::set<RsGxsMessageId>( { messageId() } ),msgs))
{
std::cerr << "GxsForumMsgItem::loadMessage() ERROR getting data";
std::cerr << std::endl;
return;
}
if (msgs.size() != 1)
{
std::cerr << "GxsForumMsgItem::loadMessage() Wrong number of Items";
std::cerr << std::endl;
return;
}
const RsGxsForumMsg& msg(msgs[0]);
RsQThreadUtils::postToObject( [msg,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 */
setMessage(msg);
}, this );
});
}
void GxsForumMsgItem::loadParentMessage(const uint32_t &token)
void GxsForumMsgItem::loadParentMessage(const RsGxsMessageId& parent_msg)
{
#ifdef DEBUG_ITEM
std::cerr << "GxsForumMsgItem::loadParentMessage()";
std::cerr << std::endl;
#endif
std::vector<RsGxsForumMsg> msgs;
if (!rsGxsForums->getMsgData(token, msgs))
RsThread::async([parent_msg,this]()
{
std::cerr << "GxsForumMsgItem::loadParentMessage() ERROR getting data";
std::cerr << std::endl;
return;
}
// 1 - get group data
if (msgs.size() != 1)
{
std::cerr << "GxsForumMsgItem::loadParentMessage() Wrong number of Items";
std::cerr << std::endl;
return;
}
#ifdef DEBUG_FORUMS
std::cerr << "Retrieving post data for post " << mThreadId << std::endl;
#endif
mParentMessage = msgs[0];
std::vector<RsGxsForumMsg> msgs;
const std::list<RsGxsGroupId> forumIds = { groupId() };
fill();
if(!rsGxsForums->getForumContent(groupId(),std::set<RsGxsMessageId>( { parent_msg } ),msgs))
{
std::cerr << "GxsForumMsgItem::loadMessage() ERROR getting data";
std::cerr << std::endl;
return;
}
if (msgs.size() != 1)
{
std::cerr << "GxsForumMsgItem::loadMessage() Wrong number of Items";
std::cerr << std::endl;
return;
}
const RsGxsForumMsg& msg(msgs[0]);
RsQThreadUtils::postToObject( [msg,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 */
mParentMessage = msg;
fill();
}, this );
});
}
void GxsForumMsgItem::fill()
{
/* fill in */
if (isLoading()) {
/* Wait for all requests */
return;
}
// if (isLoading()) {
// /* Wait for all requests */
// return;
// }
#ifdef DEBUG_ITEM
std::cerr << "GxsForumMsgItem::fill()";
@ -307,18 +357,6 @@ void GxsForumMsgItem::fill()
ui->nameLabel->setId(mMessage.mMeta.mAuthorId);
// ui->avatar->setId(msg.srcId, true);
// if (rsPeers->getPeerName(msg.srcId) != "") {
// RetroShareLink linkMessage;
// linkMessage.createMessage(msg.srcId, "");
// nameLabel->setText(linkMessage.toHtml());
// }
// else
// {
// nameLabel->setText(tr("Anonymous"));
// }
RetroShareLink msgLink = RetroShareLink::createGxsMessageLink(RetroShareLink::TYPE_FORUM, mMessage.mMeta.mGroupId, mMessage.mMeta.mMsgId, messageName());
ui->subLabel->setText(msgLink.toHtml());
if (wasExpanded() || ui->expandFrame->isVisible()) {
@ -330,14 +368,13 @@ void GxsForumMsgItem::fill()
if (isTop()) {
ui->parentFrame->hide();
} else {
// ui->parentAvatar->setId(msgParent.srcId, true);
RetroShareLink linkParent = RetroShareLink::createGxsMessageLink(RetroShareLink::TYPE_FORUM, mParentMessage.mMeta.mGroupId, mParentMessage.mMeta.mMsgId, QString::fromUtf8(mParentMessage.mMeta.mMsgName.c_str()));
ui->parentSubLabel->setText(linkParent.toHtml());
ui->parentMsgLabel->setText(RsHtml().formatText(NULL, QString::fromUtf8(mParentMessage.mMsg.c_str()), RSHTML_FORMATTEXT_EMBED_SMILEYS | RSHTML_FORMATTEXT_EMBED_LINKS));
ui->parentNameLabel->setId(mParentMessage.mMeta.mAuthorId);
RsIdentityDetails idDetails ;
rsIdentity->getIdDetails(mParentMessage.mMeta.mAuthorId,idDetails);
@ -348,16 +385,6 @@ void GxsForumMsgItem::fill()
ui->parentAvatar->setPixmap(pixmap);
// if (rsPeers->getPeerName(msgParent.srcId) !="")
// {
// RetroShareLink linkMessage;
// linkMessage.createMessage(msgParent.srcId, "");
// ui->parentNameLabel->setText(linkMessage.toHtml());
// }
// else
// {
// ui->parentNameLabel->setText(tr("Anonymous"));
// }
}
/* header stuff */
@ -440,63 +467,6 @@ void GxsForumMsgItem::setReadStatus(bool isNew, bool /*isUnread*/)
ui->frame->style()->polish( ui->frame);
}
void GxsForumMsgItem::requestParentMessage(const RsGxsMessageId &msgId)
{
#ifdef DEBUG_ITEM
std::cerr << "GxsFeedItem::requestMessage()";
std::cerr << std::endl;
#endif
if (!initLoadQueue()) {
return;
}
if (mLoadQueue->activeRequestExist(mTokenTypeParentMessage)) {
/* Request already running */
return;
}
RsTokReqOptions opts;
opts.mReqType = GXS_REQUEST_TYPE_MSG_DATA;
GxsMsgReq msgIds;
std::set<RsGxsMessageId> &vect_msgIds = msgIds[groupId()];
vect_msgIds.insert(msgId);
uint32_t token;
mLoadQueue->requestMsgInfo(token, RS_TOKREQ_ANSTYPE_DATA, opts, msgIds, mTokenTypeParentMessage);
}
void GxsForumMsgItem::loadRequest(const TokenQueue *queue, const TokenRequest &req)
{
#ifdef DEBUG_ITEM
std::cerr << "GxsFeedItem::loadRequest()";
std::cerr << std::endl;
#endif
if (queue == mLoadQueue) {
if (req.mUserType == mTokenTypeParentMessage) {
loadParentMessage(req.mToken);
return;
}
}
GxsFeedItem::loadRequest(queue, req);
}
bool GxsForumMsgItem::isLoading()
{
if (GxsFeedItem::isLoading()) {
return true;
}
if (mLoadQueue && mLoadQueue->activeRequestExist(mTokenTypeParentMessage)) {
return true;
}
return false;
}
/*********** SPECIFIC FUNCTIONS ***********************/
void GxsForumMsgItem::readAndClearItem()

View File

@ -50,20 +50,18 @@ protected:
virtual void expandFill(bool first);
/* load message data */
void requestParentMessage(const RsGxsMessageId &msgId);
virtual void loadParentMessage(const uint32_t &token);
virtual void loadParentMessage(const RsGxsMessageId &parent_msg);
/* GxsGroupFeedItem */
virtual QString groupName();
virtual void loadGroup(const uint32_t &token);
virtual void loadRequest(const TokenQueue *queue, const TokenRequest &req);
virtual void loadGroup() override;
virtual RetroShareLink::enumType getLinkType() { return RetroShareLink::TYPE_FORUM; }
virtual bool isLoading();
//virtual bool isLoading();
/* GxsFeedItem */
virtual QString messageName();
virtual void loadMessage(const uint32_t &token);
virtual void loadComment(const uint32_t &/*token*/){ return;}
virtual void loadMessage() override;
virtual void loadComment() override { return; }
private slots:
/* default stuff */
@ -90,7 +88,6 @@ private:
RsGxsForumGroup mGroup;
RsGxsForumMsg mMessage;
RsGxsForumMsg mParentMessage;
uint32_t mTokenTypeParentMessage;
/** Qt Designer generated object */
Ui::GxsForumMsgItem *ui;

View File

@ -22,6 +22,7 @@
#include "ui_PostedGroupItem.h"
#include "FeedHolder.h"
#include "util/qtthreadsutils.h"
#include "gui/RetroShareLink.h"
#include "gui/gxs/GxsIdDetails.h"
@ -90,29 +91,46 @@ bool PostedGroupItem::setGroup(const RsPostedGroup &group)
return true;
}
void PostedGroupItem::loadGroup(const uint32_t &token)
void PostedGroupItem::loadGroup()
{
#ifdef DEBUG_ITEM
std::cerr << "PostedGroupItem::loadGroup()";
std::cerr << std::endl;
RsThread::async([this]()
{
// 1 - get group data
#ifdef DEBUG_FORUMS
std::cerr << "Retrieving post data for post " << mThreadId << std::endl;
#endif
std::vector<RsPostedGroup> groups;
if (!rsPosted->getGroupData(token, groups))
{
std::cerr << "PostedGroupItem::loadGroup() ERROR getting data";
std::cerr << std::endl;
return;
}
std::vector<RsPostedGroup> groups;
const std::list<RsGxsGroupId> groupIds = { groupId() };
if (groups.size() != 1)
{
std::cerr << "PostedGroupItem::loadGroup() Wrong number of Items";
std::cerr << std::endl;
return;
}
#warning Code needed in rsPosted
#ifdef TODO
if(!rsPosted->getPostedGroupInfo(groupIds,groups))
#endif
{
RsErr() << "GxsPostedGroupItem::loadGroup() ERROR getting data" << std::endl;
return;
}
setGroup(groups[0]);
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 );
});
}
QString PostedGroupItem::groupName()

View File

@ -50,7 +50,7 @@ protected:
/* GxsGroupFeedItem */
virtual QString groupName();
virtual void loadGroup(const uint32_t &token);
virtual void loadGroup() override;
virtual RetroShareLink::enumType getLinkType() { return RetroShareLink::TYPE_UNKNOWN; }
private slots:

View File

@ -40,8 +40,10 @@ GxsFeedItem::GxsFeedItem(FeedHolder *feedHolder, uint32_t feedId, const RsGxsGro
/* load data if we can */
mMessageId = messageId;
#ifdef TO_REMOVE
mTokenTypeMessage = nextTokenType();
mTokenTypeComment = nextTokenType();
#endif
}
GxsFeedItem::~GxsFeedItem()
@ -106,6 +108,8 @@ void GxsFeedItem::fillDisplay(RsGxsUpdateBroadcastBase *updateBroadcastBase, boo
void GxsFeedItem::requestMessage()
{
loadMessage();
#ifdef TO_REMOVE
#ifdef DEBUG_ITEM
std::cerr << "GxsFeedItem::requestMessage()";
std::cerr << std::endl;
@ -129,15 +133,19 @@ void GxsFeedItem::requestMessage()
uint32_t token;
mLoadQueue->requestMsgInfo(token, RS_TOKREQ_ANSTYPE_DATA, opts, msgIds, mTokenTypeMessage);
#endif
}
void GxsFeedItem::requestComment()
{
loadComment();
#ifdef TO_REMOVE
#ifdef DEBUG_ITEM
std::cerr << "GxsFeedItem::requestComment()";
std::cerr << std::endl;
#endif
#ifdef TO_REMOVE
if (!initLoadQueue()) {
return;
}
@ -146,6 +154,7 @@ void GxsFeedItem::requestComment()
/* Request already running */
return;
}
#endif
RsTokReqOptions opts;
opts.mReqType = GXS_REQUEST_TYPE_MSG_RELATED_DATA;
@ -153,15 +162,17 @@ void GxsFeedItem::requestComment()
std::vector<RsGxsGrpMsgIdPair> msgIds;
for(int i=0;i<mMessageVersions.size();++i)
msgIds.push_back(std::make_pair(groupId(),mMessageVersions[i])) ;
for(int i=0;i<mmessageversions.size();++i)
msgids.push_back(std::make_pair(groupid(),mmessageversions[i])) ;
msgIds.push_back(std::make_pair(groupId(),messageId()));
msgids.push_back(std::make_pair(groupid(),messageid()));
uint32_t token;
mLoadQueue->requestMsgRelatedInfo(token, RS_TOKREQ_ANSTYPE_DATA, opts, msgIds, mTokenTypeComment);
#endif
}
#ifdef TO_REMOVE
void GxsFeedItem::loadRequest(const TokenQueue *queue, const TokenRequest &req)
{
#ifdef DEBUG_ITEM
@ -195,3 +206,4 @@ bool GxsFeedItem::isLoading()
return false;
}
#endif

View File

@ -45,15 +45,17 @@ protected:
void requestComment();
virtual QString messageName() = 0;
virtual void loadMessage(const uint32_t &token) = 0;
virtual void loadComment(const uint32_t &token) = 0;
virtual void loadMessage() = 0;
virtual void loadComment() = 0;
/* GxsGroupFeedItem */
virtual bool isLoading();
//virtual bool isLoading();
//virtual void fillDisplay(RsGxsUpdateBroadcastBase *updateBroadcastBase, bool complete);
#ifdef TO_REMOVE
/* TokenResponse */
virtual void loadRequest(const TokenQueue *queue, const TokenRequest &req);
#endif
protected slots:
void comments(const QString &title);

View File

@ -46,12 +46,12 @@ GxsGroupFeedItem::GxsGroupFeedItem(FeedHolder *feedHolder, uint32_t feedId, cons
mGroupId = groupId;
mGxsIface = iface;
#ifdef TO_REMOVE
mNextTokenType = 0;
mTokenTypeGroup = nextTokenType();
mLoadQueue = NULL;
#ifdef TO_REMOVE
if (mGxsIface && autoUpdate) {
/* Connect to update broadcast */
mUpdateBroadcastBase = new RsGxsUpdateBroadcastBase(mGxsIface);
@ -69,11 +69,11 @@ GxsGroupFeedItem::~GxsGroupFeedItem()
std::cerr << std::endl;
#endif
#ifdef TO_REMOVE
if (mLoadQueue) {
delete mLoadQueue;
}
#ifdef TO_REMOVE
if (mUpdateBroadcastBase)
{
delete(mUpdateBroadcastBase);
@ -81,20 +81,6 @@ GxsGroupFeedItem::~GxsGroupFeedItem()
#endif
}
bool GxsGroupFeedItem::initLoadQueue()
{
if (mLoadQueue) {
return true;
}
if (!mGxsIface) {
return false;
}
mLoadQueue = new TokenQueue(mGxsIface->getTokenService(), this);
return (mLoadQueue != NULL);
}
void GxsGroupFeedItem::unsubscribe()
{
#ifdef DEBUG_ITEM
@ -144,7 +130,6 @@ void GxsGroupFeedItem::copyGroupLink()
void GxsGroupFeedItem::fillDisplaySlot(bool complete)
{
requestGroup();
// fillDisplay(mUpdateBroadcastBase, complete);
}
#ifdef TO_REMOVE
@ -162,51 +147,6 @@ void GxsGroupFeedItem::fillDisplay(RsGxsUpdateBroadcastBase *updateBroadcastBase
void GxsGroupFeedItem::requestGroup()
{
#ifdef DEBUG_ITEM
std::cerr << "GxsGroupFeedItem::requestGroup()";
std::cerr << std::endl;
#endif
if (!initLoadQueue()) {
return;
}
if (mLoadQueue->activeRequestExist(mTokenTypeGroup)) {
/* Request already running */
return;
}
std::list<RsGxsGroupId> ids;
ids.push_back(mGroupId);
RsTokReqOptions opts;
opts.mReqType = GXS_REQUEST_TYPE_GROUP_DATA;
uint32_t token;
mLoadQueue->requestGroupInfo(token, RS_TOKREQ_ANSTYPE_SUMMARY, opts, ids, mTokenTypeGroup);
loadGroup();
}
void GxsGroupFeedItem::loadRequest(const TokenQueue *queue, const TokenRequest &req)
{
#ifdef DEBUG_ITEM
std::cerr << "GxsGroupFeedItem::loadRequest()";
std::cerr << std::endl;
#endif
if (queue == mLoadQueue) {
if (req.mUserType == mTokenTypeGroup) {
loadGroup(req.mToken);
} else {
std::cerr << "GxsGroupFeedItem::loadRequest() ERROR: INVALID TYPE";
std::cerr << std::endl;
}
}
}
bool GxsGroupFeedItem::isLoading()
{
if (mLoadQueue && mLoadQueue->activeRequestExist(mTokenTypeGroup)) {
return true;
}
return false;
}

View File

@ -25,7 +25,6 @@
#include <retroshare/rsgxsifacehelper.h>
#include "gui/feeds/FeedItem.h"
#include "util/TokenQueue.h"
#include "gui/RetroShareLink.h"
#include <stdint.h>
@ -33,7 +32,7 @@
class FeedHolder;
class RsGxsUpdateBroadcastBase;
class GxsGroupFeedItem : public FeedItem, public TokenResponse
class GxsGroupFeedItem : public FeedItem
{
Q_OBJECT
@ -46,20 +45,12 @@ public:
uint32_t feedId() const { return mFeedId; }
protected:
uint32_t nextTokenType() { return ++mNextTokenType; }
bool initLoadQueue();
/* load group data */
void requestGroup();
virtual bool isLoading();
virtual void loadGroup(const uint32_t &token) = 0;
virtual void loadGroup() = 0;
virtual RetroShareLink::enumType getLinkType() = 0;
virtual QString groupName() = 0;
//virtual void fillDisplay(RsGxsUpdateBroadcastBase *updateBroadcastBase, bool complete);
/* TokenResponse */
virtual void loadRequest(const TokenQueue *queue, const TokenRequest &req);
protected slots:
void subscribe();
@ -69,7 +60,6 @@ protected slots:
protected:
bool mIsHome;
RsGxsIfaceHelper *mGxsIface;
TokenQueue *mLoadQueue;
private slots:
/* RsGxsUpdateBroadcastBase */
@ -77,9 +67,6 @@ private slots:
private:
RsGxsGroupId mGroupId;
// RsGxsUpdateBroadcastBase *mUpdateBroadcastBase;
uint32_t mNextTokenType;
uint32_t mTokenTypeGroup;
};
Q_DECLARE_METATYPE(RsGxsGroupId)