added GUI async call to ID serialised data. Allows to copy+paste identities.

This commit is contained in:
csoler 2017-04-10 20:02:14 +02:00
parent d66e653204
commit 3130ec9041
9 changed files with 168 additions and 40 deletions

View File

@ -75,6 +75,12 @@ bool RsGxsDataAccess::requestGroupInfo(uint32_t &token, uint32_t ansType, const
gir->mGroupIds = groupIds; gir->mGroupIds = groupIds;
req = gir; req = gir;
} }
else if(reqType & GXS_REQUEST_TYPE_GROUP_SERIALIZED_DATA)
{
GroupSerializedDataReq* gir = new GroupSerializedDataReq();
gir->mGroupIds = groupIds;
req = gir;
}
if(req == NULL) if(req == NULL)
{ {
@ -103,34 +109,25 @@ bool RsGxsDataAccess::requestGroupInfo(uint32_t &token, uint32_t ansType, const
uint32_t reqType = opts.mReqType; uint32_t reqType = opts.mReqType;
if(reqType & GXS_REQUEST_TYPE_GROUP_META) if(reqType & GXS_REQUEST_TYPE_GROUP_META)
{ req = new GroupMetaReq();
GroupMetaReq* gmr = new GroupMetaReq();
req = gmr;
}
else if(reqType & GXS_REQUEST_TYPE_GROUP_DATA) else if(reqType & GXS_REQUEST_TYPE_GROUP_DATA)
{ req = new GroupDataReq();
GroupDataReq* gdr = new GroupDataReq();
req = gdr;
}
else if(reqType & GXS_REQUEST_TYPE_GROUP_IDS) else if(reqType & GXS_REQUEST_TYPE_GROUP_IDS)
{ req = new GroupIdReq();
GroupIdReq* gir = new GroupIdReq(); else if(reqType & GXS_REQUEST_TYPE_GROUP_SERIALIZED_DATA)
req = gir; req = new GroupSerializedDataReq();
} else
if(req == NULL)
{ {
std::cerr << "RsGxsDataAccess::requestGroupInfo() request type not recognised, type " std::cerr << "RsGxsDataAccess::requestGroupInfo() request type not recognised, type "
<< reqType << std::endl; << reqType << std::endl;
return false; 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); setReq(req, token, ansType, opts);
storeRequest(req); storeRequest(req);
@ -430,7 +427,16 @@ bool RsGxsDataAccess::getGroupData(const uint32_t& token, std::list<RsNxsGrp*>&
else if(req->status == GXS_REQUEST_V2_STATUS_COMPLETE) else if(req->status == GXS_REQUEST_V2_STATUS_COMPLETE)
{ {
GroupDataReq* gmreq = dynamic_cast<GroupDataReq*>(req); GroupDataReq* gmreq = dynamic_cast<GroupDataReq*>(req);
if(gmreq) GroupSerializedDataReq* gsreq = dynamic_cast<GroupSerializedDataReq*>(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); grpData.swap(gmreq->mGroupData);
gmreq->mGroupData.clear(); gmreq->mGroupData.clear();
@ -804,6 +810,7 @@ void RsGxsDataAccess::processRequests()
MsgIdReq* mir; MsgIdReq* mir;
MsgRelatedInfoReq* mri; MsgRelatedInfoReq* mri;
GroupStatisticRequest* gsr; GroupStatisticRequest* gsr;
GroupSerializedDataReq* grr;
ServiceStatisticRequest* ssr; ServiceStatisticRequest* ssr;
#ifdef DATA_DEBUG #ifdef DATA_DEBUG
@ -851,6 +858,11 @@ void RsGxsDataAccess::processRequests()
{ {
ok = getServiceStatistic(ssr); ok = getServiceStatistic(ssr);
} }
else if((grr = dynamic_cast<GroupSerializedDataReq*>(req)) != NULL)
{
ok = getGroupSerializedData(grr);
}
else else
{ {
std::cerr << "RsGxsDataAccess::processRequests() Failed to process request, token: " std::cerr << "RsGxsDataAccess::processRequests() Failed to process request, token: "
@ -929,7 +941,30 @@ bool RsGxsDataAccess::getServiceStatistic(const uint32_t &token, GxsServiceStati
return true; return true;
} }
bool RsGxsDataAccess::getGroupSerializedData(GroupSerializedDataReq* req)
{
std::map<RsGxsGroupId, RsNxsGrp*> grpData;
std::list<RsGxsGroupId> grpIdsOut;
getGroupList(req->mGroupIds, req->Options, grpIdsOut);
if(grpIdsOut.empty())
return true;
for(std::list<RsGxsGroupId>::iterator lit = grpIdsOut.begin();lit != grpIdsOut.end();++lit)
grpData[*lit] = NULL;
bool ok = mDataStore->retrieveNxsGrps(grpData, true, true);
req->mGroupData.clear();
std::map<RsGxsGroupId, RsNxsGrp*>::iterator mit = grpData.begin();
for(; mit != grpData.end(); ++mit)
req->mGroupData.push_back(mit->second) ;
return ok;
}
bool RsGxsDataAccess::getGroupData(GroupDataReq* req) bool RsGxsDataAccess::getGroupData(GroupDataReq* req)
{ {
std::map<RsGxsGroupId, RsNxsGrp*> grpData; std::map<RsGxsGroupId, RsNxsGrp*> grpData;

View File

@ -418,6 +418,13 @@ private:
*/ */
bool getGroupStatistic(GroupStatisticRequest* req); 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 * Attempts to service statistic

View File

@ -61,6 +61,12 @@ public:
std::list<RsGxsGroupId> mGroupIds; std::list<RsGxsGroupId> mGroupIds;
std::list<RsGxsGroupId> mGroupIdResult; std::list<RsGxsGroupId> mGroupIdResult;
}; };
class GroupSerializedDataReq : public GxsRequest
{
public:
std::list<RsGxsGroupId> mGroupIds;
std::list<RsNxsGrp*> mGroupData;
};
class GroupDataReq : public GxsRequest class GroupDataReq : public GxsRequest
{ {

View File

@ -322,6 +322,7 @@ public:
*/ */
virtual bool getGroupData(const uint32_t &token, std::vector<RsGxsIdGroup> &groups) = 0; virtual bool getGroupData(const uint32_t &token, std::vector<RsGxsIdGroup> &groups) = 0;
virtual bool getGroupSerializedData(const uint32_t &token, std::map<RsGxsId,std::string>& serialized_groups)=0;
//virtual bool getMsgData(const uint32_t &token, std::vector<RsGxsIdOpinion> &opinions) = 0; //virtual bool getMsgData(const uint32_t &token, std::vector<RsGxsIdOpinion> &opinions) = 0;
}; };

View File

@ -47,6 +47,7 @@
#define GXS_REQUEST_TYPE_GROUP_STATS 0x01600000 #define GXS_REQUEST_TYPE_GROUP_STATS 0x01600000
#define GXS_REQUEST_TYPE_SERVICE_STATS 0x03200000 #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 // TODO CLEANUP: RS_TOKREQOPT_MSG_* should be an inner enum of RsTokReqOptions

View File

@ -1474,6 +1474,28 @@ bool p3IdService::getGroupData(const uint32_t &token, std::vector<RsGxsIdGroup>
return ok; return ok;
} }
bool p3IdService::getGroupSerializedData(const uint32_t &token, std::map<RsGxsId,std::string>& 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;
}
/********************************************************************************/ /********************************************************************************/
/********************************************************************************/ /********************************************************************************/

View File

@ -245,6 +245,8 @@ public:
// These are exposed via RsIdentity. // These are exposed via RsIdentity.
virtual bool getGroupData(const uint32_t &token, std::vector<RsGxsIdGroup> &groups); virtual bool getGroupData(const uint32_t &token, std::vector<RsGxsIdGroup> &groups);
virtual bool getGroupSerializedData(const uint32_t &token, std::map<RsGxsId,std::string>& serialized_groups);
//virtual bool getMsgData(const uint32_t &token, std::vector<RsGxsIdOpinion> &opinions); //virtual bool getMsgData(const uint32_t &token, std::vector<RsGxsIdOpinion> &opinions);
// These are local - and not exposed via RsIdentity. // These are local - and not exposed via RsIdentity.

View File

@ -55,10 +55,11 @@
*****/ *****/
// Data Requests. // Data Requests.
#define IDDIALOG_IDLIST 1 #define IDDIALOG_IDLIST 1
#define IDDIALOG_IDDETAILS 2 #define IDDIALOG_IDDETAILS 2
#define IDDIALOG_REPLIST 3 #define IDDIALOG_REPLIST 3
#define IDDIALOG_REFRESH 4 #define IDDIALOG_REFRESH 4
#define IDDIALOG_SERIALIZED_GROUP 5
#define CIRCLEGROUP_CIRCLE_COL_GROUPNAME 0 #define CIRCLEGROUP_CIRCLE_COL_GROUPNAME 0
#define CIRCLEGROUP_CIRCLE_COL_GROUPID 1 #define CIRCLEGROUP_CIRCLE_COL_GROUPID 1
@ -814,7 +815,7 @@ void IdDialog::loadCircleGroupData(const uint32_t& token)
#ifdef ID_DEBUG #ifdef ID_DEBUG
std::cerr << "Loading circle info" << std::endl; std::cerr << "Loading circle info" << std::endl;
#endif #endif
std::vector<RsGxsCircleGroup> circle_grp_v ; std::vector<RsGxsCircleGroup> circle_grp_v ;
rsGxsCircles->getGroupData(token, circle_grp_v); rsGxsCircles->getGroupData(token, circle_grp_v);
@ -1385,6 +1386,8 @@ void IdDialog::updateSelection()
} }
} }
void IdDialog::requestIdList() void IdDialog::requestIdList()
{ {
//Disable by default, will be enable by insertIdDetails() //Disable by default, will be enable by insertIdDetails()
@ -2174,6 +2177,45 @@ void IdDialog::insertRepList(uint32_t token)
mStateHelper->setActive(IDDIALOG_REPLIST, true); mStateHelper->setActive(IDDIALOG_REPLIST, true);
} }
void IdDialog::handleSerializedGroupData(uint32_t token)
{
std::map<RsGxsId,std::string> 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<RetroShareLink> 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) void IdDialog::loadRequest(const TokenQueue * queue, const TokenRequest &req)
{ {
#ifdef ID_DEBUG #ifdef ID_DEBUG
@ -2197,6 +2239,10 @@ void IdDialog::loadRequest(const TokenQueue * queue, const TokenRequest &req)
insertRepList(req.mToken); insertRepList(req.mToken);
break; break;
case IDDIALOG_SERIALIZED_GROUP:
handleSerializedGroupData(req.mToken);
break;
case IDDIALOG_REFRESH: case IDDIALOG_REFRESH:
// replaced by RsGxsUpdateBroadcastPage // replaced by RsGxsUpdateBroadcastPage
// updateDisplay(true); // updateDisplay(true);
@ -2415,28 +2461,35 @@ void IdDialog::copyRetroshareLink()
return; 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 ; RsIdentityDetails details ;
if(! rsIdentity->getIdDetails(RsGxsId(keyId),details)) if(! rsIdentity->getIdDetails(gxs_id,details))
return ; return ;
std::string radix ; if (!mIdQueue)
if(!rsIdentity->serialiseIdentityToMemory(details.mId,radix)) return;
{
std::cerr << "(EE) Cannot get radix data for key " << keyId << std::endl;
return;
}
QList<RetroShareLink> urls ;
RetroShareLink link ; mStateHelper->setLoading(IDDIALOG_SERIALIZED_GROUP, true);
link.createIdentity(RsGxsId(keyId),QString::fromUtf8(details.mNickname.c_str()),QString::fromStdString(radix)) ;
urls.push_back(link);
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<RsGxsGroupId> 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() void IdDialog::chatIdentity()

View File

@ -133,6 +133,7 @@ private:
void requestRepList(); void requestRepList();
void insertRepList(uint32_t token); void insertRepList(uint32_t token);
void handleSerializedGroupData(uint32_t token);
void requestIdEdit(std::string &id); void requestIdEdit(std::string &id);
void showIdEdit(uint32_t token); void showIdEdit(uint32_t token);