mirror of
https://github.com/RetroShare/RetroShare.git
synced 2025-07-28 08:54:13 -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
|
@ -69,6 +69,11 @@ void PostedDialog::handleEvent_main_thread(std::shared_ptr<const RsEvent> event)
|
|||
case RsPostedEventCode::SUBSCRIBE_STATUS_CHANGED: // [[fallthrough]];
|
||||
updateDisplay(true);
|
||||
break;
|
||||
|
||||
case RsPostedEventCode::STATISTICS_CHANGED:
|
||||
updateGroupStatistics(e->mPostedGroupId);
|
||||
break;
|
||||
|
||||
default: break;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -59,6 +59,8 @@
|
|||
|
||||
#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:
|
||||
* 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);
|
||||
|
||||
mShouldUpdateMessageSummaryList = true;
|
||||
mShouldUpdateGroupStatistics = false;
|
||||
mLastGroupStatisticsUpdateTs=0;
|
||||
mInitialized = false;
|
||||
mDistSyncAllowed = allow_dist_sync;
|
||||
mInFill = false;
|
||||
|
@ -204,6 +208,21 @@ void GxsGroupFrameDialog::paintEvent(QPaintEvent *pe)
|
|||
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);
|
||||
}
|
||||
|
||||
|
@ -1106,6 +1125,12 @@ void GxsGroupFrameDialog::updateGroupSummary()
|
|||
/*********************** **** **** **** ***********************/
|
||||
|
||||
void GxsGroupFrameDialog::updateGroupStatistics(const RsGxsGroupId &groupId)
|
||||
{
|
||||
mGroupStatisticsToUpdate.insert(groupId);
|
||||
mShouldUpdateGroupStatistics = true;
|
||||
}
|
||||
|
||||
void GxsGroupFrameDialog::updateGroupStatisticsReal(const RsGxsGroupId &groupId)
|
||||
{
|
||||
RsThread::async([this,groupId]()
|
||||
{
|
||||
|
|
|
@ -104,6 +104,11 @@ protected:
|
|||
|
||||
virtual bool getGroupData(std::list<RsGxsGenericGroupData*>& groupInfo) =0;
|
||||
virtual bool getGroupStatistics(const RsGxsGroupId& groupId,GxsGroupStatistic& stat) =0;
|
||||
|
||||
private:
|
||||
void updateGroupStatisticsReal(const RsGxsGroupId &groupId);
|
||||
void updateMessageSummaryListReal(RsGxsGroupId groupId);
|
||||
|
||||
private slots:
|
||||
void todo();
|
||||
|
||||
|
@ -161,7 +166,6 @@ private:
|
|||
|
||||
void initUi();
|
||||
|
||||
void updateMessageSummaryListReal(RsGxsGroupId groupId);
|
||||
void openGroupInNewTab(const RsGxsGroupId &groupId);
|
||||
void groupSubscribe(bool subscribe);
|
||||
|
||||
|
@ -205,9 +209,16 @@ private:
|
|||
RsGxsGroupId mNavigatePendingGroupId;
|
||||
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.
|
||||
std::set<RsGxsGroupId> mGroupIdsSummaryToUpdate;
|
||||
|
||||
// GroupStatistics update
|
||||
bool mShouldUpdateGroupStatistics;
|
||||
rstime_t mLastGroupStatisticsUpdateTs;
|
||||
std::set<RsGxsGroupId> mGroupStatisticsToUpdate;
|
||||
|
||||
UIStateHelper *mStateHelper;
|
||||
|
||||
/** Qt Designer generated object */
|
||||
|
|
|
@ -80,6 +80,10 @@ void GxsChannelDialog::handleEvent_main_thread(std::shared_ptr<const RsEvent> ev
|
|||
updateDisplay(true);
|
||||
break;
|
||||
|
||||
case RsChannelEventCode::STATISTICS_CHANGED:
|
||||
updateGroupStatistics(e->mChannelGroupId);
|
||||
break;
|
||||
|
||||
default:
|
||||
break;
|
||||
}
|
||||
|
|
|
@ -69,6 +69,11 @@ void GxsForumsDialog::handleEvent_main_thread(std::shared_ptr<const RsEvent> eve
|
|||
case RsForumEventCode::SUBSCRIBE_STATUS_CHANGED:
|
||||
updateDisplay(true);
|
||||
break;
|
||||
|
||||
case RsForumEventCode::STATISTICS_CHANGED:
|
||||
updateGroupStatistics(e->mForumGroupId);
|
||||
break;
|
||||
|
||||
default:
|
||||
break;
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue