From 3130ec90412b29ce7df65528389b1237a9865b47 Mon Sep 17 00:00:00 2001 From: csoler Date: Mon, 10 Apr 2017 20:02:14 +0200 Subject: [PATCH] added GUI async call to ID serialised data. Allows to copy+paste identities. --- libretroshare/src/gxs/rsgxsdataaccess.cc | 77 +++++++++++----- libretroshare/src/gxs/rsgxsdataaccess.h | 7 ++ libretroshare/src/gxs/rsgxsrequesttypes.h | 6 ++ libretroshare/src/retroshare/rsidentity.h | 1 + libretroshare/src/retroshare/rstokenservice.h | 1 + libretroshare/src/services/p3idservice.cc | 22 +++++ libretroshare/src/services/p3idservice.h | 2 + retroshare-gui/src/gui/Identity/IdDialog.cpp | 91 +++++++++++++++---- retroshare-gui/src/gui/Identity/IdDialog.h | 1 + 9 files changed, 168 insertions(+), 40 deletions(-) diff --git a/libretroshare/src/gxs/rsgxsdataaccess.cc b/libretroshare/src/gxs/rsgxsdataaccess.cc index 8fcbbde5d..56899d4ce 100644 --- a/libretroshare/src/gxs/rsgxsdataaccess.cc +++ b/libretroshare/src/gxs/rsgxsdataaccess.cc @@ -75,6 +75,12 @@ bool RsGxsDataAccess::requestGroupInfo(uint32_t &token, uint32_t ansType, const gir->mGroupIds = groupIds; req = gir; } + else if(reqType & GXS_REQUEST_TYPE_GROUP_SERIALIZED_DATA) + { + GroupSerializedDataReq* gir = new GroupSerializedDataReq(); + gir->mGroupIds = groupIds; + req = gir; + } if(req == NULL) { @@ -103,34 +109,25 @@ bool RsGxsDataAccess::requestGroupInfo(uint32_t &token, uint32_t ansType, const uint32_t reqType = opts.mReqType; if(reqType & GXS_REQUEST_TYPE_GROUP_META) - { - GroupMetaReq* gmr = new GroupMetaReq(); - req = gmr; - } + req = new GroupMetaReq(); else if(reqType & GXS_REQUEST_TYPE_GROUP_DATA) - { - GroupDataReq* gdr = new GroupDataReq(); - req = gdr; - } + req = new GroupDataReq(); else if(reqType & GXS_REQUEST_TYPE_GROUP_IDS) - { - GroupIdReq* gir = new GroupIdReq(); - req = gir; - } - - if(req == NULL) + req = new GroupIdReq(); + else if(reqType & GXS_REQUEST_TYPE_GROUP_SERIALIZED_DATA) + req = new GroupSerializedDataReq(); + else { std::cerr << "RsGxsDataAccess::requestGroupInfo() request type not recognised, type " << reqType << std::endl; return false; - }else - { - generateToken(token); -#ifdef DATA_DEBUG - std::cerr << "RsGxsDataAccess::requestGroupInfo() gets Token: " << token << std::endl; -#endif } + generateToken(token); +#ifdef DATA_DEBUG + std::cerr << "RsGxsDataAccess::requestGroupInfo() gets Token: " << token << std::endl; +#endif + setReq(req, token, ansType, opts); storeRequest(req); @@ -430,7 +427,16 @@ bool RsGxsDataAccess::getGroupData(const uint32_t& token, std::list& else if(req->status == GXS_REQUEST_V2_STATUS_COMPLETE) { GroupDataReq* gmreq = dynamic_cast(req); - if(gmreq) + GroupSerializedDataReq* gsreq = dynamic_cast(req); + + if(gsreq) + { + grpData.swap(gsreq->mGroupData); + gsreq->mGroupData.clear(); + + locked_updateRequestStatus(token, GXS_REQUEST_V2_STATUS_DONE); + } + else if(gmreq) { grpData.swap(gmreq->mGroupData); gmreq->mGroupData.clear(); @@ -804,6 +810,7 @@ void RsGxsDataAccess::processRequests() MsgIdReq* mir; MsgRelatedInfoReq* mri; GroupStatisticRequest* gsr; + GroupSerializedDataReq* grr; ServiceStatisticRequest* ssr; #ifdef DATA_DEBUG @@ -851,6 +858,11 @@ void RsGxsDataAccess::processRequests() { ok = getServiceStatistic(ssr); } + else if((grr = dynamic_cast(req)) != NULL) + { + ok = getGroupSerializedData(grr); + } + else { std::cerr << "RsGxsDataAccess::processRequests() Failed to process request, token: " @@ -929,7 +941,30 @@ bool RsGxsDataAccess::getServiceStatistic(const uint32_t &token, GxsServiceStati return true; } +bool RsGxsDataAccess::getGroupSerializedData(GroupSerializedDataReq* req) +{ + std::map grpData; + std::list grpIdsOut; + getGroupList(req->mGroupIds, req->Options, grpIdsOut); + + if(grpIdsOut.empty()) + return true; + + + for(std::list::iterator lit = grpIdsOut.begin();lit != grpIdsOut.end();++lit) + grpData[*lit] = NULL; + + bool ok = mDataStore->retrieveNxsGrps(grpData, true, true); + req->mGroupData.clear(); + + std::map::iterator mit = grpData.begin(); + + for(; mit != grpData.end(); ++mit) + req->mGroupData.push_back(mit->second) ; + + return ok; +} bool RsGxsDataAccess::getGroupData(GroupDataReq* req) { std::map grpData; diff --git a/libretroshare/src/gxs/rsgxsdataaccess.h b/libretroshare/src/gxs/rsgxsdataaccess.h index ac21f4c41..d39823f81 100644 --- a/libretroshare/src/gxs/rsgxsdataaccess.h +++ b/libretroshare/src/gxs/rsgxsdataaccess.h @@ -418,6 +418,13 @@ private: */ bool getGroupStatistic(GroupStatisticRequest* req); + /*! + * + * Attempts to retrieve group data in serialized format + * @param req Request object to satisfy + */ + bool getGroupSerializedData(GroupSerializedDataReq* req); + /*! * * Attempts to service statistic diff --git a/libretroshare/src/gxs/rsgxsrequesttypes.h b/libretroshare/src/gxs/rsgxsrequesttypes.h index a344a55e7..8009f294b 100644 --- a/libretroshare/src/gxs/rsgxsrequesttypes.h +++ b/libretroshare/src/gxs/rsgxsrequesttypes.h @@ -61,6 +61,12 @@ public: std::list mGroupIds; std::list mGroupIdResult; }; +class GroupSerializedDataReq : public GxsRequest +{ +public: + std::list mGroupIds; + std::list mGroupData; +}; class GroupDataReq : public GxsRequest { diff --git a/libretroshare/src/retroshare/rsidentity.h b/libretroshare/src/retroshare/rsidentity.h index 53704961d..6be124e93 100644 --- a/libretroshare/src/retroshare/rsidentity.h +++ b/libretroshare/src/retroshare/rsidentity.h @@ -322,6 +322,7 @@ public: */ virtual bool getGroupData(const uint32_t &token, std::vector &groups) = 0; + virtual bool getGroupSerializedData(const uint32_t &token, std::map& serialized_groups)=0; //virtual bool getMsgData(const uint32_t &token, std::vector &opinions) = 0; }; diff --git a/libretroshare/src/retroshare/rstokenservice.h b/libretroshare/src/retroshare/rstokenservice.h index c55213965..5e74a527f 100644 --- a/libretroshare/src/retroshare/rstokenservice.h +++ b/libretroshare/src/retroshare/rstokenservice.h @@ -47,6 +47,7 @@ #define GXS_REQUEST_TYPE_GROUP_STATS 0x01600000 #define GXS_REQUEST_TYPE_SERVICE_STATS 0x03200000 +#define GXS_REQUEST_TYPE_GROUP_SERIALIZED_DATA 0x04000000 // TODO CLEANUP: RS_TOKREQOPT_MSG_* should be an inner enum of RsTokReqOptions diff --git a/libretroshare/src/services/p3idservice.cc b/libretroshare/src/services/p3idservice.cc index 9aeec2aea..dcc45af65 100644 --- a/libretroshare/src/services/p3idservice.cc +++ b/libretroshare/src/services/p3idservice.cc @@ -1474,6 +1474,28 @@ bool p3IdService::getGroupData(const uint32_t &token, std::vector return ok; } +bool p3IdService::getGroupSerializedData(const uint32_t &token, std::map& serialized_groups) +{ + unsigned char *mem = NULL; + uint32_t size; + RsGxsGroupId id ; + + serialized_groups.clear() ; + + if(!RsGenExchange::getSerializedGroupData(token,id, mem,size)) + { + std::cerr << "(EE) call to RsGenExchage::getSerializedGroupData() failed." << std::endl; + return false; + } + + std::string radix ; + + Radix64::encode(mem,size,radix) ; + + serialized_groups[RsGxsId(id)] = radix ; + + return true; +} /********************************************************************************/ /********************************************************************************/ diff --git a/libretroshare/src/services/p3idservice.h b/libretroshare/src/services/p3idservice.h index 6e4585eb6..91e55fe6d 100644 --- a/libretroshare/src/services/p3idservice.h +++ b/libretroshare/src/services/p3idservice.h @@ -245,6 +245,8 @@ public: // These are exposed via RsIdentity. virtual bool getGroupData(const uint32_t &token, std::vector &groups); + virtual bool getGroupSerializedData(const uint32_t &token, std::map& serialized_groups); + //virtual bool getMsgData(const uint32_t &token, std::vector &opinions); // These are local - and not exposed via RsIdentity. diff --git a/retroshare-gui/src/gui/Identity/IdDialog.cpp b/retroshare-gui/src/gui/Identity/IdDialog.cpp index 050785db1..b7923dc49 100644 --- a/retroshare-gui/src/gui/Identity/IdDialog.cpp +++ b/retroshare-gui/src/gui/Identity/IdDialog.cpp @@ -55,10 +55,11 @@ *****/ // Data Requests. -#define IDDIALOG_IDLIST 1 -#define IDDIALOG_IDDETAILS 2 -#define IDDIALOG_REPLIST 3 -#define IDDIALOG_REFRESH 4 +#define IDDIALOG_IDLIST 1 +#define IDDIALOG_IDDETAILS 2 +#define IDDIALOG_REPLIST 3 +#define IDDIALOG_REFRESH 4 +#define IDDIALOG_SERIALIZED_GROUP 5 #define CIRCLEGROUP_CIRCLE_COL_GROUPNAME 0 #define CIRCLEGROUP_CIRCLE_COL_GROUPID 1 @@ -814,7 +815,7 @@ 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); @@ -1385,6 +1386,8 @@ void IdDialog::updateSelection() } } + + void IdDialog::requestIdList() { //Disable by default, will be enable by insertIdDetails() @@ -2174,6 +2177,45 @@ void IdDialog::insertRepList(uint32_t token) 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 ; + link.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 @@ -2197,6 +2239,10 @@ void IdDialog::loadRequest(const TokenQueue * queue, const TokenRequest &req) insertRepList(req.mToken); break; + case IDDIALOG_SERIALIZED_GROUP: + handleSerializedGroupData(req.mToken); + break; + case IDDIALOG_REFRESH: // replaced by RsGxsUpdateBroadcastPage // updateDisplay(true); @@ -2415,28 +2461,35 @@ void IdDialog::copyRetroshareLink() return; } - std::string keyId = item->text(RSID_COL_KEYID).toStdString(); + RsGxsId gxs_id(item->text(RSID_COL_KEYID).toStdString()); + + if(gxs_id.isNull()) + { + std::cerr << "Null GXS id. Something went wrong." << std::endl; + return ; + } RsIdentityDetails details ; - if(! rsIdentity->getIdDetails(RsGxsId(keyId),details)) + if(! rsIdentity->getIdDetails(gxs_id,details)) return ; - std::string radix ; - if(!rsIdentity->serialiseIdentityToMemory(details.mId,radix)) - { - std::cerr << "(EE) Cannot get radix data for key " << keyId << std::endl; - return; - } - QList urls ; + if (!mIdQueue) + return; - RetroShareLink link ; - link.createIdentity(RsGxsId(keyId),QString::fromUtf8(details.mNickname.c_str()),QString::fromStdString(radix)) ; - urls.push_back(link); + mStateHelper->setLoading(IDDIALOG_SERIALIZED_GROUP, true); - RSLinkClipboard::copyLinks(urls) ; + mIdQueue->cancelActiveRequestTokens(IDDIALOG_SERIALIZED_GROUP); - 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.")) ; + std::list ids ; + ids.push_back(RsGxsGroupId(gxs_id)) ; + + RsTokReqOptions opts; + opts.mReqType = GXS_REQUEST_TYPE_GROUP_SERIALIZED_DATA; + + uint32_t token; + + mIdQueue->requestGroupInfo(token, RS_TOKREQ_ANSTYPE_DATA, opts, ids, IDDIALOG_SERIALIZED_GROUP); } void IdDialog::chatIdentity() diff --git a/retroshare-gui/src/gui/Identity/IdDialog.h b/retroshare-gui/src/gui/Identity/IdDialog.h index 64ab756af..1eaae935d 100644 --- a/retroshare-gui/src/gui/Identity/IdDialog.h +++ b/retroshare-gui/src/gui/Identity/IdDialog.h @@ -133,6 +133,7 @@ private: void requestRepList(); void insertRepList(uint32_t token); + void handleSerializedGroupData(uint32_t token); void requestIdEdit(std::string &id); void showIdEdit(uint32_t token);