mirror of
https://github.com/RetroShare/RetroShare.git
synced 2024-12-27 00:19:25 -05:00
fixed 2 bugs causing forums and channels to be notified when already known and added notification list for posted
This commit is contained in:
parent
5ffa5aacd2
commit
ae932b605a
@ -64,6 +64,7 @@ enum class RsServiceType : uint16_t
|
||||
GXS_TRANS = 0x0230,
|
||||
JSONAPI = 0x0240,
|
||||
FORUMS_CONFIG = 0x0315,
|
||||
POSTED_CONFIG = 0x0316,
|
||||
CHANNELS_CONFIG = 0x0317,
|
||||
RTT = 0x1011, /// Round Trip Time
|
||||
|
||||
@ -123,7 +124,9 @@ RS_DEPRECATED_FOR(RsServiceType) const uint16_t RS_SERVICE_GXS_TYPE_REPUTATION
|
||||
RS_DEPRECATED_FOR(RsServiceType) const uint16_t RS_SERVICE_TYPE_GXS_RECOGN = 0x0220;
|
||||
RS_DEPRECATED_FOR(RsServiceType) const uint16_t RS_SERVICE_TYPE_GXS_TRANS = 0x0230;
|
||||
RS_DEPRECATED_FOR(RsServiceType) const uint16_t RS_SERVICE_TYPE_JSONAPI = 0x0240;
|
||||
/// used to save notification records in GXS and possible other service-based configuration
|
||||
RS_DEPRECATED_FOR(RsServiceType) const uint16_t RS_SERVICE_GXS_TYPE_FORUMS_CONFIG = 0x0315;
|
||||
RS_DEPRECATED_FOR(RsServiceType) const uint16_t RS_SERVICE_GXS_TYPE_POSTED_CONFIG = 0x0316;
|
||||
RS_DEPRECATED_FOR(RsServiceType) const uint16_t RS_SERVICE_GXS_TYPE_CHANNELS_CONFIG = 0x0317;
|
||||
|
||||
// Experimental Services.
|
||||
|
@ -1632,6 +1632,7 @@ int RsServer::StartupRetroShare()
|
||||
mConfigMgr->addConfiguration("gxschannels_srv.cfg", mGxsChannels);
|
||||
mConfigMgr->addConfiguration("gxscircles.cfg" , gxscircles_ns);
|
||||
mConfigMgr->addConfiguration("posted.cfg" , posted_ns);
|
||||
mConfigMgr->addConfiguration("gxsposted_srv.cfg", mPosted);
|
||||
#ifdef RS_USE_WIKI
|
||||
mConfigMgr->addConfiguration("wiki.cfg", wiki_ns);
|
||||
#endif
|
||||
|
@ -136,14 +136,14 @@ uint32_t p3GxsChannels::channelsAuthenPolicy()
|
||||
static const uint32_t GXS_CHANNELS_CONFIG_MAX_TIME_NOTIFY_STORAGE = 86400*30*2 ; // ignore notifications for 2 months
|
||||
static const uint8_t GXS_CHANNELS_CONFIG_SUBTYPE_NOTIFY_RECORD = 0x01 ;
|
||||
|
||||
struct RsGxsGroupNotifyRecordsItem: public RsItem
|
||||
struct RsGxsChannelNotifyRecordsItem: public RsItem
|
||||
{
|
||||
|
||||
RsGxsGroupNotifyRecordsItem()
|
||||
RsGxsChannelNotifyRecordsItem()
|
||||
: RsItem(RS_PKT_VERSION_SERVICE,RS_SERVICE_GXS_TYPE_CHANNELS_CONFIG,GXS_CHANNELS_CONFIG_SUBTYPE_NOTIFY_RECORD)
|
||||
{}
|
||||
|
||||
virtual ~RsGxsGroupNotifyRecordsItem() {}
|
||||
virtual ~RsGxsChannelNotifyRecordsItem() {}
|
||||
|
||||
void serial_process( RsGenericSerializer::SerializeJob j,
|
||||
RsGenericSerializer::SerializeContext& ctx )
|
||||
@ -167,7 +167,7 @@ public:
|
||||
|
||||
switch(item_sub_id)
|
||||
{
|
||||
case GXS_CHANNELS_CONFIG_SUBTYPE_NOTIFY_RECORD: return new RsGxsGroupNotifyRecordsItem();
|
||||
case GXS_CHANNELS_CONFIG_SUBTYPE_NOTIFY_RECORD: return new RsGxsChannelNotifyRecordsItem();
|
||||
default:
|
||||
return NULL;
|
||||
}
|
||||
@ -178,7 +178,7 @@ bool p3GxsChannels::saveList(bool &cleanup, std::list<RsItem *>&saveList)
|
||||
{
|
||||
cleanup = true ;
|
||||
|
||||
RsGxsGroupNotifyRecordsItem *item = new RsGxsGroupNotifyRecordsItem ;
|
||||
RsGxsChannelNotifyRecordsItem *item = new RsGxsChannelNotifyRecordsItem ;
|
||||
|
||||
{
|
||||
RS_STACK_MUTEX(mKnownChannelsMutex);
|
||||
@ -198,7 +198,7 @@ bool p3GxsChannels::loadList(std::list<RsItem *>& loadList)
|
||||
|
||||
rstime_t now = time(NULL);
|
||||
|
||||
RsGxsGroupNotifyRecordsItem *fnr = dynamic_cast<RsGxsGroupNotifyRecordsItem*>(item) ;
|
||||
RsGxsChannelNotifyRecordsItem *fnr = dynamic_cast<RsGxsChannelNotifyRecordsItem*>(item) ;
|
||||
|
||||
if(fnr)
|
||||
{
|
||||
@ -206,7 +206,7 @@ bool p3GxsChannels::loadList(std::list<RsItem *>& loadList)
|
||||
mKnownChannels.clear();
|
||||
|
||||
for(auto it(fnr->records.begin());it!=fnr->records.end();++it)
|
||||
if( it->second + GXS_CHANNELS_CONFIG_MAX_TIME_NOTIFY_STORAGE < now)
|
||||
if( now < it->second + GXS_CHANNELS_CONFIG_MAX_TIME_NOTIFY_STORAGE)
|
||||
mKnownChannels.insert(*it) ;
|
||||
}
|
||||
|
||||
|
@ -96,14 +96,14 @@ uint32_t p3GxsForums::forumsAuthenPolicy()
|
||||
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 RsGxsGroupNotifyRecordsItem: public RsItem
|
||||
struct RsGxsForumNotifyRecordsItem: public RsItem
|
||||
{
|
||||
|
||||
RsGxsGroupNotifyRecordsItem()
|
||||
RsGxsForumNotifyRecordsItem()
|
||||
: RsItem(RS_PKT_VERSION_SERVICE,RS_SERVICE_GXS_TYPE_FORUMS_CONFIG,GXS_FORUMS_CONFIG_SUBTYPE_NOTIFY_RECORD)
|
||||
{}
|
||||
|
||||
virtual ~RsGxsGroupNotifyRecordsItem() {}
|
||||
virtual ~RsGxsForumNotifyRecordsItem() {}
|
||||
|
||||
void serial_process( RsGenericSerializer::SerializeJob j,
|
||||
RsGenericSerializer::SerializeContext& ctx )
|
||||
@ -127,7 +127,7 @@ public:
|
||||
|
||||
switch(item_sub_id)
|
||||
{
|
||||
case GXS_FORUMS_CONFIG_SUBTYPE_NOTIFY_RECORD: return new RsGxsGroupNotifyRecordsItem();
|
||||
case GXS_FORUMS_CONFIG_SUBTYPE_NOTIFY_RECORD: return new RsGxsForumNotifyRecordsItem();
|
||||
default:
|
||||
return NULL;
|
||||
}
|
||||
@ -138,7 +138,7 @@ bool p3GxsForums::saveList(bool &cleanup, std::list<RsItem *>&saveList)
|
||||
{
|
||||
cleanup = true ;
|
||||
|
||||
RsGxsGroupNotifyRecordsItem *item = new RsGxsGroupNotifyRecordsItem ;
|
||||
RsGxsForumNotifyRecordsItem *item = new RsGxsForumNotifyRecordsItem ;
|
||||
|
||||
item->records = mKnownForums ;
|
||||
|
||||
@ -155,14 +155,14 @@ bool p3GxsForums::loadList(std::list<RsItem *>& loadList)
|
||||
|
||||
rstime_t now = time(NULL);
|
||||
|
||||
RsGxsGroupNotifyRecordsItem *fnr = dynamic_cast<RsGxsGroupNotifyRecordsItem*>(item) ;
|
||||
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)
|
||||
if( now < it->second + GXS_FORUMS_CONFIG_MAX_TIME_NOTIFY_STORAGE)
|
||||
mKnownForums.insert(*it) ;
|
||||
}
|
||||
|
||||
|
@ -157,15 +157,26 @@ void p3PostBase::notifyChanges(std::vector<RsGxsNotify *> &changes)
|
||||
const std::list<RsGxsGroupId>& grpList = grpChange->mGrpIdList;
|
||||
|
||||
for (auto git = grpList.begin(); git != grpList.end(); ++git)
|
||||
{
|
||||
{
|
||||
if(mKnownPosted.find(*git) == mKnownPosted.end())
|
||||
{
|
||||
mKnownPosted.insert(std::make_pair(*git, time(nullptr)));
|
||||
IndicateConfigChanged();
|
||||
|
||||
auto ev = std::make_shared<RsGxsPostedEvent>();
|
||||
ev->mPostedGroupId = *git;
|
||||
ev->mPostedEventCode = RsPostedEventCode::NEW_POSTED_GROUP;
|
||||
rsEvents->postEvent(ev);
|
||||
|
||||
#ifdef POSTBASE_DEBUG
|
||||
std::cerr << "p3PostBase::notifyChanges() Incoming Group: " << *git;
|
||||
std::cerr << std::endl;
|
||||
std::cerr << "p3PostBase::notifyChanges() Incoming Group: " << *git;
|
||||
std::cerr << std::endl;
|
||||
#endif
|
||||
auto ev = std::make_shared<RsGxsPostedEvent>();
|
||||
ev->mPostedGroupId = *git;
|
||||
ev->mPostedEventCode = RsPostedEventCode::NEW_POSTED_GROUP;
|
||||
rsEvents->postEvent(ev);
|
||||
}
|
||||
else
|
||||
RsInfo() << __PRETTY_FUNCTION__
|
||||
<< " Not notifying already known forum "
|
||||
<< *git << std::endl;
|
||||
}
|
||||
}
|
||||
break;
|
||||
@ -828,3 +839,89 @@ void p3PostBase::handleResponse(uint32_t token, uint32_t req_type)
|
||||
}
|
||||
}
|
||||
|
||||
static const uint32_t GXS_POSTED_CONFIG_MAX_TIME_NOTIFY_STORAGE = 86400*30*2 ; // ignore notifications for 2 months
|
||||
static const uint8_t GXS_POSTED_CONFIG_SUBTYPE_NOTIFY_RECORD = 0x01 ;
|
||||
|
||||
struct RsGxsPostedNotifyRecordsItem: public RsItem
|
||||
{
|
||||
|
||||
RsGxsPostedNotifyRecordsItem()
|
||||
: RsItem(RS_PKT_VERSION_SERVICE,RS_SERVICE_GXS_TYPE_POSTED_CONFIG,GXS_POSTED_CONFIG_SUBTYPE_NOTIFY_RECORD)
|
||||
{}
|
||||
|
||||
virtual ~RsGxsPostedNotifyRecordsItem() {}
|
||||
|
||||
void serial_process( RsGenericSerializer::SerializeJob j,
|
||||
RsGenericSerializer::SerializeContext& ctx )
|
||||
{ RS_SERIAL_PROCESS(records); }
|
||||
|
||||
void clear() {}
|
||||
|
||||
std::map<RsGxsGroupId,rstime_t> records;
|
||||
};
|
||||
|
||||
class GxsPostedConfigSerializer : public RsServiceSerializer
|
||||
{
|
||||
public:
|
||||
GxsPostedConfigSerializer() : RsServiceSerializer(RS_SERVICE_GXS_TYPE_POSTED_CONFIG) {}
|
||||
virtual ~GxsPostedConfigSerializer() {}
|
||||
|
||||
RsItem* create_item(uint16_t service_id, uint8_t item_sub_id) const
|
||||
{
|
||||
if(service_id != RS_SERVICE_GXS_TYPE_POSTED_CONFIG)
|
||||
return NULL;
|
||||
|
||||
switch(item_sub_id)
|
||||
{
|
||||
case GXS_POSTED_CONFIG_SUBTYPE_NOTIFY_RECORD: return new RsGxsPostedNotifyRecordsItem();
|
||||
default:
|
||||
return NULL;
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
bool p3PostBase::saveList(bool &cleanup, std::list<RsItem *>&saveList)
|
||||
{
|
||||
cleanup = true ;
|
||||
|
||||
RsGxsPostedNotifyRecordsItem *item = new RsGxsPostedNotifyRecordsItem ;
|
||||
|
||||
item->records = mKnownPosted ;
|
||||
|
||||
saveList.push_back(item) ;
|
||||
return true;
|
||||
}
|
||||
|
||||
bool p3PostBase::loadList(std::list<RsItem *>& loadList)
|
||||
{
|
||||
while(!loadList.empty())
|
||||
{
|
||||
RsItem *item = loadList.front();
|
||||
loadList.pop_front();
|
||||
|
||||
rstime_t now = time(NULL);
|
||||
|
||||
RsGxsPostedNotifyRecordsItem *fnr = dynamic_cast<RsGxsPostedNotifyRecordsItem*>(item) ;
|
||||
|
||||
if(fnr != NULL)
|
||||
{
|
||||
mKnownPosted.clear();
|
||||
|
||||
for(auto it(fnr->records.begin());it!=fnr->records.end();++it)
|
||||
if( now < it->second + GXS_POSTED_CONFIG_MAX_TIME_NOTIFY_STORAGE)
|
||||
mKnownPosted.insert(*it) ;
|
||||
}
|
||||
|
||||
delete item ;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
RsSerialiser* p3PostBase::setupSerialiser()
|
||||
{
|
||||
RsSerialiser* rss = new RsSerialiser;
|
||||
rss->addSerialType(new GxsPostedConfigSerializer());
|
||||
|
||||
return rss;
|
||||
}
|
||||
|
||||
|
@ -63,39 +63,44 @@ bool encodePostCache(std::string &str, const PostStats &s);
|
||||
bool extractPostCache(const std::string &str, PostStats &s);
|
||||
|
||||
|
||||
class p3PostBase: public RsGenExchange, public GxsTokenQueue, public RsTickEvent
|
||||
class p3PostBase: public RsGenExchange, public GxsTokenQueue, public RsTickEvent, public p3Config
|
||||
{
|
||||
public:
|
||||
public:
|
||||
|
||||
p3PostBase(RsGeneralDataService *gds, RsNetworkExchangeService *nes, RsGixs* gixs,
|
||||
RsSerialType* serviceSerialiser, uint16_t serviceType);
|
||||
RsSerialType* serviceSerialiser, uint16_t serviceType);
|
||||
|
||||
virtual void service_tick();
|
||||
virtual void service_tick();
|
||||
|
||||
protected:
|
||||
protected:
|
||||
|
||||
virtual void notifyChanges(std::vector<RsGxsNotify*>& changes);
|
||||
virtual void notifyChanges(std::vector<RsGxsNotify*>& changes);
|
||||
|
||||
// Overloaded from GxsTokenQueue for Request callbacks.
|
||||
virtual void handleResponse(uint32_t token, uint32_t req_type);
|
||||
// Overloaded from GxsTokenQueue for Request callbacks.
|
||||
virtual void handleResponse(uint32_t token, uint32_t req_type);
|
||||
|
||||
// Overloaded from RsTickEvent.
|
||||
virtual void handle_event(uint32_t event_type, const std::string &elabel);
|
||||
// Overloaded from RsTickEvent.
|
||||
virtual void handle_event(uint32_t event_type, const std::string &elabel);
|
||||
|
||||
public:
|
||||
// overloads p3Config
|
||||
virtual RsSerialiser* setupSerialiser() override; // @see p3Config::setupSerialiser()
|
||||
virtual bool saveList(bool &cleanup, std::list<RsItem *>&saveList) override; // @see p3Config::saveList(bool &cleanup, std::list<RsItem *>&)
|
||||
virtual bool loadList(std::list<RsItem *>& loadList) override; // @see p3Config::loadList(std::list<RsItem *>&)
|
||||
|
||||
//////////////////////////////////////////////////////////////////////////////
|
||||
public:
|
||||
|
||||
virtual void setMessageReadStatus(uint32_t& token, const RsGxsGrpMsgIdPair& msgId, bool read);
|
||||
//////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
virtual void setMessageReadStatus(uint32_t& token, const RsGxsGrpMsgIdPair& msgId, bool read);
|
||||
|
||||
|
||||
protected:
|
||||
protected:
|
||||
|
||||
p3GxsCommentService *mCommentService;
|
||||
|
||||
private:
|
||||
private:
|
||||
|
||||
static uint32_t postBaseAuthenPolicy();
|
||||
static uint32_t postBaseAuthenPolicy();
|
||||
|
||||
// Background processing.
|
||||
void background_tick();
|
||||
@ -120,9 +125,10 @@ static uint32_t postBaseAuthenPolicy();
|
||||
|
||||
bool mBgProcessing;
|
||||
bool mBgIncremental;
|
||||
std::list<RsGxsGroupId> mBgGroupList;
|
||||
std::map<RsGxsMessageId, PostStats> mBgStatsMap;
|
||||
std::list<RsGxsGroupId> mBgGroupList;
|
||||
std::map<RsGxsMessageId, PostStats> mBgStatsMap;
|
||||
|
||||
std::map<RsGxsGroupId,rstime_t> mKnownPosted;
|
||||
};
|
||||
|
||||
#endif
|
||||
|
Loading…
Reference in New Issue
Block a user