From 61083ff77a1fc0f7df8e964ab825dd4dd2293887 Mon Sep 17 00:00:00 2001 From: csoler Date: Tue, 18 Feb 2020 11:07:41 +0100 Subject: [PATCH 1/5] fixed elided label when size is too small to draw anything --- retroshare-gui/src/gui/common/ElidedLabel.cpp | 3 ++- retroshare-gui/src/gui/gxs/GxsIdTreeWidgetItem.cpp | 5 ++++- 2 files changed, 6 insertions(+), 2 deletions(-) diff --git a/retroshare-gui/src/gui/common/ElidedLabel.cpp b/retroshare-gui/src/gui/common/ElidedLabel.cpp index 15cdbd1ed..fbde8b026 100644 --- a/retroshare-gui/src/gui/common/ElidedLabel.cpp +++ b/retroshare-gui/src/gui/common/ElidedLabel.cpp @@ -200,7 +200,8 @@ bool ElidedLabel::paintElidedLine(QPainter& painter,QString plainText,const QRec iTransX = 0; } - painter.drawText(QPoint(iTransX + cr.left(), y + fontMetrics.ascent() + cr.top()), elidedLastLine); + if(width+iTransX+cr.left() <= cr.right()) + painter.drawText(QPoint(iTransX + cr.left(), y + fontMetrics.ascent() + cr.top()), elidedLastLine); //Draw button to get ToolTip if(drawRoundRect) diff --git a/retroshare-gui/src/gui/gxs/GxsIdTreeWidgetItem.cpp b/retroshare-gui/src/gui/gxs/GxsIdTreeWidgetItem.cpp index 39e0f0216..c0f1fdc36 100644 --- a/retroshare-gui/src/gui/gxs/GxsIdTreeWidgetItem.cpp +++ b/retroshare-gui/src/gui/gxs/GxsIdTreeWidgetItem.cpp @@ -263,7 +263,10 @@ void GxsIdTreeItemDelegate::paint(QPainter *painter, const QStyleOptionViewItem launchAsyncLoading(); } - QPixmap pix = icon.pixmap(r.size()); + QRect pixmaprect(r); + pixmaprect.adjust(r.height(),0,0,0); + + QPixmap pix = icon.pixmap(pixmaprect.size()); const QPoint p = QPoint(r.height()/2.0, (r.height() - pix.height())/2); // draw pixmap at center of item From d1b26c9d366f25c398bcaa8674085324c9402e2f Mon Sep 17 00:00:00 2001 From: csoler Date: Tue, 18 Feb 2020 11:19:10 +0100 Subject: [PATCH 2/5] removed dead code form GxsForumThreadWidget.cpp --- .../src/gui/gxs/GxsIdTreeWidgetItem.cpp | 5 - .../gui/gxsforums/GxsForumThreadWidget.cpp | 91 +------------------ 2 files changed, 1 insertion(+), 95 deletions(-) diff --git a/retroshare-gui/src/gui/gxs/GxsIdTreeWidgetItem.cpp b/retroshare-gui/src/gui/gxs/GxsIdTreeWidgetItem.cpp index c0f1fdc36..f9fcaca21 100644 --- a/retroshare-gui/src/gui/gxs/GxsIdTreeWidgetItem.cpp +++ b/retroshare-gui/src/gui/gxs/GxsIdTreeWidgetItem.cpp @@ -271,14 +271,9 @@ void GxsIdTreeItemDelegate::paint(QPainter *painter, const QStyleOptionViewItem // draw pixmap at center of item painter->drawPixmap(r.topLeft() + p, pix); - //painter->drawText(r.topLeft() + QPoint(r.height()+ f/2.0 + f/2.0,f*1.0), str); - - //cr.adjust(margin(), margin(), -margin(), -margin()); QRect mRectElision; - r.adjust(pix.height()+f,(r.height()-f)/2.0,0,0); bool didElide = ElidedLabel::paintElidedLine(*painter,str,r,Qt::AlignLeft,false,false,mRectElision); - } diff --git a/retroshare-gui/src/gui/gxsforums/GxsForumThreadWidget.cpp b/retroshare-gui/src/gui/gxsforums/GxsForumThreadWidget.cpp index f47f0a1d0..d4e7f1208 100644 --- a/retroshare-gui/src/gui/gxsforums/GxsForumThreadWidget.cpp +++ b/retroshare-gui/src/gui/gxsforums/GxsForumThreadWidget.cpp @@ -184,95 +184,6 @@ public: } }; -class AuthorItemDelegate: public QStyledItemDelegate -{ -public: - AuthorItemDelegate() {} - - QSize sizeHint(const QStyleOptionViewItem &option, const QModelIndex &index) const override - { - QStyleOptionViewItemV4 opt = option; - initStyleOption(&opt, index); - - // disable default icon - opt.icon = QIcon(); - const QRect r = option.rect; - - RsGxsId id(index.data(Qt::UserRole).toString().toStdString()); - QString str; - QList icons; - QString comment; - - QFontMetricsF fm(option.font); - float f = fm.height(); - - QIcon icon ; - - if(!GxsIdDetails::MakeIdDesc(id, true, str, icons, comment,GxsIdDetails::ICON_TYPE_AVATAR)) - icon = GxsIdDetails::getLoadingIcon(id); - else - icon = *icons.begin(); - - QPixmap pix = icon.pixmap(r.size()); - - return QSize(1.2*(pix.width() + fm.width(str)),std::max(1.1*pix.height(),1.4*fm.height())); - } - - virtual void paint(QPainter *painter, const QStyleOptionViewItem &option, const QModelIndex& index) const override - { - if(!index.isValid()) - { - std::cerr << "(EE) attempt to draw an invalid index." << std::endl; - return ; - } - - QStyleOptionViewItemV4 opt = option; - initStyleOption(&opt, index); - - // disable default icon - opt.icon = QIcon(); - // draw default item - QApplication::style()->drawControl(QStyle::CE_ItemViewItem, &opt, painter, 0); - - const QRect r = option.rect; - - RsGxsId id(index.data(Qt::UserRole).toString().toStdString()); - QString str; - QList icons; - QString comment; - - QFontMetricsF fm(painter->font()); - float f = fm.height(); - - QIcon icon ; - - if(!GxsIdDetails::MakeIdDesc(id, true, str, icons, comment,GxsIdDetails::ICON_TYPE_AVATAR)) - icon = GxsIdDetails::getLoadingIcon(id); - else - icon = *icons.begin(); - - unsigned int warning_level = qvariant_cast(index.sibling(index.row(),RsGxsForumModel::COLUMN_THREAD_DISTRIBUTION).data(Qt::DecorationRole)); - - if(warning_level == 2) - { - str = tr("[Banned]"); - icon = QIcon(IMAGE_BIOHAZARD); - } - - if(index.data(RsGxsForumModel::MissingRole).toBool()) - painter->drawText(r.topLeft() + QPoint(f/2.0,f*1.0), tr("[None]")); - else - { - QPixmap pix = icon.pixmap(r.size()); - const QPoint p = QPoint(r.height()/2.0, (r.height() - pix.height())/2); - - // draw pixmap at center of item - painter->drawPixmap(r.topLeft() + p, pix); - painter->drawText(r.topLeft() + QPoint(r.height()+ f/2.0 + f/2.0,f*1.0), str); - } - } -}; - class ForumPostSortFilterProxyModel: public QSortFilterProxyModel { public: @@ -331,7 +242,7 @@ GxsForumThreadWidget::GxsForumThreadWidget(const RsGxsGroupId &forumId, QWidget ui->threadTreeWidget->setSortingEnabled(true); ui->threadTreeWidget->setItemDelegateForColumn(RsGxsForumModel::COLUMN_THREAD_DISTRIBUTION,new DistributionItemDelegate()) ; - ui->threadTreeWidget->setItemDelegateForColumn(RsGxsForumModel::COLUMN_THREAD_AUTHOR,new AuthorItemDelegate()) ; + ui->threadTreeWidget->setItemDelegateForColumn(RsGxsForumModel::COLUMN_THREAD_AUTHOR,new GxsIdTreeItemDelegate()) ; ui->threadTreeWidget->setItemDelegateForColumn(RsGxsForumModel::COLUMN_THREAD_READ,new ReadStatusItemDelegate()) ; ui->threadTreeWidget->header()->setSortIndicatorShown(true); From 7e08d24b64f1a59b0a57d0f99721afd207a1a99a Mon Sep 17 00:00:00 2001 From: csoler Date: Sun, 16 Feb 2020 20:57:36 +0100 Subject: [PATCH 3/5] removed most of the token queue system from GxsFeedItems --- .../src/gui/Posted/PostedCardView.cpp | 180 ++++++++----- .../src/gui/Posted/PostedCardView.h | 6 +- retroshare-gui/src/gui/Posted/PostedItem.cpp | 190 ++++++++----- retroshare-gui/src/gui/Posted/PostedItem.h | 9 +- .../src/gui/feeds/GxsChannelGroupItem.cpp | 49 ++-- .../src/gui/feeds/GxsChannelGroupItem.h | 2 +- .../src/gui/feeds/GxsChannelPostItem.cpp | 173 +++++++----- .../src/gui/feeds/GxsChannelPostItem.h | 6 +- .../src/gui/feeds/GxsForumGroupItem.cpp | 51 ++-- .../src/gui/feeds/GxsForumGroupItem.h | 2 +- .../src/gui/feeds/GxsForumMsgItem.cpp | 252 ++++++++---------- .../src/gui/feeds/GxsForumMsgItem.h | 13 +- .../src/gui/feeds/PostedGroupItem.cpp | 54 ++-- .../src/gui/feeds/PostedGroupItem.h | 2 +- retroshare-gui/src/gui/gxs/GxsFeedItem.cpp | 18 +- retroshare-gui/src/gui/gxs/GxsFeedItem.h | 8 +- .../src/gui/gxs/GxsGroupFeedItem.cpp | 66 +---- retroshare-gui/src/gui/gxs/GxsGroupFeedItem.h | 17 +- 18 files changed, 607 insertions(+), 491 deletions(-) diff --git a/retroshare-gui/src/gui/Posted/PostedCardView.cpp b/retroshare-gui/src/gui/Posted/PostedCardView.cpp index 1fef4f160..59d8976cc 100644 --- a/retroshare-gui/src/gui/Posted/PostedCardView.cpp +++ b/retroshare-gui/src/gui/Posted/PostedCardView.cpp @@ -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 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 groups; + const std::list 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 posts; - std::vector 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 posts; + std::vector 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( { 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 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 msgIds; + + for(auto MsgId: messageVersions()) + msgIds.insert(MsgId); + + std::vector posts; + std::vector 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"); diff --git a/retroshare-gui/src/gui/Posted/PostedCardView.h b/retroshare-gui/src/gui/Posted/PostedCardView.h index 7fc303680..49f6e68c4 100644 --- a/retroshare-gui/src/gui/Posted/PostedCardView.h +++ b/retroshare-gui/src/gui/Posted/PostedCardView.h @@ -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(); diff --git a/retroshare-gui/src/gui/Posted/PostedItem.cpp b/retroshare-gui/src/gui/Posted/PostedItem.cpp index b09452a8e..01e02738f 100644 --- a/retroshare-gui/src/gui/Posted/PostedItem.cpp +++ b/retroshare-gui/src/gui/Posted/PostedItem.cpp @@ -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 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 groups; + const std::list 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 posts; - std::vector 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 posts; + std::vector 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( { 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 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 msgIds; + + for(auto MsgId: messageVersions()) + msgIds.insert(MsgId); + + std::vector posts; + std::vector 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"); diff --git a/retroshare-gui/src/gui/Posted/PostedItem.h b/retroshare-gui/src/gui/Posted/PostedItem.h index 97b6974d0..0d6a161f6 100644 --- a/retroshare-gui/src/gui/Posted/PostedItem.h +++ b/retroshare-gui/src/gui/Posted/PostedItem.h @@ -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(); diff --git a/retroshare-gui/src/gui/feeds/GxsChannelGroupItem.cpp b/retroshare-gui/src/gui/feeds/GxsChannelGroupItem.cpp index af3e575dd..cb3e67aca 100644 --- a/retroshare-gui/src/gui/feeds/GxsChannelGroupItem.cpp +++ b/retroshare-gui/src/gui/feeds/GxsChannelGroupItem.cpp @@ -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 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 groups; + const std::list 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() diff --git a/retroshare-gui/src/gui/feeds/GxsChannelGroupItem.h b/retroshare-gui/src/gui/feeds/GxsChannelGroupItem.h index 266d1c019..cd7f6510b 100644 --- a/retroshare-gui/src/gui/feeds/GxsChannelGroupItem.h +++ b/retroshare-gui/src/gui/feeds/GxsChannelGroupItem.h @@ -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: diff --git a/retroshare-gui/src/gui/feeds/GxsChannelPostItem.cpp b/retroshare-gui/src/gui/feeds/GxsChannelPostItem.cpp index af2116616..c7cc02a11 100644 --- a/retroshare-gui/src/gui/feeds/GxsChannelPostItem.cpp +++ b/retroshare-gui/src/gui/feeds/GxsChannelPostItem.cpp @@ -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 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 groups; + const std::list 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 posts; - std::vector 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 posts; + std::vector 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( { 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 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 msgIds; + + for(auto MsgId: messageVersions()) + msgIds.insert(MsgId); + + std::vector posts; + std::vector 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()"; diff --git a/retroshare-gui/src/gui/feeds/GxsChannelPostItem.h b/retroshare-gui/src/gui/feeds/GxsChannelPostItem.h index a067098d9..566acda30 100644 --- a/retroshare-gui/src/gui/feeds/GxsChannelPostItem.h +++ b/retroshare-gui/src/gui/feeds/GxsChannelPostItem.h @@ -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 */ diff --git a/retroshare-gui/src/gui/feeds/GxsForumGroupItem.cpp b/retroshare-gui/src/gui/feeds/GxsForumGroupItem.cpp index 8b97d73cf..57cf259ab 100644 --- a/retroshare-gui/src/gui/feeds/GxsForumGroupItem.cpp +++ b/retroshare-gui/src/gui/feeds/GxsForumGroupItem.cpp @@ -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 groups; - if (!rsGxsForums->getGroupData(token, groups)) - { - std::cerr << "GxsForumGroupItem::loadGroup() ERROR getting data"; - std::cerr << std::endl; - return; - } + std::vector groups; + const std::list 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() diff --git a/retroshare-gui/src/gui/feeds/GxsForumGroupItem.h b/retroshare-gui/src/gui/feeds/GxsForumGroupItem.h index 3ac198630..442ad70e8 100644 --- a/retroshare-gui/src/gui/feeds/GxsForumGroupItem.h +++ b/retroshare-gui/src/gui/feeds/GxsForumGroupItem.h @@ -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: diff --git a/retroshare-gui/src/gui/feeds/GxsForumMsgItem.cpp b/retroshare-gui/src/gui/feeds/GxsForumMsgItem.cpp index 0e691258c..50decda82 100644 --- a/retroshare-gui/src/gui/feeds/GxsForumMsgItem.cpp +++ b/retroshare-gui/src/gui/feeds/GxsForumMsgItem.cpp @@ -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 @@ -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 groups; - if (!rsGxsForums->getGroupData(token, groups)) - { - std::cerr << "GxsForumGroupItem::loadGroup() ERROR getting data"; - std::cerr << std::endl; - return; - } + std::vector groups; + const std::list 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 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 msgs; + const std::list forumIds = { groupId() }; + + if(!rsGxsForums->getForumContent(groupId(),std::set( { 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 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 msgs; + const std::list forumIds = { groupId() }; - fill(); + if(!rsGxsForums->getForumContent(groupId(),std::set( { 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 &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() diff --git a/retroshare-gui/src/gui/feeds/GxsForumMsgItem.h b/retroshare-gui/src/gui/feeds/GxsForumMsgItem.h index 332d5877e..35872ab9c 100644 --- a/retroshare-gui/src/gui/feeds/GxsForumMsgItem.h +++ b/retroshare-gui/src/gui/feeds/GxsForumMsgItem.h @@ -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; diff --git a/retroshare-gui/src/gui/feeds/PostedGroupItem.cpp b/retroshare-gui/src/gui/feeds/PostedGroupItem.cpp index 50cfb92d1..be8d3b78f 100644 --- a/retroshare-gui/src/gui/feeds/PostedGroupItem.cpp +++ b/retroshare-gui/src/gui/feeds/PostedGroupItem.cpp @@ -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 groups; - if (!rsPosted->getGroupData(token, groups)) - { - std::cerr << "PostedGroupItem::loadGroup() ERROR getting data"; - std::cerr << std::endl; - return; - } + std::vector groups; + const std::list 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() diff --git a/retroshare-gui/src/gui/feeds/PostedGroupItem.h b/retroshare-gui/src/gui/feeds/PostedGroupItem.h index 88e1906dc..642dc4be0 100644 --- a/retroshare-gui/src/gui/feeds/PostedGroupItem.h +++ b/retroshare-gui/src/gui/feeds/PostedGroupItem.h @@ -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: diff --git a/retroshare-gui/src/gui/gxs/GxsFeedItem.cpp b/retroshare-gui/src/gui/gxs/GxsFeedItem.cpp index 2f11fe00e..ec796a38c 100644 --- a/retroshare-gui/src/gui/gxs/GxsFeedItem.cpp +++ b/retroshare-gui/src/gui/gxs/GxsFeedItem.cpp @@ -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 msgIds; - for(int i=0;irequestMsgRelatedInfo(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 diff --git a/retroshare-gui/src/gui/gxs/GxsFeedItem.h b/retroshare-gui/src/gui/gxs/GxsFeedItem.h index 91fda9cf6..c7c16ea79 100644 --- a/retroshare-gui/src/gui/gxs/GxsFeedItem.h +++ b/retroshare-gui/src/gui/gxs/GxsFeedItem.h @@ -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); diff --git a/retroshare-gui/src/gui/gxs/GxsGroupFeedItem.cpp b/retroshare-gui/src/gui/gxs/GxsGroupFeedItem.cpp index b8d60dd24..631dcc1e8 100644 --- a/retroshare-gui/src/gui/gxs/GxsGroupFeedItem.cpp +++ b/retroshare-gui/src/gui/gxs/GxsGroupFeedItem.cpp @@ -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 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; -} diff --git a/retroshare-gui/src/gui/gxs/GxsGroupFeedItem.h b/retroshare-gui/src/gui/gxs/GxsGroupFeedItem.h index 6c9c8d21d..653d62bb1 100644 --- a/retroshare-gui/src/gui/gxs/GxsGroupFeedItem.h +++ b/retroshare-gui/src/gui/gxs/GxsGroupFeedItem.h @@ -25,7 +25,6 @@ #include #include "gui/feeds/FeedItem.h" -#include "util/TokenQueue.h" #include "gui/RetroShareLink.h" #include @@ -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) From 5645d716994684d3ebb60629c4fc9e7be4e2451e Mon Sep 17 00:00:00 2001 From: csoler Date: Wed, 19 Feb 2020 21:52:55 +0100 Subject: [PATCH 4/5] fixed connexion between posted items and async API, and removed dead code and debug info --- libretroshare/src/services/p3posted.cc | 8 +- libretroshare/src/services/p3posted.h | 8 +- retroshare-gui/src/gui/Identity/IdDialog.cpp | 1 + .../src/gui/Posted/PostedCardView.cpp | 15 +- retroshare-gui/src/gui/Posted/PostedItem.cpp | 17 +-- .../src/gui/Posted/PostedListWidget.cpp | 12 +- .../src/gui/WikiPoos/WikiDialog.cpp | 3 +- .../src/gui/feeds/GxsChannelGroupItem.cpp | 2 +- .../src/gui/feeds/PostedGroupItem.cpp | 5 +- .../src/gui/gxs/GxsGroupFeedItem.cpp | 36 ----- retroshare-gui/src/gui/gxs/GxsIdChooser.cpp | 39 ------ .../src/gui/gxs/GxsMessageFramePostWidget.cpp | 29 ---- .../gui/gxsforums/GxsForumThreadWidget.cpp | 129 ------------------ 13 files changed, 29 insertions(+), 275 deletions(-) diff --git a/libretroshare/src/services/p3posted.cc b/libretroshare/src/services/p3posted.cc index 0eed0965e..006127918 100644 --- a/libretroshare/src/services/p3posted.cc +++ b/libretroshare/src/services/p3posted.cc @@ -302,17 +302,17 @@ bool p3Posted::createPost(uint32_t &token, RsPostedPost &msg) bool p3Posted::getBoardsInfo( const std::list& boardsIds, - std::vector& channelsInfo ) + std::vector& groupsInfo ) { uint32_t token; RsTokReqOptions opts; opts.mReqType = GXS_REQUEST_TYPE_GROUP_DATA; if( !requestGroupInfo(token, opts, boardsIds) || waitToken(token) != RsTokenService::COMPLETE ) return false; - return getGroupData(token, channelsInfo) && !channelsInfo.empty(); + return getGroupData(token, groupsInfo) && !groupsInfo.empty(); } -bool p3Posted::getBoardContent( const RsGxsGroupId& channelId, +bool p3Posted::getBoardContent( const RsGxsGroupId& groupId, const std::set& contentsIds, std::vector& posts, std::vector& comments ) @@ -322,7 +322,7 @@ bool p3Posted::getBoardContent( const RsGxsGroupId& channelId, opts.mReqType = GXS_REQUEST_TYPE_MSG_DATA; GxsMsgReq msgIds; - msgIds[channelId] = contentsIds; + msgIds[groupId] = contentsIds; if( !requestMsgInfo(token, opts, msgIds) || waitToken(token) != RsTokenService::COMPLETE ) return false; diff --git a/libretroshare/src/services/p3posted.h b/libretroshare/src/services/p3posted.h index b8674e242..04c7503e1 100644 --- a/libretroshare/src/services/p3posted.h +++ b/libretroshare/src/services/p3posted.h @@ -58,12 +58,10 @@ virtual void receiveHelperChanges(std::vector& changes) return RsGxsIfaceHelper::receiveChanges(changes); } - bool getBoardsInfo( - const std::list& boardsIds, - std::vector& channelsInfo ) override; + bool getBoardsInfo(const std::list& boardsIds, + std::vector& groupsInfo ) override; - bool getBoardContent( - const RsGxsGroupId& boardId, + bool getBoardContent(const RsGxsGroupId& groupId, const std::set& contentsIds, std::vector& posts, std::vector& comments ) override; diff --git a/retroshare-gui/src/gui/Identity/IdDialog.cpp b/retroshare-gui/src/gui/Identity/IdDialog.cpp index 4a4ec6530..c66544cc3 100644 --- a/retroshare-gui/src/gui/Identity/IdDialog.cpp +++ b/retroshare-gui/src/gui/Identity/IdDialog.cpp @@ -627,6 +627,7 @@ void IdDialog::loadCircles(const std::list& groupInfo) std::cerr << " more than 1 item correspond to this ID. Removing!" << std::endl; #endif delete clist.front() ; + clist.pop_front(); } item = clist.front() ; diff --git a/retroshare-gui/src/gui/Posted/PostedCardView.cpp b/retroshare-gui/src/gui/Posted/PostedCardView.cpp index 59d8976cc..60e947ec1 100644 --- a/retroshare-gui/src/gui/Posted/PostedCardView.cpp +++ b/retroshare-gui/src/gui/Posted/PostedCardView.cpp @@ -172,10 +172,7 @@ void PostedCardView::loadGroup() std::vector groups; const std::list groupIds = { groupId() }; -#warning Code needed in rsPosted -#ifdef TODO - if(!rsPosted->getPostedGroupInfo(groupIds,groups)) -#endif + if(!rsPosted->getBoardsInfo(groupIds,groups)) { RsErr() << "GxsPostedGroupItem::loadGroup() ERROR getting data" << std::endl; return; @@ -210,10 +207,7 @@ void PostedCardView::loadMessage() std::vector posts; std::vector comments; -#warning Code needed in rsPosted -#ifdef TODO - if(! rsPosted->getPostedContent( groupId(), std::set( { messageId() } ),posts,comments)) -#endif + if(! rsPosted->getBoardContent( groupId(), std::set( { messageId() } ),posts,comments)) { RsErr() << "PostedItem::loadMessage() ERROR getting data" << std::endl; return; @@ -265,10 +259,7 @@ void PostedCardView::loadComment() std::vector posts; std::vector comments; -#warning Code needed in rsPosted -#ifdef TODO - if(! rsPosted->getPostedContent( groupId(),msgIds,posts,comments)) -#endif + if(! rsPosted->getBoardContent( groupId(),msgIds,posts,comments)) { RsErr() << "PostedCardView::loadGroup() ERROR getting data" << std::endl; return; diff --git a/retroshare-gui/src/gui/Posted/PostedItem.cpp b/retroshare-gui/src/gui/Posted/PostedItem.cpp index 01e02738f..8b3ad07e3 100644 --- a/retroshare-gui/src/gui/Posted/PostedItem.cpp +++ b/retroshare-gui/src/gui/Posted/PostedItem.cpp @@ -182,10 +182,7 @@ void PostedItem::loadGroup() std::vector groups; const std::list groupIds = { groupId() }; -#warning Code needed in rsPosted -#ifdef TODO - if(!rsPosted->getPostedGroupInfo(groupIds,groups)) -#endif + if(!rsPosted->getBoardsInfo(groupIds,groups)) { RsErr() << "GxsPostedGroupItem::loadGroup() ERROR getting data" << std::endl; return; @@ -220,10 +217,7 @@ void PostedItem::loadMessage() std::vector posts; std::vector comments; -#warning Code needed in rsPosted -#ifdef TODO - if(! rsPosted->getPostedContent( groupId(), std::set( { messageId() } ),posts,comments)) -#endif + if(! rsPosted->getBoardContent( groupId(), std::set( { messageId() } ),posts,comments)) { RsErr() << "PostedItem::loadMessage() ERROR getting data" << std::endl; return; @@ -283,12 +277,9 @@ void PostedItem::loadComment() std::vector posts; std::vector comments; -#warning Code needed in rsPosted -#ifdef TODO - if(! rsPosted->getPostedContent( groupId(),msgIds,posts,comments)) -#endif + if(! rsPosted->getBoardContent( groupId(),msgIds,posts,comments)) { - RsErr() << "GxsGxsChannelGroupItem::loadGroup() ERROR getting data" << std::endl; + RsErr() << "PostedItem::loadGroup() ERROR getting data" << std::endl; return; } diff --git a/retroshare-gui/src/gui/Posted/PostedListWidget.cpp b/retroshare-gui/src/gui/Posted/PostedListWidget.cpp index 35ceeb212..6d0c852a5 100644 --- a/retroshare-gui/src/gui/Posted/PostedListWidget.cpp +++ b/retroshare-gui/src/gui/Posted/PostedListWidget.cpp @@ -42,7 +42,7 @@ #define POSTED_DEFAULT_LISTING_LENGTH 10 #define POSTED_MAX_INDEX 10000 -#define DEBUG_POSTED_LIST_WIDGET +//#define DEBUG_POSTED_LIST_WIDGET #define BOARD_DEFAULT_IMAGE ":/icons/png/posted.png" @@ -714,35 +714,45 @@ void PostedListWidget::applyRanking() foreach (PostedCardView *item, mPostCardView) { +#ifdef DEBUG_POSTED_LIST_WIDGET std::cerr << "PostedListWidget::applyRanking() Item: " << item; std::cerr << std::endl; +#endif if (item->getPost().mMeta.mPublishTs < min_ts) { +#ifdef DEBUG_POSTED_LIST_WIDGET std::cerr << "\t Skipping OLD"; std::cerr << std::endl; +#endif item->hide(); continue; } if (counter >= mPostIndex + mPostShow) { +#ifdef DEBUG_POSTED_LIST_WIDGET std::cerr << "\t END - Counter too high"; std::cerr << std::endl; +#endif item->hide(); } else if (counter >= mPostIndex) { +#ifdef DEBUG_POSTED_LIST_WIDGET std::cerr << "\t Adding to Layout"; std::cerr << std::endl; +#endif /* add it in! */ cviewlayout->addWidget(item); item->show(); } else { +#ifdef DEBUG_POSTED_LIST_WIDGET std::cerr << "\t Skipping to Low"; std::cerr << std::endl; +#endif item->hide(); } ++counter; diff --git a/retroshare-gui/src/gui/WikiPoos/WikiDialog.cpp b/retroshare-gui/src/gui/WikiPoos/WikiDialog.cpp index 68e1adbb3..5c23eada5 100644 --- a/retroshare-gui/src/gui/WikiPoos/WikiDialog.cpp +++ b/retroshare-gui/src/gui/WikiPoos/WikiDialog.cpp @@ -78,8 +78,7 @@ /** Constructor */ -WikiDialog::WikiDialog(QWidget *parent) -: RsGxsUpdateBroadcastPage(rsWiki, parent) +WikiDialog::WikiDialog(QWidget *parent) : RsGxsUpdateBroadcastPage(rsWiki, parent) { /* Invoke the Qt Designer generated object setup routine */ ui.setupUi(this); diff --git a/retroshare-gui/src/gui/feeds/GxsChannelGroupItem.cpp b/retroshare-gui/src/gui/feeds/GxsChannelGroupItem.cpp index cb3e67aca..e1c9a028f 100644 --- a/retroshare-gui/src/gui/feeds/GxsChannelGroupItem.cpp +++ b/retroshare-gui/src/gui/feeds/GxsChannelGroupItem.cpp @@ -101,7 +101,7 @@ void GxsChannelGroupItem::loadGroup() if(!rsGxsChannels->getChannelsInfo(groupIds,groups)) { - RsErr() << "GxsGxsChannelGroupItem::loadGroup() ERROR getting data" << std::endl; + RsErr() << "PostedItem::loadGroup() ERROR getting data" << std::endl; return; } diff --git a/retroshare-gui/src/gui/feeds/PostedGroupItem.cpp b/retroshare-gui/src/gui/feeds/PostedGroupItem.cpp index be8d3b78f..d512a0b7a 100644 --- a/retroshare-gui/src/gui/feeds/PostedGroupItem.cpp +++ b/retroshare-gui/src/gui/feeds/PostedGroupItem.cpp @@ -104,10 +104,7 @@ void PostedGroupItem::loadGroup() std::vector groups; const std::list groupIds = { groupId() }; -#warning Code needed in rsPosted -#ifdef TODO - if(!rsPosted->getPostedGroupInfo(groupIds,groups)) -#endif + if(!rsPosted->getBoardsInfo(groupIds,groups)) { RsErr() << "GxsPostedGroupItem::loadGroup() ERROR getting data" << std::endl; return; diff --git a/retroshare-gui/src/gui/gxs/GxsGroupFeedItem.cpp b/retroshare-gui/src/gui/gxs/GxsGroupFeedItem.cpp index 631dcc1e8..fb530a3ef 100644 --- a/retroshare-gui/src/gui/gxs/GxsGroupFeedItem.cpp +++ b/retroshare-gui/src/gui/gxs/GxsGroupFeedItem.cpp @@ -45,21 +45,6 @@ GxsGroupFeedItem::GxsGroupFeedItem(FeedHolder *feedHolder, uint32_t feedId, cons /* load data if we can */ mGroupId = groupId; mGxsIface = iface; - -#ifdef TO_REMOVE - mNextTokenType = 0; - mTokenTypeGroup = nextTokenType(); - - mLoadQueue = NULL; - - if (mGxsIface && autoUpdate) { - /* Connect to update broadcast */ - mUpdateBroadcastBase = new RsGxsUpdateBroadcastBase(mGxsIface); - connect(mUpdateBroadcastBase, SIGNAL(fillDisplay(bool)), this, SLOT(fillDisplaySlot(bool))); - } else { - mUpdateBroadcastBase = NULL; - } -#endif } GxsGroupFeedItem::~GxsGroupFeedItem() @@ -69,16 +54,6 @@ GxsGroupFeedItem::~GxsGroupFeedItem() std::cerr << std::endl; #endif -#ifdef TO_REMOVE - if (mLoadQueue) { - delete mLoadQueue; - } - - if (mUpdateBroadcastBase) - { - delete(mUpdateBroadcastBase); - } -#endif } void GxsGroupFeedItem::unsubscribe() @@ -132,17 +107,6 @@ void GxsGroupFeedItem::fillDisplaySlot(bool complete) requestGroup(); } -#ifdef TO_REMOVE -void GxsGroupFeedItem::fillDisplay(RsGxsUpdateBroadcastBase *updateBroadcastBase, bool /*complete*/) -{ - std::set grpIds; - updateBroadcastBase->getAllGrpIds(grpIds); - - if (grpIds.find(groupId()) != grpIds.end()) - requestGroup(); -} -#endif - /***********************************************************/ void GxsGroupFeedItem::requestGroup() diff --git a/retroshare-gui/src/gui/gxs/GxsIdChooser.cpp b/retroshare-gui/src/gui/gxs/GxsIdChooser.cpp index 60d813111..230573f95 100644 --- a/retroshare-gui/src/gui/gxs/GxsIdChooser.cpp +++ b/retroshare-gui/src/gui/gxs/GxsIdChooser.cpp @@ -221,50 +221,11 @@ bool GxsIdChooser::isInConstraintSet(const RsGxsId& id) const void GxsIdChooser::setEntryEnabled(int indx,bool /*enabled*/) { removeItem(indx) ; - -#ifdef TO_REMOVE -// bool disable = !enabled ; -// -// QSortFilterProxyModel* model = qobject_cast(QComboBox::model()); -// //QStandardItem* item = model->item(index); -// -// QModelIndex ii = model->index(indx,0); -// -// // visually disable by greying out - works only if combobox has been painted already and palette returns the wanted color -// //model->setFlags(ii,disable ? (model->flags(ii) & ~(Qt::ItemIsSelectable|Qt::ItemIsEnabled)) : (Qt::ItemIsSelectable|Qt::ItemIsEnabled)); -// -// uint32_t v = enabled?(1|32):(0); -// -// std::cerr << "GxsIdChooser::setEnabledEntry: i=" << indx << ", v=" << v << std::endl; -// -// // clear item data in order to use default color -// //model->setData(ii,disable ? (QComboBox::palette().color(QPalette::Disabled, QPalette::Text)) : QVariant(), Qt::TextColorRole); -// model->setData(ii,QVariant(v),Qt::UserRole-1) ; -// -// std::cerr << "model data after operation: " << model->data(ii,Qt::UserRole-1).toUInt() << std::endl; -#endif } uint32_t GxsIdChooser::countEnabledEntries() const { return count() ; - -#ifdef TO_REMOVE -// uint32_t res = 0 ; -// QSortFilterProxyModel* model = qobject_cast(QComboBox::model()); -// -// for(uint32_t i=0;irowCount();++i) -// { -// QModelIndex ii = model->index(i,0); -// uint32_t v = model->data(ii,Qt::UserRole-1).toUInt() ; -// -// std::cerr << "GxsIdChooser::countEnabledEntries(): i=" << i << ", v=" << v << std::endl; -// if(v > 0) -// ++res ; -// } -// -// return res ; -#endif } void GxsIdChooser::loadPrivateIds() diff --git a/retroshare-gui/src/gui/gxs/GxsMessageFramePostWidget.cpp b/retroshare-gui/src/gui/gxs/GxsMessageFramePostWidget.cpp index ed7e910d2..906c0d8de 100644 --- a/retroshare-gui/src/gui/gxs/GxsMessageFramePostWidget.cpp +++ b/retroshare-gui/src/gui/gxs/GxsMessageFramePostWidget.cpp @@ -106,35 +106,6 @@ void GxsMessageFramePostWidget::updateDisplay(bool complete) if (groupId().isNull()) { return; } - -#ifdef TO_REMOVE - bool updateGroup = false; - const std::set &grpIdsMeta = getGrpIdsMeta(); - - if(grpIdsMeta.find(groupId())!=grpIdsMeta.end()) - updateGroup = true; - - const std::set &grpIds = getGrpIds(); - if (!groupId().isNull() && grpIds.find(groupId())!=grpIds.end()) - { - updateGroup = true; - /* Do we need to fill all posts? */ - requestAllPosts(); - } else { - std::map > msgs; - getAllMsgIds(msgs); - if (!msgs.empty()) { - auto mit = msgs.find(groupId()); - if (mit != msgs.end()) { - requestPosts(mit->second); - } - } - } - - if (updateGroup) { - requestGroupData(); - } -#endif } void GxsMessageFramePostWidget::fillThreadAddPost(const QVariant &post, bool related, int current, int count) diff --git a/retroshare-gui/src/gui/gxsforums/GxsForumThreadWidget.cpp b/retroshare-gui/src/gui/gxsforums/GxsForumThreadWidget.cpp index d4e7f1208..b071673b3 100644 --- a/retroshare-gui/src/gui/gxsforums/GxsForumThreadWidget.cpp +++ b/retroshare-gui/src/gui/gxsforums/GxsForumThreadWidget.cpp @@ -481,55 +481,6 @@ QIcon GxsForumThreadWidget::groupIcon() return QIcon(); } -#ifdef TO_REMOVE -void GxsForumThreadWidget::changeEvent(QEvent *e) -{ - RsGxsUpdateBroadcastWidget::changeEvent(e); - switch (e->type()) { - case QEvent::StyleChange: - //calculateIconsAndFonts(); - break; - default: - // remove compiler warnings - break; - } -} - -static void removeMessages(std::map > &msgIds, QList &removeMsgId) -{ - QList removedMsgId; - - for (auto grpIt = msgIds.begin(); grpIt != msgIds.end(); ) - { - std::set &msgs = grpIt->second; - - QList::const_iterator removeMsgIt; - for (removeMsgIt = removeMsgId.begin(); removeMsgIt != removeMsgId.end(); ++removeMsgIt) { - if(msgs.find(*removeMsgIt) != msgs.end()) - { - removedMsgId.push_back(*removeMsgIt); - msgs.erase(*removeMsgIt); - } - } - - if (msgs.empty()) { - std::map >::iterator grpItErase = grpIt++; - msgIds.erase(grpItErase); - } else { - ++grpIt; - } - } - - if (!removedMsgId.isEmpty()) { - QList::const_iterator removedMsgIt; - for (removedMsgIt = removedMsgId.begin(); removedMsgIt != removedMsgId.end(); ++removedMsgIt) { - // remove first message id - removeMsgId.removeOne(*removedMsgIt); - } - } -} -#endif - void GxsForumThreadWidget::saveExpandedItems(QList& expanded_items) const { expanded_items.clear(); @@ -565,16 +516,6 @@ void GxsForumThreadWidget::updateDisplay(bool complete) #ifdef DEBUG_FORUMS std::cerr << "udateDisplay: groupId()=" << groupId()<< std::endl; #endif -#ifdef TO_REMOVE - if(mUpdating) - { -#ifdef DEBUG_FORUMS - std::cerr << " Already updating. Return!"<< std::endl; -#endif - return; - } -#endif - if(groupId().isNull()) { #ifdef DEBUG_FORUMS @@ -590,55 +531,6 @@ void GxsForumThreadWidget::updateDisplay(bool complete) #endif complete = true; } - -#ifdef TO_REMOVE - if(!complete) - { -#ifdef DEBUG_FORUMS - std::cerr << " checking changed group data and msgs"<< std::endl; -#endif - - const std::set &grpIdsMeta = getGrpIdsMeta(); - - if(grpIdsMeta.find(groupId())!=grpIdsMeta.end()) - { -#ifdef DEBUG_FORUMS - std::cerr << " grpMeta change. reloading!" << std::endl; -#endif - complete = true; - } - - const std::set &grpIds = getGrpIds(); - - if (grpIds.find(groupId())!=grpIds.end()) - { -#ifdef DEBUG_FORUMS - std::cerr << " grp data change. reloading!" << std::endl; -#endif - complete = true; - } - else - { - // retrieve the list of modified msg ids - // if current group is listed in the map, reload the whole hierarchy - - std::map > msgIds; - getAllMsgIds(msgIds); - - // if (!mIgnoredMsgId.empty()) /* Filter ignored messages */ - // removeMessages(msgIds, mIgnoredMsgId); - - if (msgIds.find(groupId()) != msgIds.end()) - { -#ifdef DEBUG_FORUMS - std::cerr << " msg data change. reloading!" << std::endl; -#endif - complete=true; - } - } - } -#endif - if(complete) // need to update the group data, reload the messages etc. { saveExpandedItems(mSavedExpandedMessages); @@ -1214,27 +1106,6 @@ void GxsForumThreadWidget::insertMessageData(const RsGxsForumMsg &msg) bool redacted = (overall_reputation == RsReputationLevel::LOCALLY_NEGATIVE); -#ifdef TO_REMOVE - bool setToReadOnActive = Settings->getForumMsgSetToReadOnActivate(); - uint32_t status = msg.mMeta.mMsgStatus ;//item->data(RsGxsForumModel::COLUMN_THREAD_DATA, ROLE_THREAD_STATUS).toUInt(); - - QModelIndex index = getCurrentIndex(); - if (IS_MSG_NEW(status)) { - if (setToReadOnActive) { - /* set to read */ - mThreadModel->setMsgReadStatus(mThreadProxyModel->mapToSource(index),true,false); - } else { - /* set to unread by user */ - mThreadModel->setMsgReadStatus(mThreadProxyModel->mapToSource(index),false,false); - } - } else { - if (setToReadOnActive && IS_MSG_UNREAD(status)) { - /* set to read */ - mThreadModel->setMsgReadStatus(mThreadProxyModel->mapToSource(index), true,false); - } - } -#endif - ui->time_label->setText(DateTime::formatLongDateTime(msg.mMeta.mPublishTs)); ui->by_label->setId(msg.mMeta.mAuthorId); ui->lineRight->show(); From 1c84c6123bb6f8bef4e0bb9b115978f9efbffcdd Mon Sep 17 00:00:00 2001 From: csoler Date: Thu, 20 Feb 2020 20:53:40 +0100 Subject: [PATCH 5/5] removed deadcode from IdDialog and moved CircleItem to new async API --- retroshare-gui/src/gui/Identity/IdDialog.cpp | 303 +----------------- retroshare-gui/src/gui/Identity/IdDialog.h | 2 - .../src/gui/feeds/GxsCircleItem.cpp | 126 +------- retroshare-gui/src/gui/feeds/GxsCircleItem.h | 6 +- 4 files changed, 10 insertions(+), 427 deletions(-) diff --git a/retroshare-gui/src/gui/Identity/IdDialog.cpp b/retroshare-gui/src/gui/Identity/IdDialog.cpp index c66544cc3..7b3d437e2 100644 --- a/retroshare-gui/src/gui/Identity/IdDialog.cpp +++ b/retroshare-gui/src/gui/Identity/IdDialog.cpp @@ -484,46 +484,6 @@ void IdDialog::updateCirclesDisplay() /************************** Request / Response *************************/ /*** Loading Main Index ***/ -#ifdef TO_REMOVE -void IdDialog::requestCircleGroupMeta() -{ - mStateHelper->setLoading(CIRCLESDIALOG_GROUPMETA, true); - -#ifdef ID_DEBUG - std::cerr << "CirclesDialog::requestGroupMeta()"; - std::cerr << std::endl; -#endif - - mCircleQueue->cancelActiveRequestTokens(CIRCLESDIALOG_GROUPMETA); - - RsTokReqOptions opts; - opts.mReqType = GXS_REQUEST_TYPE_GROUP_META; - - uint32_t token; - mCircleQueue->requestGroupInfo(token, RS_TOKREQ_ANSTYPE_SUMMARY, opts, CIRCLESDIALOG_GROUPMETA); -} -void IdDialog::requestCircleGroupData(const RsGxsCircleId& circle_id) -{ - mStateHelper->setLoading(CIRCLESDIALOG_GROUPDATA, true); - -#ifdef ID_DEBUG - std::cerr << "CirclesDialog::requestGroupData()"; - std::cerr << std::endl; -#endif - - mCircleQueue->cancelActiveRequestTokens(CIRCLESDIALOG_GROUPDATA); - - RsTokReqOptions opts; - opts.mReqType = GXS_REQUEST_TYPE_GROUP_DATA; - - std::list grps ; - grps.push_back(RsGxsGroupId(circle_id)); - - uint32_t token; - mCircleQueue->requestGroupInfo(token, RS_TOKREQ_ANSTYPE_DATA, opts, grps, CIRCLESDIALOG_GROUPDATA); -} -#endif - void IdDialog::updateCircles() { RsThread::async([this]() @@ -897,104 +857,6 @@ static void mark_matching_tree(QTreeWidget *w, const std::set& members, } } -#ifdef TO_REMOVE -void IdDialog::loadCircleGroupData(const uint32_t& token) -{ -#ifdef ID_DEBUG - std::cerr << "Loading circle info" << std::endl; -#endif - - std::vector circle_grp_v ; - rsGxsCircles->getGroupData(token, circle_grp_v); - - if (circle_grp_v.empty()) - { - std::cerr << "(EE) unexpected empty result from getGroupData. Cannot process circle now!" << std::endl; - return ; - } - - if (circle_grp_v.size() != 1) - { - std::cerr << "(EE) very weird result from getGroupData. Should get exactly one circle" << std::endl; - return ; - } - - RsGxsCircleGroup cg = circle_grp_v.front(); - RsGxsCircleId requested_cid(cg.mMeta.mGroupId) ; - - QTreeWidgetItem *item = ui->treeWidget_membership->currentItem(); - - RsGxsCircleId id ; - if(!getItemCircleId(item,id)) - return ; - - if(requested_cid != id) - { - std::cerr << "(WW) not the same circle. Dropping request." << std::endl; - return ; - } - - /* now mark all the members */ - - std::set members = cg.mInvitedMembers; - - mark_matching_tree(ui->idTreeWidget, members, RSID_COL_KEYID) ; - - mStateHelper->setLoading(CIRCLESDIALOG_GROUPDATA, false); -} - -void IdDialog::updateCircleGroup(const uint32_t& token) -{ -#ifdef ID_DEBUG - std::cerr << "Loading circle info" << std::endl; -#endif - - std::vector circle_grp_v ; - rsGxsCircles->getGroupData(token, circle_grp_v); - - if (circle_grp_v.empty()) - { - std::cerr << "(EE) unexpected empty result from getGroupData. Cannot process circle now!" << std::endl; - return ; - } - - if (circle_grp_v.size() != 1) - { - std::cerr << "(EE) very weird result from getGroupData. Should get exactly one circle" << std::endl; - return ; - } - - RsGxsCircleGroup cg = circle_grp_v.front(); - - /* now mark all the members */ - - std::set members = cg.mInvitedMembers; - - std::map::iterator it = mCircleUpdates.find(token) ; - - if(it == mCircleUpdates.end()) - { - std::cerr << "(EE) Cannot find token " << token << " to perform group update!" << std::endl; - return ; - } - - if(it->second.action == CircleUpdateOrder::GRANT_MEMBERSHIP) - cg.mInvitedMembers.insert(it->second.gxs_id) ; - else if(it->second.action == CircleUpdateOrder::REVOKE_MEMBERSHIP) - cg.mInvitedMembers.erase(it->second.gxs_id) ; - else - { - std::cerr << "(EE) unrecognised membership action to perform: " << it->second.action << "!" << std::endl; - return ; - } - - uint32_t token2 ; - rsGxsCircles->updateGroup(token2,cg) ; - - mCircleUpdates.erase(it) ; -} -#endif - bool IdDialog::getItemCircleId(QTreeWidgetItem *item,RsGxsCircleId& id) { #ifdef CIRCLE_MEMBERSHIP_CATEGORIES @@ -1045,7 +907,7 @@ void IdDialog::grantCircleMembership() RsThread::async([circle_id,gxs_id_to_grant]() { - // 1 - get message data from p3GxsForums + // 1 - set message data in p3GxsCircles rsGxsCircles->inviteIdsToCircle(std::set( { gxs_id_to_grant } ),circle_id); }); @@ -2140,20 +2002,6 @@ void IdDialog::modifyReputation() std::cerr << std::endl; #endif -#ifdef SUSPENDED - // Cyril: apparently the old reputation system was in used here. It's based on GXS data exchange, and probably not - // very efficient because of this. - - uint32_t token; - if (!rsIdentity->submitOpinion(token, id, false, op)) - { -#ifdef ID_DEBUG - std::cerr << "IdDialog::modifyReputation() Error submitting Opinion"; - std::cerr << std::endl; -#endif - } -#endif - // trigger refresh when finished. // basic / anstype are not needed. updateIdentity(); @@ -2198,17 +2046,6 @@ void IdDialog::updateDisplay(bool complete) updateCircles(); return; } - -// std::set grpIds; -// getAllGrpIds(grpIds); -// if (!getGrpIds().empty()) { -// requestIdList(); -// -// if (!mId.isNull() && grpIds.find(mId)!=grpIds.end()) { -// requestIdDetails(); -// requestRepList(); -// } -// } } void IdDialog::addIdentity() @@ -2271,144 +2108,6 @@ void IdDialog::filterIds() ui->idTreeWidget->filterItems(filterColumn, text); } -#ifdef TO_REMOVE -void IdDialog::requestRepList() -{ - // Removing this for the moment. - return; - - mStateHelper->setLoading(IDDIALOG_REPLIST, true); - - mIdQueue->cancelActiveRequestTokens(IDDIALOG_REPLIST); - - std::list groupIds; - groupIds.push_back(mId); - - RsTokReqOptions opts; - opts.mReqType = GXS_REQUEST_TYPE_MSG_DATA; - - uint32_t token; - mIdQueue->requestMsgInfo(token, RS_TOKREQ_ANSTYPE_DATA, opts, groupIds, IDDIALOG_REPLIST); -} - -void IdDialog::insertRepList(uint32_t token) -{ - Q_UNUSED(token) - mStateHelper->setLoading(IDDIALOG_REPLIST, false); - mStateHelper->setActive(IDDIALOG_REPLIST, true); -} - -void IdDialog::handleSerializedGroupData(uint32_t token) -{ - std::map serialized_group_map ; - - rsIdentity->getGroupSerializedData(token, serialized_group_map); - - if(serialized_group_map.size() < 1) - { - std::cerr << "(EE) Cannot get radix data " << std::endl; - return; - } - if(serialized_group_map.size() > 1) - { - std::cerr << "(EE) Too many results for serialized data" << std::endl; - return; - } - - RsGxsId gxs_id = serialized_group_map.begin()->first ; - std::string radix = serialized_group_map.begin()->second ; - - RsIdentityDetails details ; - - if(!rsIdentity->getIdDetails(gxs_id,details)) - { - std::cerr << "(EE) Cannot get id details for key " << gxs_id << std::endl; - return; - } - - QList urls ; - - RetroShareLink link = RetroShareLink::createIdentity(gxs_id,QString::fromUtf8(details.mNickname.c_str()),QString::fromStdString(radix)) ; - urls.push_back(link); - - RSLinkClipboard::copyLinks(urls) ; - - QMessageBox::information(NULL,tr("information"),tr("This identity link was copied to your clipboard. Paste it in a mail, or a message to transmit the identity to someone.")) ; -} - -void IdDialog::loadRequest(const TokenQueue * queue, const TokenRequest &req) -{ -#ifdef ID_DEBUG - std::cerr << "IdDialog::loadRequest() UserType: " << req.mUserType; - std::cerr << std::endl; -#endif - - if(queue == mIdQueue) - { - switch(req.mUserType) - { -#ifdef TO_REMOVE - case IDDIALOG_IDLIST: - insertIdList(req.mToken); - break; - - case IDDIALOG_IDDETAILS: - insertIdDetails(req.mToken); - break; - - case IDDIALOG_REPLIST: - insertRepList(req.mToken); - break; - - case IDDIALOG_SERIALIZED_GROUP: - handleSerializedGroupData(req.mToken); - break; - - case IDDIALOG_REFRESH: - // replaced by RsGxsUpdateBroadcastPage - // updateDisplay(true); - break; - default: - std::cerr << "IdDialog::loadRequest() ERROR"; - std::cerr << std::endl; - break; -#endif - } - } - -#ifdef TO_REMOVE - if(queue == mCircleQueue) - { -#ifdef ID_DEBUG - std::cerr << "CirclesDialog::loadRequest() UserType: " << req.mUserType; - std::cerr << std::endl; -#endif - - /* now switch on req */ - switch(req.mUserType) - { -// case CIRCLESDIALOG_GROUPMETA: -// loadCircleGroupMeta(req.mToken); -// break; - -// case CIRCLESDIALOG_GROUPDATA: -// loadCircleGroupData(req.mToken); -// break; -// -// case CIRCLESDIALOG_GROUPUPDATE: -// updateCircleGroup(req.mToken); -// break; - - default: - std::cerr << "CirclesDialog::loadRequest() ERROR: INVALID TYPE"; - std::cerr << std::endl; - break; - } - } -#endif -} -#endif - void IdDialog::IdListCustomPopupMenu( QPoint ) { QMenu *contextMenu = new QMenu(this); diff --git a/retroshare-gui/src/gui/Identity/IdDialog.h b/retroshare-gui/src/gui/Identity/IdDialog.h index c7d6f7088..7cecd4cc5 100644 --- a/retroshare-gui/src/gui/Identity/IdDialog.h +++ b/retroshare-gui/src/gui/Identity/IdDialog.h @@ -25,8 +25,6 @@ #include -#include "util/TokenQueue.h" - #define IMAGE_IDDIALOG ":/icons/png/people.png" namespace Ui { diff --git a/retroshare-gui/src/gui/feeds/GxsCircleItem.cpp b/retroshare-gui/src/gui/feeds/GxsCircleItem.cpp index 7673c6d19..11ccf3004 100644 --- a/retroshare-gui/src/gui/feeds/GxsCircleItem.cpp +++ b/retroshare-gui/src/gui/feeds/GxsCircleItem.cpp @@ -45,7 +45,6 @@ GxsCircleItem::GxsCircleItem(FeedHolder *feedHolder, uint32_t feedId, const RsGx setup(); } - GxsCircleItem::~GxsCircleItem() { delete(ui); @@ -76,7 +75,6 @@ void GxsCircleItem::setup() if(idDetails.mAvatar.mSize == 0 || !GxsIdDetails::loadPixmapFromData(idDetails.mAvatar.mData, idDetails.mAvatar.mSize, pixmap,GxsIdDetails::SMALL)) pixmap = GxsIdDetails::makeDefaultIcon(mGxsId,GxsIdDetails::SMALL); - /* update circle information */ RsGxsCircleDetails circleDetails; @@ -161,10 +159,6 @@ void GxsCircleItem::setup() ui->gxsIdLabel->setText(idName); ui->gxsIdLabel->setId(mGxsId); } - - /* Setup TokenQueue */ - mCircleQueue = new TokenQueue(rsGxsCircles->getTokenService(), this); - } uint64_t GxsCircleItem::uniqueIdentifier() const @@ -172,35 +166,6 @@ uint64_t GxsCircleItem::uniqueIdentifier() const return hash_64bits("GxsCircle " + mCircleId.toStdString() + " " + mGxsId.toStdString() + " " + QString::number(mType).toStdString()); } -void GxsCircleItem::loadRequest(const TokenQueue * queue, const TokenRequest &req) -{ -#ifdef ID_DEBUG - std::cerr << "GxsCircleItem::loadRequest() UserType: " << req.mUserType; - std::cerr << std::endl; -#endif - if(queue == mCircleQueue) - { -#ifdef ID_DEBUG - std::cerr << "CirclesDialog::loadRequest() UserType: " << req.mUserType; - std::cerr << std::endl; -#endif - - /* now switch on req */ - switch(req.mUserType) - { - case CIRCLESDIALOG_GROUPUPDATE: - updateCircleGroup(req.mToken); - break; - - default: - std::cerr << "GxsCircleItem::loadRequest() ERROR: INVALID TYPE"; - std::cerr << std::endl; - break; - } - } -} - - /*********** SPECIFIC FUNCTIONS ***********************/ void GxsCircleItem::showCircleDetails() @@ -219,92 +184,17 @@ void GxsCircleItem::acceptCircleSubscription() void GxsCircleItem::grantCircleMembership() { - - RsTokReqOptions opts; - opts.mReqType = GXS_REQUEST_TYPE_GROUP_DATA; - - std::list grps ; - grps.push_back(RsGxsGroupId(mCircleId)); - - uint32_t token; - mCircleQueue->requestGroupInfo(token, RS_TOKREQ_ANSTYPE_DATA, opts, grps, CIRCLESDIALOG_GROUPUPDATE); - - CircleUpdateOrder c ; - c.token = token ; - c.gxs_id = mGxsId ; - c.action = CircleUpdateOrder::GRANT_MEMBERSHIP ; - - mCircleUpdates[token] = c ; + RsThread::async([this]() + { + rsGxsCircles->inviteIdsToCircle(std::set( { mGxsId } ),mCircleId); + }); } void GxsCircleItem::revokeCircleMembership() { - - RsTokReqOptions opts; - opts.mReqType = GXS_REQUEST_TYPE_GROUP_DATA; - - std::list grps; - grps.push_back(RsGxsGroupId(mCircleId)); - - uint32_t token; - mCircleQueue->requestGroupInfo(token, RS_TOKREQ_ANSTYPE_DATA, opts, grps, CIRCLESDIALOG_GROUPUPDATE); - - CircleUpdateOrder c; - c.token = token; - c.gxs_id = mGxsId; - c.action = CircleUpdateOrder::REVOKE_MEMBERSHIP; - - mCircleUpdates[token] = c; -} - -void GxsCircleItem::updateCircleGroup(const uint32_t& token) -{ -#ifdef ID_DEBUG - std::cerr << "Loading circle info" << std::endl; -#endif - - std::vector circle_grp_v ; - rsGxsCircles->getGroupData(token, circle_grp_v); - - if (circle_grp_v.empty()) - { - std::cerr << "(EE) unexpected empty result from getGroupData. Cannot process circle now!" << std::endl; - return ; - } - - if (circle_grp_v.size() != 1) - { - std::cerr << "(EE) very weird result from getGroupData. Should get exactly one circle" << std::endl; - return ; - } - - RsGxsCircleGroup cg = circle_grp_v.front(); - - /* now mark all the members */ - - //std::set members = cg.mInvitedMembers; - - std::map::iterator it = mCircleUpdates.find(token) ; - - if(it == mCircleUpdates.end()) - { - std::cerr << "(EE) Cannot find token " << token << " to perform group update!" << std::endl; - return ; - } - - if(it->second.action == CircleUpdateOrder::GRANT_MEMBERSHIP) - cg.mInvitedMembers.insert(it->second.gxs_id) ; - else if(it->second.action == CircleUpdateOrder::REVOKE_MEMBERSHIP) - cg.mInvitedMembers.erase(it->second.gxs_id) ; - else - { - std::cerr << "(EE) unrecognised membership action to perform: " << it->second.action << "!" << std::endl; - return ; - } - - uint32_t token2 ; - rsGxsCircles->updateGroup(token2,cg) ; - - mCircleUpdates.erase(it) ; + RsThread::async([this]() + { + rsGxsCircles->revokeIdsFromCircle(std::set( { mGxsId } ),mCircleId); + }); } diff --git a/retroshare-gui/src/gui/feeds/GxsCircleItem.h b/retroshare-gui/src/gui/feeds/GxsCircleItem.h index 8c611c06b..55531222d 100644 --- a/retroshare-gui/src/gui/feeds/GxsCircleItem.h +++ b/retroshare-gui/src/gui/feeds/GxsCircleItem.h @@ -42,7 +42,7 @@ struct CircleUpdateOrder }; -class GxsCircleItem : public FeedItem, public TokenResponse +class GxsCircleItem : public FeedItem { Q_OBJECT @@ -78,10 +78,6 @@ private: RsGxsCircleId mCircleId; RsGxsId mGxsId; - TokenQueue *mCircleQueue; - std::map mCircleUpdates ; - - /** Qt Designer generated object */ Ui::GxsCircleItem *ui; };