From 6a9b697e421f8487d89ac4f4c95c4cd3ca0a2d30 Mon Sep 17 00:00:00 2001 From: csoler Date: Mon, 6 Feb 2017 23:46:01 +0100 Subject: [PATCH] made RsReputation::overallReputationLevel() to also return the identity ownership flags so that we dont need to rely on async calls to p3IdService to get them --- libretroshare/src/gxs/rsgixs.h | 2 +- libretroshare/src/retroshare/rsreputations.h | 5 ++- libretroshare/src/services/p3gxsreputation.cc | 33 ++++++++++++++++++- libretroshare/src/services/p3gxsreputation.h | 3 +- .../gui/gxsforums/GxsForumThreadWidget.cpp | 14 +++----- .../src/gui/gxsforums/GxsForumsFillThread.cpp | 4 ++- 6 files changed, 46 insertions(+), 15 deletions(-) diff --git a/libretroshare/src/gxs/rsgixs.h b/libretroshare/src/gxs/rsgixs.h index 22993b65f..2f2c0f0ec 100644 --- a/libretroshare/src/gxs/rsgixs.h +++ b/libretroshare/src/gxs/rsgixs.h @@ -177,7 +177,7 @@ class RsGixsReputation { public: // get Reputation. - virtual RsReputations::ReputationLevel overallReputationLevel(const RsGxsId& id) = 0; + virtual RsReputations::ReputationLevel overallReputationLevel(const RsGxsId& id,uint32_t *identity_flags=NULL) = 0; }; /*** This Class pulls all the GXS Interfaces together ****/ diff --git a/libretroshare/src/retroshare/rsreputations.h b/libretroshare/src/retroshare/rsreputations.h index a44f29dc8..105de420a 100644 --- a/libretroshare/src/retroshare/rsreputations.h +++ b/libretroshare/src/retroshare/rsreputations.h @@ -63,7 +63,10 @@ public: virtual bool setOwnOpinion(const RsGxsId& key_id, const Opinion& op) =0; virtual bool getOwnOpinion(const RsGxsId& key_id, Opinion& op) =0; virtual bool getReputationInfo(const RsGxsId& id, const RsPgpId &ownerNode, ReputationInfo& info,bool stamp=true) =0; - virtual ReputationLevel overallReputationLevel(const RsGxsId& id)=0; + + // This returns the reputation level and also the flags of the identity service for that id. This is useful in order to get these flags without relying on the async method of p3Identity + + virtual ReputationLevel overallReputationLevel(const RsGxsId& id,uint32_t *identity_flags=NULL)=0; // parameters diff --git a/libretroshare/src/services/p3gxsreputation.cc b/libretroshare/src/services/p3gxsreputation.cc index 0152909ef..0f5650df7 100644 --- a/libretroshare/src/services/p3gxsreputation.cc +++ b/libretroshare/src/services/p3gxsreputation.cc @@ -768,14 +768,45 @@ bool p3GxsReputation::updateLatestUpdate(RsPeerId peerid,time_t latest_update) * Opinion ****/ -RsReputations::ReputationLevel p3GxsReputation::overallReputationLevel(const RsGxsId& id) +RsReputations::ReputationLevel p3GxsReputation::overallReputationLevel(const RsGxsId& id,uint32_t *identity_flags) { ReputationInfo info ; getReputationInfo(id,RsPgpId(),info) ; + RsPgpId owner_id ; + + if(identity_flags) + getIdentityFlagsAndOwnerId(id,*identity_flags,owner_id); + return info.mOverallReputationLevel ; } +bool p3GxsReputation::getIdentityFlagsAndOwnerId(const RsGxsId& gxsid, uint32_t& identity_flags,RsPgpId& owner_id) +{ + if(gxsid.isNull()) + return false ; + + RsStackMutex stack(mReputationMtx); /****** LOCKED MUTEX *******/ + + std::map::iterator it = mReputations.find(gxsid) ; + + if(it == mReputations.end()) + return false ; + + if(!(it->second.mIdentityFlags & REPUTATION_IDENTITY_FLAG_UP_TO_DATE)) + return false ; + + if(it->second.mIdentityFlags & REPUTATION_IDENTITY_FLAG_PGP_LINKED) + identity_flags |= RS_IDENTITY_FLAGS_PGP_LINKED ; + + if(it->second.mIdentityFlags & REPUTATION_IDENTITY_FLAG_PGP_KNOWN) + identity_flags |= RS_IDENTITY_FLAGS_PGP_KNOWN ; + + owner_id = it->second.mOwnerNode ; + + return true ; +} + bool p3GxsReputation::getReputationInfo(const RsGxsId& gxsid, const RsPgpId& ownerNode, RsReputations::ReputationInfo& info, bool stamp) { if(gxsid.isNull()) diff --git a/libretroshare/src/services/p3gxsreputation.h b/libretroshare/src/services/p3gxsreputation.h index d8ca3a39c..baabdaa43 100644 --- a/libretroshare/src/services/p3gxsreputation.h +++ b/libretroshare/src/services/p3gxsreputation.h @@ -115,7 +115,7 @@ public: virtual bool isNodeBanned(const RsPgpId& id); virtual void banNode(const RsPgpId& id,bool b) ; - virtual ReputationLevel overallReputationLevel(const RsGxsId& id); + virtual ReputationLevel overallReputationLevel(const RsGxsId& id,uint32_t *identity_flags=NULL); virtual void setNodeAutoPositiveOpinionForContacts(bool b) ; virtual bool nodeAutoPositiveOpinionForContacts() ; @@ -143,6 +143,7 @@ public: virtual bool loadList(std::list& load) ; private: + bool getIdentityFlagsAndOwnerId(const RsGxsId& gxsid, uint32_t& identity_flags, RsPgpId &owner_id); bool processIncoming(); diff --git a/retroshare-gui/src/gui/gxsforums/GxsForumThreadWidget.cpp b/retroshare-gui/src/gui/gxsforums/GxsForumThreadWidget.cpp index dff2f5546..841e77f77 100644 --- a/retroshare-gui/src/gui/gxsforums/GxsForumThreadWidget.cpp +++ b/retroshare-gui/src/gui/gxsforums/GxsForumThreadWidget.cpp @@ -1110,18 +1110,12 @@ QTreeWidgetItem *GxsForumThreadWidget::convertMsgToThreadWidget(const RsGxsForum // Early check for a message that should be hidden because its author // is flagged with a bad reputation - RsIdentityDetails iddetails; - RsReputations::ReputationLevel reputation_level = RsReputations::REPUTATION_NEUTRAL; + uint32_t idflags =0; + RsReputations::ReputationLevel reputation_level = rsReputations->overallReputationLevel(msg.mMeta.mAuthorId,&idflags) ; bool redacted = false; - if( rsIdentity->getIdDetails(msg.mMeta.mAuthorId,iddetails) ) - { - reputation_level = iddetails.mReputation.mOverallReputationLevel; - redacted = (reputation_level == RsReputations::REPUTATION_LOCALLY_NEGATIVE); - } - else - reputation_level = RsReputations::REPUTATION_UNKNOWN; + redacted = (reputation_level == RsReputations::REPUTATION_LOCALLY_NEGATIVE); GxsIdRSTreeWidgetItem *item = new GxsIdRSTreeWidgetItem(mThreadCompareRole,GxsIdDetails::ICON_TYPE_AVATAR ); item->moveToThread(ui->threadTreeWidget->thread()); @@ -1144,7 +1138,7 @@ QTreeWidgetItem *GxsForumThreadWidget::convertMsgToThreadWidget(const RsGxsForum rep_warning_level = 2 ; rep_tooltip_str = tr("You have banned this ID. The message will not be\ndisplayed nor forwarded to your friends.") ; } - else if(reputation_level < rsGxsForums->minReputationForForwardingMessages(mForumGroup.mMeta.mSignFlags,iddetails.mFlags)) + else if(reputation_level < rsGxsForums->minReputationForForwardingMessages(mForumGroup.mMeta.mSignFlags,idflags)) { rep_warning_level = 1 ; rep_tooltip_str = tr("You have not set an opinion for this person,\n and your friends do not vote positively: Spam regulation \nprevents the message to be forwarded to your friends.") ; diff --git a/retroshare-gui/src/gui/gxsforums/GxsForumsFillThread.cpp b/retroshare-gui/src/gui/gxsforums/GxsForumsFillThread.cpp index 7a578b6db..4c381ce42 100644 --- a/retroshare-gui/src/gui/gxsforums/GxsForumsFillThread.cpp +++ b/retroshare-gui/src/gui/gxsforums/GxsForumsFillThread.cpp @@ -31,7 +31,7 @@ #include #include -#define DEBUG_FORUMS +//#define DEBUG_FORUMS #define PROGRESSBAR_MAX 100 @@ -158,7 +158,9 @@ void GxsForumsFillThread::run() for(uint32_t i=0;i