From 5292ff0af5763ea4de76e3c4b53ac4c1e94533aa Mon Sep 17 00:00:00 2001 From: csoler Date: Fri, 29 Jan 2021 00:18:08 +0100 Subject: [PATCH] added info about last time unsubscribed circles and forums have been advertised by subscribed friends --- libretroshare/src/gxs/rsgenexchange.cc | 11 ++++++++++- libretroshare/src/gxs/rsgenexchange.h | 10 +++++++++- libretroshare/src/services/p3gxscircles.cc | 6 +++++- libretroshare/src/services/p3gxscircles.h | 2 +- libretroshare/src/services/p3gxsforums.cc | 18 ++++++++++++++++++ libretroshare/src/services/p3gxsforums.h | 1 + .../src/gui/gxsforums/GxsForumThreadWidget.cpp | 5 +++++ 7 files changed, 49 insertions(+), 4 deletions(-) diff --git a/libretroshare/src/gxs/rsgenexchange.cc b/libretroshare/src/gxs/rsgenexchange.cc index 4439f4807..6ae096281 100644 --- a/libretroshare/src/gxs/rsgenexchange.cc +++ b/libretroshare/src/gxs/rsgenexchange.cc @@ -1384,7 +1384,9 @@ bool RsGenExchange::getGroupMeta(const uint32_t &token, std::listmeta.mGroupId << " name \"" << gItem->meta.mGroupName << "\" last seen=" << gItem->meta.mLastSeen << " now=" << time(nullptr) << std::endl; // Also check the group privacy flags. A while ago, it as possible to publish a group without privacy flags. Now it is not possible anymore. // As a consequence, it's important to supply a correct value in this flag before the data can be edited/updated. diff --git a/libretroshare/src/gxs/rsgenexchange.h b/libretroshare/src/gxs/rsgenexchange.h index ed190ff56..1bb8bbde6 100644 --- a/libretroshare/src/gxs/rsgenexchange.h +++ b/libretroshare/src/gxs/rsgenexchange.h @@ -666,7 +666,15 @@ protected: * that the group is always in use. */ virtual bool service_checkIfGroupIsStillUsed(const RsGxsGrpMetaData& /* meta */) { return true; } // see RsGenExchange - virtual rstime_t service_getLastGroupUsageTs(const RsGxsGroupId&) { return 0; } + + /*! + * \brief service_getLastGroupSeenTs + * \return + * returns the last time a friend sent information (statistics) about this group. That practically means when the + * group was still being subscribed by at least one friend. This is used by service_checkIfGroupIsStillUsed() to + * help getting rid of dead groups. + */ + virtual rstime_t service_getLastGroupSeenTs(const RsGxsGroupId&) { return 0; } public: /*! diff --git a/libretroshare/src/services/p3gxscircles.cc b/libretroshare/src/services/p3gxscircles.cc index 60c264321..b1a3bc5e2 100644 --- a/libretroshare/src/services/p3gxscircles.cc +++ b/libretroshare/src/services/p3gxscircles.cc @@ -1700,7 +1700,7 @@ bool p3GxsCircles::locked_checkCircleCacheForAutoSubscribe(RsGxsCircleCache& cac return true; } -rstime_t p3GxsCircles::service_getLastGroupUsageTs(const RsGxsGroupId& gid) +rstime_t p3GxsCircles::service_getLastGroupSeenTs(const RsGxsGroupId& gid) { rstime_t now = time(nullptr); @@ -1710,7 +1710,11 @@ rstime_t p3GxsCircles::service_getLastGroupUsageTs(const RsGxsGroupId& gid) bool unknown_posted = (it == mKnownCircles.end()); if(unknown_posted) + { + mKnownCircles[gid] = now; + IndicateConfigChanged(); return now; + } else return it->second; } diff --git a/libretroshare/src/services/p3gxscircles.h b/libretroshare/src/services/p3gxscircles.h index 2fb2429ee..a98e09184 100644 --- a/libretroshare/src/services/p3gxscircles.h +++ b/libretroshare/src/services/p3gxscircles.h @@ -290,7 +290,7 @@ public: virtual void updateGroup(uint32_t &token, RsGxsCircleGroup &group) override; virtual bool service_checkIfGroupIsStillUsed(const RsGxsGrpMetaData& meta) override; - virtual rstime_t service_getLastGroupUsageTs(const RsGxsGroupId&) override; + virtual rstime_t service_getLastGroupSeenTs(const RsGxsGroupId&) override; /* membership management for external circles */ diff --git a/libretroshare/src/services/p3gxsforums.cc b/libretroshare/src/services/p3gxsforums.cc index f2145ccee..a301997e6 100644 --- a/libretroshare/src/services/p3gxsforums.cc +++ b/libretroshare/src/services/p3gxsforums.cc @@ -417,6 +417,24 @@ void p3GxsForums::service_tick() return; } +rstime_t p3GxsForums::service_getLastGroupSeenTs(const RsGxsGroupId& gid) +{ + rstime_t now = time(nullptr); + + RS_STACK_MUTEX(mKnownForumsMutex); + + auto it = mKnownForums.find(gid); + bool unknown_forum = it == mKnownForums.end(); + + if(unknown_forum) + { + mKnownForums[gid] = now; + IndicateConfigChanged(); + return now; + } + else + return it->second; +} bool p3GxsForums::service_checkIfGroupIsStillUsed(const RsGxsGrpMetaData& meta) { #ifdef GXSFORUMS_DEBUG diff --git a/libretroshare/src/services/p3gxsforums.h b/libretroshare/src/services/p3gxsforums.h index da45afcdc..97f04cc7b 100644 --- a/libretroshare/src/services/p3gxsforums.h +++ b/libretroshare/src/services/p3gxsforums.h @@ -53,6 +53,7 @@ protected: virtual bool loadList(std::list& loadList) override; // @see p3Config::loadList(std::list&) virtual bool service_checkIfGroupIsStillUsed(const RsGxsGrpMetaData& meta) override; + virtual rstime_t service_getLastGroupSeenTs(const RsGxsGroupId&) override; public: /// @see RsGxsForums::createForumV2 bool createForumV2( diff --git a/retroshare-gui/src/gui/gxsforums/GxsForumThreadWidget.cpp b/retroshare-gui/src/gui/gxsforums/GxsForumThreadWidget.cpp index 457766fc0..eddfbf933 100644 --- a/retroshare-gui/src/gui/gxsforums/GxsForumThreadWidget.cpp +++ b/retroshare-gui/src/gui/gxsforums/GxsForumThreadWidget.cpp @@ -1065,6 +1065,11 @@ void GxsForumThreadWidget::updateForumDescription(bool success) forum_description += QString("%1: \t%2
").arg(tr("Synchronization"),getDurationString( rsGxsForums->getSyncPeriod(group.mMeta.mGroupId)/86400 )) ; forum_description += QString("%1: \t%2
").arg(tr("Storage"),getDurationString( rsGxsForums->getStoragePeriod(group.mMeta.mGroupId)/86400)); } + else + { + if(group.mMeta.mLastSeen > 0) + forum_description += QString("%1: \t%2 days ago
").arg(tr("Last seen at friends:"),QString::number((time(nullptr) - group.mMeta.mLastSeen)/86400)); + } QString distrib_string = tr("[unknown]"); switch(static_cast(group.mMeta.mCircleType))