From 1c84c6123bb6f8bef4e0bb9b115978f9efbffcdd Mon Sep 17 00:00:00 2001 From: csoler Date: Thu, 20 Feb 2020 20:53:40 +0100 Subject: [PATCH] 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; };