From 6fde55217cfabfe10e8a582fc23eded126d35f26 Mon Sep 17 00:00:00 2001 From: csoler Date: Tue, 4 Mar 2025 16:52:29 +0100 Subject: [PATCH] added async update of ID list --- retroshare-gui/src/gui/Identity/IdDialog.cpp | 69 ++++++++++++------- retroshare-gui/src/gui/Identity/IdDialog.h | 3 +- .../src/gui/Identity/IdentityListModel.h | 3 +- 3 files changed, 50 insertions(+), 25 deletions(-) diff --git a/retroshare-gui/src/gui/Identity/IdDialog.cpp b/retroshare-gui/src/gui/Identity/IdDialog.cpp index b80dae798..de1f4b977 100644 --- a/retroshare-gui/src/gui/Identity/IdDialog.cpp +++ b/retroshare-gui/src/gui/Identity/IdDialog.cpp @@ -463,21 +463,14 @@ void IdDialog::handleEvent_main_thread(std::shared_ptr event) mId.clear(); updateIdentity(); } - updateIdList(); + updateIdListRequest(); break; case RsGxsIdentityEventCode::NEW_IDENTITY: case RsGxsIdentityEventCode::UPDATED_IDENTITY: if (isVisible()) - { - if(rsIdentity->isOwnId(RsGxsId(e->mIdentityId))) - updateIdList(); - else - updateIdTimer.start(3000); // use a timer for events not generated by local changes which generally - // come in large herds. Allows to group multiple changes into a single UI update. - } - else - needUpdateIdsOnNextShow = true; + updateIdListRequest(); // use a timer for events not generated by local changes which generally + // come in large herds. Allows to group multiple changes into a single UI update. if(!mId.isNull() && mId == e->mIdentityId) updateIdentity(); @@ -537,7 +530,7 @@ void IdDialog::toggleAutoBanIdentities(bool b) if(!id.isNull()) { rsReputations->banNode(id,b) ; - updateIdList(); + updateIdListRequest(); } } @@ -977,7 +970,7 @@ bool IdDialog::getItemCircleId(QTreeWidgetItem *item,RsGxsCircleId& id) void IdDialog::showEvent(QShowEvent *s) { if (needUpdateIdsOnNextShow) - updateIdList(); + updateIdListRequest(); if (needUpdateCirclesOnNextShow) updateCircles(); @@ -1360,7 +1353,7 @@ void IdDialog::filterToggled(const bool &value) QAction *source = qobject_cast(QObject::sender()); if (source) { filter = source->data().toInt(); - updateIdList(); + updateIdListRequest(); } } } @@ -1377,19 +1370,49 @@ void IdDialog::updateSelection() } } +void IdDialog::updateIdListRequest() +{ + if(updateIdTimer.isActive()) + { + std::cerr << "updateIdListRequest(): restarting timer"<< std::endl; + updateIdTimer.stop(); + updateIdTimer.start(1000); + } + else + { + std::cerr << "updateIdListRequest(): starting timer"<< std::endl; + updateIdTimer.start(1000); + } +} + void IdDialog::updateIdList() { - std::cerr << "Updating identity list in widget: stack is:" << std::endl; + std::cerr << "Updating identity list in widget." << std::endl; //print_stacktrace(); - applyWhileKeepingTree( [this]() { + RsThread::async([this]() + { + std::list *ids = new std::list(); - mIdListModel->updateIdentityList(); + if(!rsIdentity->getIdentitiesSummaries(*ids)) + { + std::cerr << __PRETTY_FUNCTION__ << " failed to retrieve identity metadata." << std::endl; + return; + } - } + RsQThreadUtils::postToObject( [ids,this]() + { - ); + applyWhileKeepingTree( [ids,this]() { + + mIdListModel->setIdentities(*ids) ; + delete ids; + + }); + }); + }); } + #ifdef TO_REMOVE bool IdDialog::fillIdListItem(const RsGxsIdGroup& data, QTreeWidgetItem *&item, const RsPgpId &ownPgpId, int accept) { @@ -2412,7 +2435,7 @@ void IdDialog::negativePerson() rsReputations->setOwnOpinion(id, RsOpinion::NEGATIVE); updateIdentity(); - updateIdList(); + updateIdListRequest(); } void IdDialog::neutralPerson() @@ -2423,7 +2446,7 @@ void IdDialog::neutralPerson() rsReputations->setOwnOpinion(id, RsOpinion::NEUTRAL); updateIdentity(); - updateIdList(); + updateIdListRequest(); } void IdDialog::positivePerson() { @@ -2433,7 +2456,7 @@ void IdDialog::positivePerson() rsReputations->setOwnOpinion(id, RsOpinion::POSITIVE); updateIdentity(); - updateIdList(); + updateIdListRequest(); } void IdDialog::addtoContacts() @@ -2443,7 +2466,7 @@ void IdDialog::addtoContacts() for(const auto& id : lst) rsIdentity->setAsRegularContact(id,true); - updateIdList(); + updateIdListRequest(); } void IdDialog::removefromContacts() @@ -2453,7 +2476,7 @@ void IdDialog::removefromContacts() for(const auto& id : lst) rsIdentity->setAsRegularContact(id,false); - updateIdList(); + updateIdListRequest(); } void IdDialog::on_closeInfoFrameButton_Invite_clicked() diff --git a/retroshare-gui/src/gui/Identity/IdDialog.h b/retroshare-gui/src/gui/Identity/IdDialog.h index 811e4424f..3ba384960 100644 --- a/retroshare-gui/src/gui/Identity/IdDialog.h +++ b/retroshare-gui/src/gui/Identity/IdDialog.h @@ -61,6 +61,7 @@ protected: void loadIdentity(RsGxsIdGroup id_data); void loadCircles(const std::list& circle_metas); + void updateIdListRequest(); //void requestCircleGroupData(const RsGxsCircleId& circle_id); bool getItemCircleId(QTreeWidgetItem *item,RsGxsCircleId& id) ; @@ -70,7 +71,7 @@ protected: private slots: void updateIdList(); - void updateCircles(); + void updateCircles(); void createExternalCircle(); void showEditExistingCircle(); void updateCirclesDisplay(); diff --git a/retroshare-gui/src/gui/Identity/IdentityListModel.h b/retroshare-gui/src/gui/Identity/IdentityListModel.h index 00b346803..4aab1c0a8 100644 --- a/retroshare-gui/src/gui/Identity/IdentityListModel.h +++ b/retroshare-gui/src/gui/Identity/IdentityListModel.h @@ -144,6 +144,8 @@ public: QColor mTextColorGroup; QColor mTextColorStatus[RS_STATUS_COUNT]; + void setIdentities(const std::list& identities_meta); + private: const HierarchicalCategoryInformation *getCategoryInfo (const EntryIndex&) const; const HierarchicalIdentityInformation *getIdentityInfo(const EntryIndex&) const; @@ -178,7 +180,6 @@ signals: void dataAboutToLoad(); private: - void setIdentities(const std::list& identities_meta); bool passesFilter(const EntryIndex &e, int column) const; void preMods() ;