diff --git a/libretroshare/src/services/p3gxscircles.cc b/libretroshare/src/services/p3gxscircles.cc index 4667c79a6..3665b0db5 100644 --- a/libretroshare/src/services/p3gxscircles.cc +++ b/libretroshare/src/services/p3gxscircles.cc @@ -188,7 +188,7 @@ void p3GxsCircles::service_tick() time_t now = time(NULL); if(now > mLastCacheMembershipUpdateTS + GXS_CIRCLE_DELAY_TO_CHECK_MEMBERSHIP_UPDATE) { - p3GxsCircles::checkCircleCacheForMembershipUpdate(); + checkCircleCache(); mLastCacheMembershipUpdateTS = now ; } return; @@ -1194,11 +1194,17 @@ bool p3GxsCircles::cache_reloadids(const RsGxsCircleId &circleId) return true; } -bool p3GxsCircles::checkCircleCacheForMembershipUpdate() +bool p3GxsCircles::checkCircleCache() { -#warning TODO. Should go over existing cache entries and update/process the membership requests - std::cerr << __PRETTY_FUNCTION__ << ": not implemented!" << std::endl; - return false ; +#ifdef DEBUG_CIRCLES + std::cerr << "checkCircleCache(): calling auto-subscribe check and membership update check." << std::endl; +#endif + RsStackMutex stack(mCircleMtx); /********** STACK LOCKED MTX ******/ + + mCircleCache.applyToAllCachedEntries(*this,&p3GxsCircles::locked_checkCircleCacheForAutoSubscribe) ; +// mCircleCache.applyToAllCachedEntries(*this,&p3GxsCircles::locked_checkCircleCacheForMembershipUpdate) ; + + return true ; } bool p3GxsCircles::locked_checkCircleCacheForMembershipUpdate(RsGxsCircleCache& cache) @@ -1934,8 +1940,11 @@ bool p3GxsCircles::pushCircleMembershipRequest(const RsGxsId& own_gxsid,const Rs std::cerr << " AuthorId : " << s->meta.mAuthorId << std::endl; std::cerr << " ThreadId : " << s->meta.mThreadId << std::endl; #endif - uint32_t token ; + + if(request_type == RsGxsCircleSubscriptionRequestItem::SUBSCRIPTION_REQUEST_SUBSCRIBE) + RsGenExchange::subscribeToGroup(token, RsGxsGroupId(circle_id), true); + RsGenExchange::publishMsg(token, s); // update the cache. diff --git a/libretroshare/src/services/p3gxscircles.h b/libretroshare/src/services/p3gxscircles.h index 6c47970e6..a27cf833c 100644 --- a/libretroshare/src/services/p3gxscircles.h +++ b/libretroshare/src/services/p3gxscircles.h @@ -247,7 +247,7 @@ virtual RsServiceInfo getServiceInfo(); bool cache_load_for_token(uint32_t token); bool cache_reloadids(const RsGxsCircleId &circleId); - bool checkCircleCacheForMembershipUpdate(); + bool checkCircleCache(); bool locked_checkCircleCacheForAutoSubscribe(RsGxsCircleCache &cache); bool locked_processLoadingCacheEntry(RsGxsCircleCache &cache); diff --git a/libretroshare/src/util/rsmemcache.h b/libretroshare/src/util/rsmemcache.h index dfe7c33d6..612fe5f04 100644 --- a/libretroshare/src/util/rsmemcache.h +++ b/libretroshare/src/util/rsmemcache.h @@ -52,10 +52,10 @@ template class RsMemCache { - public: +public: RsMemCache(uint32_t max_size = DEFAULT_MEM_CACHE_SIZE, std::string name = "UnknownMemCache") - :mDataCount(0), mMaxSize(max_size), mName(name) + :mDataCount(0), mMaxSize(max_size), mName(name) { clearStats(); return; @@ -69,7 +69,11 @@ template class RsMemCache bool resize(); // should be called periodically to cleanup old entries. - private: + // Apply a method of a given class ClientClass to all cached data. Can be useful... + + template bool applyToAllCachedEntries(ClientClass& c,bool (ClientClass::*method)(Value&)); + +private: bool update_lrumap(const Key &key, time_t old_ts, time_t new_ts); bool discard_LRU(int count_to_clear); @@ -77,24 +81,24 @@ template class RsMemCache // internal class. class cache_data { - public: + public: cache_data() { return; } cache_data(Key in_key, Value in_data, time_t in_ts) - :key(in_key), data(in_data), ts(in_ts) { return; } + :key(in_key), data(in_data), ts(in_ts) { return; } Key key; Value data; time_t ts; }; - std::map mDataMap; - std::multimap mLruMap; - uint32_t mDataCount; + std::map mDataMap; + std::multimap mLruMap; + uint32_t mDataCount; uint32_t mMaxSize; std::string mName; // some statistics. - void printStats(std::ostream &out); + void printStats(std::ostream &out); void clearStats(); mutable uint32_t mStats_inserted; @@ -129,6 +133,15 @@ template bool RsMemCache::is_cached(const Ke } +template template bool RsMemCache::applyToAllCachedEntries(ClientClass& c, bool (ClientClass::*method)(Value&)) +{ + bool res = true ; + + for(typename std::map::iterator it(mDataMap.begin());it!=mDataMap.end();++it) + res = res && ((c.*method)(it->second.data)) ; + + return res ; +} template bool RsMemCache::fetch(const Key &key, Value &data) { diff --git a/retroshare-gui/src/gui/Identity/IdDialog.cpp b/retroshare-gui/src/gui/Identity/IdDialog.cpp index a384cd706..39e751213 100644 --- a/retroshare-gui/src/gui/Identity/IdDialog.cpp +++ b/retroshare-gui/src/gui/Identity/IdDialog.cpp @@ -483,30 +483,6 @@ void IdDialog::loadCircleGroupMeta(const uint32_t &token) item->setData(CIRCLEGROUP_CIRCLE_COL_GROUPID,Qt::UserRole, QString::fromStdString(vit->mGroupId.toStdString())); item->setData(CIRCLEGROUP_CIRCLE_COL_GROUPFLAGS, Qt::UserRole, QVariant(vit->mSubscribeFlags)); - QString tooltip ; - tooltip += tr("Circle ID: ")+QString::fromStdString(vit->mGroupId.toStdString()) ; - - tooltip += "\n"+tr("Role: "); - - if(am_I_admin) - tooltip += tr("Administrator (Can edit invite list, and request membership).") ; - else - tooltip += tr("User (Can only request membership).") ; - - tooltip += "\n"+tr("Distribution: "); - if(am_I_subscribed) - tooltip += tr("subscribed (Receive/forward membership requests from others and invite list).") ; - else - tooltip += tr("unsubscribed (Only receive invite list).") ; - - tooltip += "\n"+tr("Permissions: ") ; - - if(am_I_in_circle) - tooltip += tr("Full member (have access to data limited to this circle)") ; - else - tooltip += tr("Not a member (do not have access to data limited to this circle)") ; - - item->setToolTip(CIRCLEGROUP_CIRCLE_COL_GROUPNAME,tooltip); #ifdef CIRCLE_MEMBERSHIP_CATEGORIES if(am_I_in_circle) { @@ -536,6 +512,31 @@ void IdDialog::loadCircleGroupMeta(const uint32_t &token) // just in case. item->setData(CIRCLEGROUP_CIRCLE_COL_GROUPFLAGS, Qt::UserRole, QVariant(vit->mSubscribeFlags)); + + QString tooltip ; + tooltip += tr("Circle ID: ")+QString::fromStdString(vit->mGroupId.toStdString()) ; + + tooltip += "\n"+tr("Role: "); + + if(am_I_admin) + tooltip += tr("Administrator (Can edit invite list, and request membership).") ; + else + tooltip += tr("User (Can only request membership).") ; + + tooltip += "\n"+tr("Distribution: "); + if(am_I_subscribed) + tooltip += tr("subscribed (Receive/forward membership requests from others and invite list).") ; + else + tooltip += tr("unsubscribed (Only receive invite list).") ; + + tooltip += "\n"+tr("Permissions: ") ; + + if(am_I_in_circle) + tooltip += tr("Full member (have access to data limited to this circle)") ; + else + tooltip += tr("Not a member (do not have access to data limited to this circle)") ; + + item->setToolTip(CIRCLEGROUP_CIRCLE_COL_GROUPNAME,tooltip); if (am_I_admin) {