added load/save of known forums to avoid re-displaying it in the NewsFeed after then have been deleted.

This commit is contained in:
csoler 2018-02-16 23:24:01 +01:00
parent 47f9a4907b
commit 252626f5ec
No known key found for this signature in database
GPG Key ID: 7BCA522266C0804C
5 changed files with 105 additions and 4 deletions

View File

@ -915,7 +915,6 @@ private:
std::vector<MsgDeletePublish> mMsgDeletePublish;
std::map<RsGxsId,std::set<RsPeerId> > mRoutingClues ;
std::list<std::pair<RsGxsMessageId,RsPeerId> > mTrackingClues ;
};
#endif // RSGENEXCHANGE_H

View File

@ -84,6 +84,8 @@ const uint16_t RS_SERVICE_GXS_TYPE_REPUTATION = 0x0219;
const uint16_t RS_SERVICE_TYPE_GXS_RECOGN = 0x0220;
const uint16_t RS_SERVICE_TYPE_GXS_TRANS = 0x0230;
const uint16_t RS_SERVICE_GXS_TYPE_FORUMS_CONFIG = 0x0315;
// Experimental Services.
/* DSDV Testing at the moment - Service Only */
const uint16_t RS_SERVICE_TYPE_DSDV = 0x1010;

View File

@ -1649,6 +1649,7 @@ int RsServer::StartupRetroShare()
mConfigMgr->addConfiguration("identity.cfg", gxsid_ns);
mConfigMgr->addConfiguration("gxsforums.cfg", gxsforums_ns);
mConfigMgr->addConfiguration("gxsforums_srv.cfg", mGxsForums);
mConfigMgr->addConfiguration("gxschannels.cfg", gxschannels_ns);
mConfigMgr->addConfiguration("gxscircles.cfg", gxscircles_ns);
mConfigMgr->addConfiguration("posted.cfg", posted_ns);

View File

@ -95,6 +95,91 @@ uint32_t p3GxsForums::forumsAuthenPolicy()
return policy;
}
static const uint32_t GXS_FORUMS_CONFIG_MAX_TIME_NOTIFY_STORAGE = 86400*30*2 ; // ignore notifications for 2 months
static const uint8_t GXS_FORUMS_CONFIG_SUBTYPE_NOTIFY_RECORD = 0x01 ;
struct RsGxsForumNotifyRecordsItem: public RsItem
{
RsGxsForumNotifyRecordsItem()
: RsItem(RS_PKT_VERSION_SERVICE,RS_SERVICE_GXS_TYPE_FORUMS_CONFIG,GXS_FORUMS_CONFIG_SUBTYPE_NOTIFY_RECORD)
{}
virtual ~RsGxsForumNotifyRecordsItem() {}
void serial_process( RsGenericSerializer::SerializeJob j, RsGenericSerializer::SerializeContext& ctx )
{
RS_REGISTER_SERIAL_MEMBER(records);
}
void clear() {}
std::map<RsGxsGroupId,time_t> records;
};
class GxsForumsConfigSerializer : public RsServiceSerializer
{
public:
GxsForumsConfigSerializer() : RsServiceSerializer(RS_SERVICE_TYPE_GXS_TRANS) {}
virtual ~GxsForumsConfigSerializer() {}
RsItem* create_item(uint16_t service_id, uint8_t item_sub_id) const
{
if(service_id != RS_SERVICE_GXS_TYPE_FORUMS_CONFIG)
return NULL;
switch(item_sub_id)
{
case GXS_FORUMS_CONFIG_SUBTYPE_NOTIFY_RECORD: return new RsGxsForumNotifyRecordsItem();
default:
return NULL;
}
}
};
bool p3GxsForums::saveList(bool &cleanup, std::list<RsItem *>&saveList)
{
cleanup = true ;
RsGxsForumNotifyRecordsItem *item = new RsGxsForumNotifyRecordsItem ;
item->records = mKnownForums ;
saveList.push_back(item) ;
return true;
}
bool p3GxsForums::loadList(std::list<RsItem *>& loadList)
{
while(!loadList.empty())
{
RsItem *item = loadList.front();
loadList.pop_front();
time_t now = time(NULL);
RsGxsForumNotifyRecordsItem *fnr = dynamic_cast<RsGxsForumNotifyRecordsItem*>(item) ;
if(fnr != NULL)
{
mKnownForums.clear();
for(auto it(fnr->records.begin());it!=fnr->records.end();++it)
if( it->second + GXS_FORUMS_CONFIG_MAX_TIME_NOTIFY_STORAGE < now)
mKnownForums.insert(*it) ;
}
delete item ;
}
return true;
}
RsSerialiser* p3GxsForums::setupSerialiser()
{
RsSerialiser* rss = new RsSerialiser;
rss->addSerialType(new GxsForumsConfigSerializer());
return rss;
}
void p3GxsForums::notifyChanges(std::vector<RsGxsNotify *> &changes)
{
@ -145,7 +230,9 @@ void p3GxsForums::notifyChanges(std::vector<RsGxsNotify *> &changes)
if(mKnownForums.find(*git) == mKnownForums.end())
{
notify->AddFeedItem(RS_FEED_ITEM_FORUM_NEW, git->toStdString());
mKnownForums.insert(*git) ;
mKnownForums.insert(std::make_pair(*git,time(NULL))) ;
IndicateConfigChanged();
}
else
std::cerr << "(II) Not notifying already known forum " << *git << std::endl;
@ -182,7 +269,9 @@ void p3GxsForums::notifyChanges(std::vector<RsGxsNotify *> &changes)
void p3GxsForums::service_tick()
{
dummy_tick();
#ifdef TO_REMOVE
RsTickEvent::tick_events();
#endif
return;
}
@ -564,6 +653,7 @@ bool p3GxsForums::generateGroup(uint32_t &token, std::string groupName)
}
#ifdef TO_REMOVE
// Overloaded from RsTickEvent for Event callbacks.
void p3GxsForums::handle_event(uint32_t event_type, const std::string &/*elabel*/)
{
@ -584,4 +674,5 @@ void p3GxsForums::handle_event(uint32_t event_type, const std::string &/*elabel*
break;
}
}
#endif

View File

@ -39,8 +39,10 @@
*
*/
class p3GxsForums: public RsGenExchange, public RsGxsForums,
class p3GxsForums: public RsGenExchange, public RsGxsForums, public p3Config
#ifdef TO_REMOVE
public RsTickEvent /* only needed for testing - remove after */
#endif
{
public:
@ -55,8 +57,14 @@ virtual void service_tick();
virtual void notifyChanges(std::vector<RsGxsNotify*>& changes);
#ifdef TO_REMOVE
// Overloaded from RsTickEvent.
virtual void handle_event(uint32_t event_type, const std::string &elabel);
#endif
virtual RsSerialiser* setupSerialiser(); // @see p3Config::setupSerialiser()
virtual bool saveList(bool &cleanup, std::list<RsItem *>&saveList); // @see p3Config::saveList(bool &cleanup, std::list<RsItem *>&)
virtual bool loadList(std::list<RsItem *>& loadList); // @see p3Config::loadList(std::list<RsItem *>&)
public:
@ -117,7 +125,7 @@ bool generateGroup(uint32_t &token, std::string groupName);
int mGenCount;
std::vector<ForumDummyRef> mGenRefs;
RsGxsMessageId mGenThreadId;
std::set<RsGxsGroupId> mKnownForums ;
std::map<RsGxsGroupId,time_t> mKnownForums ;
};