finished removing token queue from IdDialog.cpp

This commit is contained in:
csoler 2020-02-11 08:36:35 +01:00
parent 1a250f5138
commit e4f243694b
No known key found for this signature in database
GPG Key ID: 7BCA522266C0804C
5 changed files with 132 additions and 113 deletions

View File

@ -312,7 +312,7 @@ public:
RsGxsCircleMsg& msg) =0; RsGxsCircleMsg& msg) =0;
/** /**
* @brief Invite identities to circle * @brief Invite identities to circle (admin key is required)
* @jsonapi{development} * @jsonapi{development}
* @param[in] identities ids of the identities to invite * @param[in] identities ids of the identities to invite
* @param[in] circleId Id of the circle you own and want to invite ids in * @param[in] circleId Id of the circle you own and want to invite ids in
@ -321,6 +321,16 @@ public:
virtual bool inviteIdsToCircle( const std::set<RsGxsId>& identities, virtual bool inviteIdsToCircle( const std::set<RsGxsId>& identities,
const RsGxsCircleId& circleId ) = 0; const RsGxsCircleId& circleId ) = 0;
/**
* @brief Remove identities from circle (admin key is required)
* @jsonapi{development}
* @param[in] identities ids of the identities to remove from the invite list
* @param[in] circleId Id of the circle you own and want to invite ids in
* @return false if something failed, true otherwhise
*/
virtual bool revokeIdsFromCircle( const std::set<RsGxsId>& identities,
const RsGxsCircleId& circleId ) = 0;
/** /**
* @brief Request circle membership, or accept circle invitation * @brief Request circle membership, or accept circle invitation
* @jsonapi{development} * @jsonapi{development}

View File

@ -365,6 +365,36 @@ bool p3GxsCircles::inviteIdsToCircle( const std::set<RsGxsId>& identities,
return editCircle(circleGrp); return editCircle(circleGrp);
} }
bool p3GxsCircles::revokeIdsFromCircle( const std::set<RsGxsId>& identities, const RsGxsCircleId& circleId )
{
const std::list<RsGxsGroupId> circlesIds{ RsGxsGroupId(circleId) };
std::vector<RsGxsCircleGroup> circlesInfo;
if(!getCirclesInfo(circlesIds, circlesInfo))
{
std::cerr << __PRETTY_FUNCTION__ << "Error! Failure getting group data." << std::endl;
return false;
}
if(circlesInfo.empty())
{
std::cerr << __PRETTY_FUNCTION__ << "Error! Circle: " << circleId.toStdString() << " not found!" << std::endl;
return false;
}
RsGxsCircleGroup& circleGrp = circlesInfo[0];
if(!(circleGrp.mMeta.mSubscribeFlags & GXS_SERV::GROUP_SUBSCRIBE_ADMIN))
{
std::cerr << __PRETTY_FUNCTION__ << "Error! Attempt to edit non-own " << "circle: " << circleId.toStdString() << std::endl;
return false;
}
circleGrp.mInvitedMembers.erase(identities.begin(), identities.end());
return editCircle(circleGrp);
}
bool p3GxsCircles::exportCircleLink( bool p3GxsCircles::exportCircleLink(
std::string& link, const RsGxsCircleId& circleId, std::string& link, const RsGxsCircleId& circleId,
bool includeGxsData, const std::string& baseUrl, std::string& errMsg ) bool includeGxsData, const std::string& baseUrl, std::string& errMsg )

View File

@ -208,6 +208,10 @@ public:
bool inviteIdsToCircle( const std::set<RsGxsId>& identities, bool inviteIdsToCircle( const std::set<RsGxsId>& identities,
const RsGxsCircleId& circleId ) override; const RsGxsCircleId& circleId ) override;
/// @see RsGxsCircles
bool revokeIdsFromCircle( const std::set<RsGxsId>& identities,
const RsGxsCircleId& circleId ) override;
/// @see RsGxsCircles /// @see RsGxsCircles
bool getCircleRequest(const RsGxsGroupId& circleId, bool getCircleRequest(const RsGxsGroupId& circleId,
const RsGxsMessageId& msgId, const RsGxsMessageId& msgId,

View File

@ -146,8 +146,6 @@ IdDialog::IdDialog(QWidget *parent) : MainPage(parent), ui(new Ui::IdDialog)
{ {
ui->setupUi(this); ui->setupUi(this);
mIdQueue = NULL;
mEventHandlerId_identity = 0; mEventHandlerId_identity = 0;
rsEvents->registerEventsHandler(RsEventType::GXS_IDENTITY, [this](std::shared_ptr<const RsEvent> event) { RsQThreadUtils::postToObject( [=]() { handleEvent_main_thread(event); }, this ); }, mEventHandlerId_identity ); rsEvents->registerEventsHandler(RsEventType::GXS_IDENTITY, [this](std::shared_ptr<const RsEvent> event) { RsQThreadUtils::postToObject( [=]() { handleEvent_main_thread(event); }, this ); }, mEventHandlerId_identity );
@ -358,8 +356,6 @@ IdDialog::IdDialog(QWidget *parent) : MainPage(parent), ui(new Ui::IdDialog)
QHeaderView * idheader = ui->idTreeWidget->header(); QHeaderView * idheader = ui->idTreeWidget->header();
QHeaderView_setSectionResizeModeColumn(idheader, RSID_COL_VOTES, QHeaderView::ResizeToContents); QHeaderView_setSectionResizeModeColumn(idheader, RSID_COL_VOTES, QHeaderView::ResizeToContents);
mIdQueue = new TokenQueue(rsIdentity->getTokenService(), this);
mStateHelper->setActive(IDDIALOG_IDDETAILS, false); mStateHelper->setActive(IDDIALOG_IDDETAILS, false);
mStateHelper->setActive(IDDIALOG_REPLIST, false); mStateHelper->setActive(IDDIALOG_REPLIST, false);
@ -389,10 +385,6 @@ IdDialog::IdDialog(QWidget *parent) : MainPage(parent), ui(new Ui::IdDialog)
connect(ui->treeWidget_membership, SIGNAL(customContextMenuRequested(QPoint)), this, SLOT(CircleListCustomPopupMenu(QPoint))); connect(ui->treeWidget_membership, SIGNAL(customContextMenuRequested(QPoint)), this, SLOT(CircleListCustomPopupMenu(QPoint)));
connect(ui->autoBanIdentities_CB, SIGNAL(toggled(bool)), this, SLOT(toggleAutoBanIdentities(bool))); connect(ui->autoBanIdentities_CB, SIGNAL(toggled(bool)), this, SLOT(toggleAutoBanIdentities(bool)));
/* Setup TokenQueue */
mCircleQueue = new TokenQueue(rsGxsCircles->getTokenService(), this);
updateCircles(); updateCircles();
updateIdList(); updateIdList();
} }
@ -415,7 +407,7 @@ void IdDialog::handleEvent_main_thread(std::shared_ptr<const RsEvent> event)
updateIdList(); updateIdList();
if(!mId.isNull() && mId == e->mIdentityId) if(!mId.isNull() && mId == e->mIdentityId)
requestIdDetails(); updateIdentity();
break; break;
default: default:
@ -1039,54 +1031,36 @@ void IdDialog::showEditExistingCircle()
void IdDialog::grantCircleMembership() void IdDialog::grantCircleMembership()
{ {
RsGxsCircleId circle_id ; RsGxsCircleId circle_id ;
if(!getItemCircleId(ui->treeWidget_membership->currentItem(),circle_id)) if(!getItemCircleId(ui->treeWidget_membership->currentItem(),circle_id))
return; return;
RsGxsId gxs_id_to_revoke(qobject_cast<QAction*>(sender())->data().toString().toStdString()); RsGxsId gxs_id_to_grant(qobject_cast<QAction*>(sender())->data().toString().toStdString());
RsTokReqOptions opts; RsThread::async([circle_id,gxs_id_to_grant]()
opts.mReqType = GXS_REQUEST_TYPE_GROUP_DATA; {
// 1 - get message data from p3GxsForums
std::list<RsGxsGroupId> grps ; rsGxsCircles->inviteIdsToCircle(std::set<RsGxsId>( { gxs_id_to_grant } ),circle_id);
grps.push_back(RsGxsGroupId(circle_id)); });
uint32_t token;
mCircleQueue->requestGroupInfo(token, RS_TOKREQ_ANSTYPE_DATA, opts, grps, CIRCLESDIALOG_GROUPUPDATE);
CircleUpdateOrder c ;
c.token = token ;
c.gxs_id = gxs_id_to_revoke ;
c.action = CircleUpdateOrder::GRANT_MEMBERSHIP ;
mCircleUpdates[token] = c ;
} }
void IdDialog::revokeCircleMembership() void IdDialog::revokeCircleMembership()
{ {
RsGxsCircleId circle_id ; RsGxsCircleId circle_id ;
if(!getItemCircleId(ui->treeWidget_membership->currentItem(),circle_id)) if(!getItemCircleId(ui->treeWidget_membership->currentItem(),circle_id))
return; return;
RsGxsId gxs_id_to_revoke(qobject_cast<QAction*>(sender())->data().toString().toStdString()); RsGxsId gxs_id_to_revoke(qobject_cast<QAction*>(sender())->data().toString().toStdString());
RsTokReqOptions opts; RsThread::async([circle_id,gxs_id_to_revoke]()
opts.mReqType = GXS_REQUEST_TYPE_GROUP_DATA; {
// 1 - get message data from p3GxsForums
std::list<RsGxsGroupId> grps ; rsGxsCircles->revokeIdsFromCircle(std::set<RsGxsId>( { gxs_id_to_revoke } ),circle_id);
grps.push_back(RsGxsGroupId(circle_id)); });
uint32_t token;
mCircleQueue->requestGroupInfo(token, RS_TOKREQ_ANSTYPE_DATA, opts, grps, CIRCLESDIALOG_GROUPUPDATE);
CircleUpdateOrder c ;
c.token = token ;
c.gxs_id = gxs_id_to_revoke ;
c.action = CircleUpdateOrder::REVOKE_MEMBERSHIP ;
mCircleUpdates[token] = c ;
} }
void IdDialog::acceptCircleSubscription() void IdDialog::acceptCircleSubscription()
@ -1394,7 +1368,6 @@ IdDialog::~IdDialog()
processSettings(false); processSettings(false);
delete(ui); delete(ui);
delete(mIdQueue);
} }
static QString getHumanReadableDuration(uint32_t seconds) static QString getHumanReadableDuration(uint32_t seconds)
@ -1475,7 +1448,7 @@ void IdDialog::updateSelection()
if (id != mId) { if (id != mId) {
mId = id; mId = id;
requestIdDetails(); updateIdentity();
//updateRepList(); //updateRepList();
} }
} }
@ -1488,12 +1461,8 @@ void IdDialog::updateIdList()
ui->removeIdentity->setEnabled(false); ui->removeIdentity->setEnabled(false);
ui->editIdentity->setEnabled(false); ui->editIdentity->setEnabled(false);
if (!mIdQueue)
return;
int accept = filter; int accept = filter;
RsThread::async([this]() RsThread::async([this]()
{ {
// 1 - get message data from p3GxsForums // 1 - get message data from p3GxsForums
@ -1788,10 +1757,8 @@ void IdDialog::loadIdentities(const std::map<RsGxsGroupId,RsGxsIdGroup>& ids_set
updateSelection(); updateSelection();
} }
void IdDialog::requestIdDetails() void IdDialog::updateIdentity()
{ {
mIdQueue->cancelActiveRequestTokens(IDDIALOG_IDDETAILS);
if (mId.isNull()) if (mId.isNull())
{ {
mStateHelper->setActive(IDDIALOG_IDDETAILS, false); mStateHelper->setActive(IDDIALOG_IDDETAILS, false);
@ -1804,53 +1771,48 @@ void IdDialog::requestIdDetails()
mStateHelper->setLoading(IDDIALOG_IDDETAILS, true); mStateHelper->setLoading(IDDIALOG_IDDETAILS, true);
RsTokReqOptions opts; RsThread::async([this]()
opts.mReqType = GXS_REQUEST_TYPE_GROUP_DATA; {
#ifdef ID_DEBUG
std::cerr << "Retrieving post data for identity " << mThreadId << std::endl;
#endif
uint32_t token; std::set<RsGxsId> ids( { RsGxsId(mId) } ) ;
std::list<RsGxsGroupId> groupIds; std::vector<RsGxsIdGroup> ids_data;
groupIds.push_back(mId);
mIdQueue->requestGroupInfo(token, RS_TOKREQ_ANSTYPE_DATA, opts, groupIds, IDDIALOG_IDDETAILS); if(!rsIdentity->getIdentitiesInfo(ids,ids_data))
{
std::cerr << __PRETTY_FUNCTION__ << " failed to retrieve identities group info for id " << mId << std::endl;
return;
}
if(ids_data.size() != 1)
{
std::cerr << __PRETTY_FUNCTION__ << " failed to retrieve exactly one group info for id " << mId << std::endl;
return;
}
RsGxsIdGroup group(ids_data[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 */
loadIdentity(group);
}, this );
});
} }
void IdDialog::insertIdDetails(uint32_t token) void IdDialog::loadIdentity(RsGxsIdGroup data)
{ {
mStateHelper->setLoading(IDDIALOG_IDDETAILS, false); mStateHelper->setLoading(IDDIALOG_IDDETAILS, false);
/* get details from libretroshare */ /* get details from libretroshare */
RsGxsIdGroup data;
std::vector<RsGxsIdGroup> datavector;
if (!rsIdentity->getGroupData(token, datavector))
{
mStateHelper->setActive(IDDIALOG_IDDETAILS, false);
mStateHelper->clear(IDDIALOG_REPLIST);
clearPerson();
ui->lineEdit_KeyId->setText("ERROR GETTING KEY!");
return;
}
if (datavector.size() != 1)
{
#ifdef ID_DEBUG
std::cerr << "IdDialog::insertIdDetails() Invalid datavector size";
#endif
mStateHelper->setActive(IDDIALOG_IDDETAILS, false);
mStateHelper->clear(IDDIALOG_IDDETAILS);
clearPerson();
ui->lineEdit_KeyId->setText("INVALID DV SIZE");
return;
}
mStateHelper->setActive(IDDIALOG_IDDETAILS, true); mStateHelper->setActive(IDDIALOG_IDDETAILS, true);
data = datavector[0];
/* get GPG Details from rsPeers */ /* get GPG Details from rsPeers */
RsPgpId ownPgpId = rsPeers->getGPGOwnId(); RsPgpId ownPgpId = rsPeers->getGPGOwnId();
@ -2183,7 +2145,7 @@ void IdDialog::modifyReputation()
// trigger refresh when finished. // trigger refresh when finished.
// basic / anstype are not needed. // basic / anstype are not needed.
requestIdDetails(); updateIdentity();
updateIdList(); updateIdList();
return; return;
@ -2220,7 +2182,7 @@ void IdDialog::updateDisplay(bool complete)
/* Fill complete */ /* Fill complete */
updateIdList(); updateIdList();
//requestIdDetails(); //requestIdDetails();
requestRepList(); //requestRepList();
updateCircles(); updateCircles();
return; return;
@ -2298,6 +2260,7 @@ void IdDialog::filterIds()
ui->idTreeWidget->filterItems(filterColumn, text); ui->idTreeWidget->filterItems(filterColumn, text);
} }
#ifdef TO_REMOVE
void IdDialog::requestRepList() void IdDialog::requestRepList()
{ {
// Removing this for the moment. // Removing this for the moment.
@ -2373,9 +2336,10 @@ void IdDialog::loadRequest(const TokenQueue * queue, const TokenRequest &req)
{ {
switch(req.mUserType) switch(req.mUserType)
{ {
// case IDDIALOG_IDLIST: #ifdef TO_REMOVE
// insertIdList(req.mToken); case IDDIALOG_IDLIST:
// break; insertIdList(req.mToken);
break;
case IDDIALOG_IDDETAILS: case IDDIALOG_IDDETAILS:
insertIdDetails(req.mToken); insertIdDetails(req.mToken);
@ -2397,6 +2361,7 @@ void IdDialog::loadRequest(const TokenQueue * queue, const TokenRequest &req)
std::cerr << "IdDialog::loadRequest() ERROR"; std::cerr << "IdDialog::loadRequest() ERROR";
std::cerr << std::endl; std::cerr << std::endl;
break; break;
#endif
} }
} }
@ -2431,6 +2396,7 @@ void IdDialog::loadRequest(const TokenQueue * queue, const TokenRequest &req)
} }
#endif #endif
} }
#endif
void IdDialog::IdListCustomPopupMenu( QPoint ) void IdDialog::IdListCustomPopupMenu( QPoint )
{ {
@ -2618,22 +2584,36 @@ void IdDialog::copyRetroshareLink()
if(! rsIdentity->getIdDetails(gxs_id,details)) if(! rsIdentity->getIdDetails(gxs_id,details))
return ; return ;
if (!mIdQueue) RsThread::async([gxs_id,details,this]()
return; {
#ifdef ID_DEBUG
std::cerr << "Retrieving post data for identity " << mThreadId << std::endl;
#endif
std::string radix,errMsg;
mStateHelper->setLoading(IDDIALOG_SERIALIZED_GROUP, true); if(!rsIdentity->exportIdentityLink( radix, gxs_id, true, std::string(), errMsg))
{
std::cerr << "Cannot retrieve identity data " << mId << " to create a link. Error:" << errMsg << std::endl;
return ;
}
mIdQueue->cancelActiveRequestTokens(IDDIALOG_SERIALIZED_GROUP); RsQThreadUtils::postToObject( [radix,details,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 */
std::list<RsGxsGroupId> ids ; QList<RetroShareLink> urls ;
ids.push_back(RsGxsGroupId(gxs_id)) ;
RsTokReqOptions opts; RetroShareLink link = RetroShareLink::createIdentity(details.mId,QString::fromUtf8(details.mNickname.c_str()),QString::fromStdString(radix)) ;
opts.mReqType = GXS_REQUEST_TYPE_GROUP_SERIALIZED_DATA; urls.push_back(link);
uint32_t token; RSLinkClipboard::copyLinks(urls) ;
mIdQueue->requestGroupInfo(token, RS_TOKREQ_ANSTYPE_DATA, opts, ids, 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.")) ;
}, this );
});
} }
void IdDialog::chatIdentity() void IdDialog::chatIdentity()
@ -2762,7 +2742,7 @@ void IdDialog::negativePerson()
rsReputations->setOwnOpinion(RsGxsId(Id), RsOpinion::NEGATIVE); rsReputations->setOwnOpinion(RsGxsId(Id), RsOpinion::NEGATIVE);
} }
requestIdDetails(); updateIdentity();
updateIdList(); updateIdList();
} }
@ -2778,7 +2758,7 @@ void IdDialog::neutralPerson()
rsReputations->setOwnOpinion(RsGxsId(Id), RsOpinion::NEUTRAL); rsReputations->setOwnOpinion(RsGxsId(Id), RsOpinion::NEUTRAL);
} }
requestIdDetails(); updateIdentity();
updateIdList(); updateIdList();
} }
void IdDialog::positivePerson() void IdDialog::positivePerson()
@ -2793,7 +2773,7 @@ void IdDialog::positivePerson()
rsReputations->setOwnOpinion(RsGxsId(Id), RsOpinion::POSITIVE); rsReputations->setOwnOpinion(RsGxsId(Id), RsOpinion::POSITIVE);
} }
requestIdDetails(); updateIdentity();
updateIdList(); updateIdList();
} }

View File

@ -45,7 +45,7 @@ struct CircleUpdateOrder
uint32_t action ; uint32_t action ;
}; };
class IdDialog : public MainPage, public TokenResponse class IdDialog : public MainPage
{ {
Q_OBJECT Q_OBJECT
@ -57,8 +57,6 @@ public:
virtual QString pageName() const { return tr("People") ; } //MainPage virtual QString pageName() const { return tr("People") ; } //MainPage
virtual QString helpText() const { return ""; } //MainPage virtual QString helpText() const { return ""; } //MainPage
void loadRequest(const TokenQueue *queue, const TokenRequest &req);
void navigate(const RsGxsId& gxs_id) ; // shows the info about this particular ID void navigate(const RsGxsId& gxs_id) ; // shows the info about this particular ID
protected: protected:
virtual void updateDisplay(bool complete); virtual void updateDisplay(bool complete);
@ -66,6 +64,9 @@ protected:
void updateIdList(); void updateIdList();
void loadIdentities(const std::map<RsGxsGroupId, RsGxsIdGroup> &ids_set); void loadIdentities(const std::map<RsGxsGroupId, RsGxsIdGroup> &ids_set);
void updateIdentity();
void loadIdentity(RsGxsIdGroup id_data);
void updateCircles(); void updateCircles();
void loadCircles(const std::list<RsGroupMetaData>& circle_metas); void loadCircles(const std::list<RsGroupMetaData>& circle_metas);
@ -121,9 +122,6 @@ private:
void processSettings(bool load); void processSettings(bool load);
QString createUsageString(const RsIdentityUsage& u) const; QString createUsageString(const RsIdentityUsage& u) const;
void requestIdDetails();
void insertIdDetails(uint32_t token);
void requestIdData(std::list<RsGxsGroupId> &ids); void requestIdData(std::list<RsGxsGroupId> &ids);
bool fillIdListItem(const RsGxsIdGroup& data, QTreeWidgetItem *&item, const RsPgpId &ownPgpId, int accept); bool fillIdListItem(const RsGxsIdGroup& data, QTreeWidgetItem *&item, const RsPgpId &ownPgpId, int accept);
void insertIdList(uint32_t token); void insertIdList(uint32_t token);
@ -139,9 +137,6 @@ private:
void clearPerson(); void clearPerson();
private: private:
TokenQueue *mIdQueue;
TokenQueue *mCircleQueue;
UIStateHelper *mStateHelper; UIStateHelper *mStateHelper;
QTreeWidgetItem *contactsItem; QTreeWidgetItem *contactsItem;