mirror of
https://github.com/RetroShare/RetroShare.git
synced 2025-05-20 15:00:36 -04:00
created a specific GxsEvent for Group Statistics changes and handle it in the GUI for all friends at once every 2 min at most
This commit is contained in:
parent
b7363b4d4e
commit
f74c65fcc0
13 changed files with 126 additions and 19 deletions
|
@ -1692,7 +1692,7 @@ void RsGenExchange::notifyChangedGroupStats(const RsGxsGroupId &grpId)
|
||||||
{
|
{
|
||||||
RS_STACK_MUTEX(mGenMtx);
|
RS_STACK_MUTEX(mGenMtx);
|
||||||
|
|
||||||
RsGxsGroupChange* gc = new RsGxsGroupChange(RsGxsNotify::TYPE_PROCESSED, false);
|
RsGxsGroupChange* gc = new RsGxsGroupChange(RsGxsNotify::TYPE_STATISTICS_CHANGED, false);
|
||||||
gc->mGrpIdList.push_back(grpId);
|
gc->mGrpIdList.push_back(grpId);
|
||||||
mNotifications.push_back(gc);
|
mNotifications.push_back(gc);
|
||||||
}
|
}
|
||||||
|
|
|
@ -111,6 +111,7 @@ enum class RsChannelEventCode: uint8_t
|
||||||
SUBSCRIBE_STATUS_CHANGED = 0x06, // subscription for channel mChannelGroupId changed.
|
SUBSCRIBE_STATUS_CHANGED = 0x06, // subscription for channel mChannelGroupId changed.
|
||||||
READ_STATUS_CHANGED = 0x07, // existing message has been read or set to unread
|
READ_STATUS_CHANGED = 0x07, // existing message has been read or set to unread
|
||||||
RECEIVED_DISTANT_SEARCH_RESULT = 0x08, // result for the given group id available for the given turtle request id
|
RECEIVED_DISTANT_SEARCH_RESULT = 0x08, // result for the given group id available for the given turtle request id
|
||||||
|
STATISTICS_CHANGED = 0x09, // stats (nb of supplier friends, how many msgs they have etc) has changed
|
||||||
};
|
};
|
||||||
|
|
||||||
struct RsGxsChannelEvent: RsEvent
|
struct RsGxsChannelEvent: RsEvent
|
||||||
|
|
|
@ -111,6 +111,7 @@ enum class RsForumEventCode: uint8_t
|
||||||
UPDATED_MESSAGE = 0x04, /// existing message has been updated in a particular forum
|
UPDATED_MESSAGE = 0x04, /// existing message has been updated in a particular forum
|
||||||
SUBSCRIBE_STATUS_CHANGED = 0x05, /// forum was subscribed or unsubscribed
|
SUBSCRIBE_STATUS_CHANGED = 0x05, /// forum was subscribed or unsubscribed
|
||||||
READ_STATUS_CHANGED = 0x06, /// msg was read or marked unread
|
READ_STATUS_CHANGED = 0x06, /// msg was read or marked unread
|
||||||
|
STATISTICS_CHANGED = 0x07, /// suppliers and how many messages they have changed
|
||||||
};
|
};
|
||||||
|
|
||||||
struct RsGxsForumEvent: RsEvent
|
struct RsGxsForumEvent: RsEvent
|
||||||
|
|
|
@ -46,7 +46,8 @@ struct RsGxsNotify
|
||||||
TYPE_RECEIVED_NEW = 0x02,
|
TYPE_RECEIVED_NEW = 0x02,
|
||||||
TYPE_PROCESSED = 0x03,
|
TYPE_PROCESSED = 0x03,
|
||||||
TYPE_RECEIVED_PUBLISHKEY = 0x04,
|
TYPE_RECEIVED_PUBLISHKEY = 0x04,
|
||||||
TYPE_RECEIVED_DISTANT_SEARCH_RESULTS = 0x05
|
TYPE_RECEIVED_DISTANT_SEARCH_RESULTS = 0x05,
|
||||||
|
TYPE_STATISTICS_CHANGED = 0x06
|
||||||
};
|
};
|
||||||
|
|
||||||
virtual ~RsGxsNotify() {}
|
virtual ~RsGxsNotify() {}
|
||||||
|
|
|
@ -114,6 +114,7 @@ enum class RsPostedEventCode: uint8_t
|
||||||
UPDATED_POSTED_GROUP = 0x04,
|
UPDATED_POSTED_GROUP = 0x04,
|
||||||
UPDATED_MESSAGE = 0x05,
|
UPDATED_MESSAGE = 0x05,
|
||||||
READ_STATUS_CHANGED = 0x06,
|
READ_STATUS_CHANGED = 0x06,
|
||||||
|
STATISTICS_CHANGED = 0x07,
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -302,7 +302,6 @@ void p3GxsChannels::notifyChanges(std::vector<RsGxsNotify *> &changes)
|
||||||
{
|
{
|
||||||
switch (grpChange->getType())
|
switch (grpChange->getType())
|
||||||
{
|
{
|
||||||
default:
|
|
||||||
case RsGxsNotify::TYPE_PROCESSED: // happens when the group is subscribed
|
case RsGxsNotify::TYPE_PROCESSED: // happens when the group is subscribed
|
||||||
{
|
{
|
||||||
std::list<RsGxsGroupId> &grpList = grpChange->mGrpIdList;
|
std::list<RsGxsGroupId> &grpList = grpChange->mGrpIdList;
|
||||||
|
@ -315,6 +314,20 @@ void p3GxsChannels::notifyChanges(std::vector<RsGxsNotify *> &changes)
|
||||||
rsEvents->postEvent(ev);
|
rsEvents->postEvent(ev);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
|
||||||
|
case RsGxsNotify::TYPE_STATISTICS_CHANGED:
|
||||||
|
{
|
||||||
|
std::list<RsGxsGroupId> &grpList = grpChange->mGrpIdList;
|
||||||
|
std::list<RsGxsGroupId>::iterator git;
|
||||||
|
for (git = grpList.begin(); git != grpList.end(); ++git)
|
||||||
|
{
|
||||||
|
auto ev = std::make_shared<RsGxsChannelEvent>();
|
||||||
|
ev->mChannelGroupId = *git;
|
||||||
|
ev->mChannelEventCode = RsChannelEventCode::STATISTICS_CHANGED;
|
||||||
|
rsEvents->postEvent(ev);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
|
|
||||||
|
@ -356,9 +369,14 @@ void p3GxsChannels::notifyChanges(std::vector<RsGxsNotify *> &changes)
|
||||||
|
|
||||||
rsEvents->postEvent(ev);
|
rsEvents->postEvent(ev);
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
|
||||||
|
default:
|
||||||
|
RsErr() << " Got a GXS event of type " << grpChange->getType() << " Currently not handled." << std::endl;
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
RsGxsDistantSearchResultChange *dsrChange = dynamic_cast<RsGxsDistantSearchResultChange*>(*it);
|
RsGxsDistantSearchResultChange *dsrChange = dynamic_cast<RsGxsDistantSearchResultChange*>(*it);
|
||||||
|
|
|
@ -246,7 +246,6 @@ void p3GxsForums::notifyChanges(std::vector<RsGxsNotify *> &changes)
|
||||||
{
|
{
|
||||||
switch (grpChange->getType())
|
switch (grpChange->getType())
|
||||||
{
|
{
|
||||||
default:
|
|
||||||
case RsGxsNotify::TYPE_PROCESSED: // happens when the group is subscribed
|
case RsGxsNotify::TYPE_PROCESSED: // happens when the group is subscribed
|
||||||
{
|
{
|
||||||
std::list<RsGxsGroupId> &grpList = grpChange->mGrpIdList;
|
std::list<RsGxsGroupId> &grpList = grpChange->mGrpIdList;
|
||||||
|
@ -288,8 +287,26 @@ void p3GxsForums::notifyChanges(std::vector<RsGxsNotify *> &changes)
|
||||||
<< " Not notifying already known forum "
|
<< " Not notifying already known forum "
|
||||||
<< *git << std::endl;
|
<< *git << std::endl;
|
||||||
}
|
}
|
||||||
break;
|
|
||||||
}
|
}
|
||||||
|
break;
|
||||||
|
|
||||||
|
case RsGxsNotify::TYPE_STATISTICS_CHANGED:
|
||||||
|
{
|
||||||
|
std::list<RsGxsGroupId> &grpList = grpChange->mGrpIdList;
|
||||||
|
std::list<RsGxsGroupId>::iterator git;
|
||||||
|
for (git = grpList.begin(); git != grpList.end(); ++git)
|
||||||
|
{
|
||||||
|
auto ev = std::make_shared<RsGxsForumEvent>();
|
||||||
|
ev->mForumGroupId = *git;
|
||||||
|
ev->mForumEventCode = RsForumEventCode::STATISTICS_CHANGED;
|
||||||
|
rsEvents->postEvent(ev);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
default:
|
||||||
|
RsErr() << " Got a GXS event of type " << grpChange->getType() << " Currently not handled." << std::endl;
|
||||||
|
break;
|
||||||
|
|
||||||
|
|
||||||
#ifdef NOT_USED_YET
|
#ifdef NOT_USED_YET
|
||||||
case RsGxsNotify::TYPE_RECEIVED_PUBLISHKEY:
|
case RsGxsNotify::TYPE_RECEIVED_PUBLISHKEY:
|
||||||
|
|
|
@ -134,7 +134,6 @@ void p3PostBase::notifyChanges(std::vector<RsGxsNotify *> &changes)
|
||||||
|
|
||||||
switch(grpChange->getType())
|
switch(grpChange->getType())
|
||||||
{
|
{
|
||||||
default:
|
|
||||||
case RsGxsNotify::TYPE_PROCESSED: // happens when the group is subscribed
|
case RsGxsNotify::TYPE_PROCESSED: // happens when the group is subscribed
|
||||||
{
|
{
|
||||||
std::list<RsGxsGroupId> &grpList = grpChange->mGrpIdList;
|
std::list<RsGxsGroupId> &grpList = grpChange->mGrpIdList;
|
||||||
|
@ -150,6 +149,21 @@ void p3PostBase::notifyChanges(std::vector<RsGxsNotify *> &changes)
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
|
|
||||||
|
case RsGxsNotify::TYPE_STATISTICS_CHANGED:
|
||||||
|
{
|
||||||
|
std::list<RsGxsGroupId> &grpList = grpChange->mGrpIdList;
|
||||||
|
std::list<RsGxsGroupId>::iterator git;
|
||||||
|
|
||||||
|
for (git = grpList.begin(); git != grpList.end(); ++git)
|
||||||
|
{
|
||||||
|
auto ev = std::make_shared<RsGxsPostedEvent>();
|
||||||
|
ev->mPostedGroupId = *git;
|
||||||
|
ev->mPostedEventCode = RsPostedEventCode::STATISTICS_CHANGED;
|
||||||
|
rsEvents->postEvent(ev);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
|
||||||
case RsGxsNotify::TYPE_PUBLISHED:
|
case RsGxsNotify::TYPE_PUBLISHED:
|
||||||
case RsGxsNotify::TYPE_RECEIVED_NEW:
|
case RsGxsNotify::TYPE_RECEIVED_NEW:
|
||||||
{
|
{
|
||||||
|
@ -180,6 +194,10 @@ void p3PostBase::notifyChanges(std::vector<RsGxsNotify *> &changes)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
|
|
||||||
|
default:
|
||||||
|
RsErr() << " Got a GXS event of type " << grpChange->getType() << " Currently not handled." << std::endl;
|
||||||
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -69,6 +69,11 @@ void PostedDialog::handleEvent_main_thread(std::shared_ptr<const RsEvent> event)
|
||||||
case RsPostedEventCode::SUBSCRIBE_STATUS_CHANGED: // [[fallthrough]];
|
case RsPostedEventCode::SUBSCRIBE_STATUS_CHANGED: // [[fallthrough]];
|
||||||
updateDisplay(true);
|
updateDisplay(true);
|
||||||
break;
|
break;
|
||||||
|
|
||||||
|
case RsPostedEventCode::STATISTICS_CHANGED:
|
||||||
|
updateGroupStatistics(e->mPostedGroupId);
|
||||||
|
break;
|
||||||
|
|
||||||
default: break;
|
default: break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -59,6 +59,8 @@
|
||||||
|
|
||||||
#define MAX_COMMENT_TITLE 32
|
#define MAX_COMMENT_TITLE 32
|
||||||
|
|
||||||
|
static const uint32_t DELAY_BETWEEN_GROUP_STATISTICS_UPDATE = 120; // do not update group statistics more often than once every 2 mins
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Transformation Notes:
|
* Transformation Notes:
|
||||||
* there are still a couple of things that the new groups differ from Old version.
|
* there are still a couple of things that the new groups differ from Old version.
|
||||||
|
@ -77,6 +79,8 @@ GxsGroupFrameDialog::GxsGroupFrameDialog(RsGxsIfaceHelper *ifaceImpl, QWidget *p
|
||||||
ui->setupUi(this);
|
ui->setupUi(this);
|
||||||
|
|
||||||
mShouldUpdateMessageSummaryList = true;
|
mShouldUpdateMessageSummaryList = true;
|
||||||
|
mShouldUpdateGroupStatistics = false;
|
||||||
|
mLastGroupStatisticsUpdateTs=0;
|
||||||
mInitialized = false;
|
mInitialized = false;
|
||||||
mDistSyncAllowed = allow_dist_sync;
|
mDistSyncAllowed = allow_dist_sync;
|
||||||
mInFill = false;
|
mInFill = false;
|
||||||
|
@ -204,6 +208,21 @@ void GxsGroupFrameDialog::paintEvent(QPaintEvent *pe)
|
||||||
mGroupIdsSummaryToUpdate.clear();
|
mGroupIdsSummaryToUpdate.clear();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
rstime_t now = time(nullptr);
|
||||||
|
|
||||||
|
if(mShouldUpdateGroupStatistics && now > DELAY_BETWEEN_GROUP_STATISTICS_UPDATE + mLastGroupStatisticsUpdateTs)
|
||||||
|
{
|
||||||
|
// This mechanism allows to gather multiple updateGroupStatistics events at once and not send too many of them at the same time.
|
||||||
|
// it avoids re-loadign all the group everytime a friend sends new statistics.
|
||||||
|
|
||||||
|
for(auto& groupId: mGroupStatisticsToUpdate)
|
||||||
|
updateGroupStatisticsReal(groupId);
|
||||||
|
|
||||||
|
mShouldUpdateGroupStatistics = false;
|
||||||
|
mLastGroupStatisticsUpdateTs = time(nullptr);
|
||||||
|
mGroupStatisticsToUpdate.clear();
|
||||||
|
}
|
||||||
|
|
||||||
MainPage::paintEvent(pe);
|
MainPage::paintEvent(pe);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1106,6 +1125,12 @@ void GxsGroupFrameDialog::updateGroupSummary()
|
||||||
/*********************** **** **** **** ***********************/
|
/*********************** **** **** **** ***********************/
|
||||||
|
|
||||||
void GxsGroupFrameDialog::updateGroupStatistics(const RsGxsGroupId &groupId)
|
void GxsGroupFrameDialog::updateGroupStatistics(const RsGxsGroupId &groupId)
|
||||||
|
{
|
||||||
|
mGroupStatisticsToUpdate.insert(groupId);
|
||||||
|
mShouldUpdateGroupStatistics = true;
|
||||||
|
}
|
||||||
|
|
||||||
|
void GxsGroupFrameDialog::updateGroupStatisticsReal(const RsGxsGroupId &groupId)
|
||||||
{
|
{
|
||||||
RsThread::async([this,groupId]()
|
RsThread::async([this,groupId]()
|
||||||
{
|
{
|
||||||
|
|
|
@ -104,6 +104,11 @@ protected:
|
||||||
|
|
||||||
virtual bool getGroupData(std::list<RsGxsGenericGroupData*>& groupInfo) =0;
|
virtual bool getGroupData(std::list<RsGxsGenericGroupData*>& groupInfo) =0;
|
||||||
virtual bool getGroupStatistics(const RsGxsGroupId& groupId,GxsGroupStatistic& stat) =0;
|
virtual bool getGroupStatistics(const RsGxsGroupId& groupId,GxsGroupStatistic& stat) =0;
|
||||||
|
|
||||||
|
private:
|
||||||
|
void updateGroupStatisticsReal(const RsGxsGroupId &groupId);
|
||||||
|
void updateMessageSummaryListReal(RsGxsGroupId groupId);
|
||||||
|
|
||||||
private slots:
|
private slots:
|
||||||
void todo();
|
void todo();
|
||||||
|
|
||||||
|
@ -161,7 +166,6 @@ private:
|
||||||
|
|
||||||
void initUi();
|
void initUi();
|
||||||
|
|
||||||
void updateMessageSummaryListReal(RsGxsGroupId groupId);
|
|
||||||
void openGroupInNewTab(const RsGxsGroupId &groupId);
|
void openGroupInNewTab(const RsGxsGroupId &groupId);
|
||||||
void groupSubscribe(bool subscribe);
|
void groupSubscribe(bool subscribe);
|
||||||
|
|
||||||
|
@ -205,9 +209,16 @@ private:
|
||||||
RsGxsGroupId mNavigatePendingGroupId;
|
RsGxsGroupId mNavigatePendingGroupId;
|
||||||
RsGxsMessageId mNavigatePendingMsgId;
|
RsGxsMessageId mNavigatePendingMsgId;
|
||||||
|
|
||||||
|
// Message summary list update
|
||||||
|
|
||||||
bool mShouldUpdateMessageSummaryList ; // whether we should update the counting for groups. This takes some CPU so we only do it when needed.
|
bool mShouldUpdateMessageSummaryList ; // whether we should update the counting for groups. This takes some CPU so we only do it when needed.
|
||||||
std::set<RsGxsGroupId> mGroupIdsSummaryToUpdate;
|
std::set<RsGxsGroupId> mGroupIdsSummaryToUpdate;
|
||||||
|
|
||||||
|
// GroupStatistics update
|
||||||
|
bool mShouldUpdateGroupStatistics;
|
||||||
|
rstime_t mLastGroupStatisticsUpdateTs;
|
||||||
|
std::set<RsGxsGroupId> mGroupStatisticsToUpdate;
|
||||||
|
|
||||||
UIStateHelper *mStateHelper;
|
UIStateHelper *mStateHelper;
|
||||||
|
|
||||||
/** Qt Designer generated object */
|
/** Qt Designer generated object */
|
||||||
|
|
|
@ -80,6 +80,10 @@ void GxsChannelDialog::handleEvent_main_thread(std::shared_ptr<const RsEvent> ev
|
||||||
updateDisplay(true);
|
updateDisplay(true);
|
||||||
break;
|
break;
|
||||||
|
|
||||||
|
case RsChannelEventCode::STATISTICS_CHANGED:
|
||||||
|
updateGroupStatistics(e->mChannelGroupId);
|
||||||
|
break;
|
||||||
|
|
||||||
default:
|
default:
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
|
@ -69,6 +69,11 @@ void GxsForumsDialog::handleEvent_main_thread(std::shared_ptr<const RsEvent> eve
|
||||||
case RsForumEventCode::SUBSCRIBE_STATUS_CHANGED:
|
case RsForumEventCode::SUBSCRIBE_STATUS_CHANGED:
|
||||||
updateDisplay(true);
|
updateDisplay(true);
|
||||||
break;
|
break;
|
||||||
|
|
||||||
|
case RsForumEventCode::STATISTICS_CHANGED:
|
||||||
|
updateGroupStatistics(e->mForumGroupId);
|
||||||
|
break;
|
||||||
|
|
||||||
default:
|
default:
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue