- Added two new members to GxsGroupStatistic/GxsServiceStatistic - mNumMsgsNew, mNumMsgsUnread

- Set mGrpId on GxsGroupStatistic
- Changed GxsUserNotify and GxsGroupFrameDialog to statistics

git-svn-id: http://svn.code.sf.net/p/retroshare/code/trunk@7462 b45a01b8-16f6-495d-af2f-9b41ad6348cc
This commit is contained in:
thunder2 2014-07-20 19:35:33 +00:00
parent 5399618cef
commit 9c3266fdd9
6 changed files with 50 additions and 102 deletions

View File

@ -1460,12 +1460,25 @@ bool RsGxsDataAccess::getGroupStatistic(GroupStatisticRequest *req)
std::vector<RsGxsMsgMetaData*>& msgMetaV = metaResult[req->mGrpId];
req->mGroupStatistic.mGrpId = req->mGrpId;
req->mGroupStatistic.mNumMsgs = msgMetaV.size();
req->mGroupStatistic.mTotalSizeOfMsgs = 0;
req->mGroupStatistic.mNumMsgsNew = 0;
req->mGroupStatistic.mNumMsgsUnread = 0;
for(int i = 0; i < msgMetaV.size(); i++)
{
RsGxsMsgMetaData* m = msgMetaV[i];
req->mGroupStatistic.mTotalSizeOfMsgs += m->mMsgSize + m->serial_size();
if (IS_MSG_NEW(m->mMsgStatus))
{
++req->mGroupStatistic.mNumMsgsNew;
}
if (IS_MSG_UNREAD(m->mMsgStatus))
{
++req->mGroupStatistic.mNumMsgsUnread;
}
}
cleanseMsgMetaMap(metaResult);
@ -1485,6 +1498,8 @@ bool RsGxsDataAccess::getServiceStatistic(ServiceStatisticRequest *req)
req->mServiceStatistic.mSizeOfGrps = 0;
req->mServiceStatistic.mSizeOfMsgs = 0;
req->mServiceStatistic.mNumGrpsSubscribed = 0;
req->mServiceStatistic.mNumMsgsNew = 0;
req->mServiceStatistic.mNumMsgsUnread = 0;
for(; mit != grpMeta.end(); mit++)
{
@ -1496,6 +1511,8 @@ bool RsGxsDataAccess::getServiceStatistic(ServiceStatisticRequest *req)
req->mServiceStatistic.mNumMsgs += gr.mGroupStatistic.mNumMsgs;
req->mServiceStatistic.mSizeOfMsgs += gr.mGroupStatistic.mTotalSizeOfMsgs;
req->mServiceStatistic.mNumGrpsSubscribed += m->mSubscribeFlags & GXS_SERV::GROUP_SUBSCRIBE_SUBSCRIBED ? 1 : 0;
req->mServiceStatistic.mNumMsgsNew += gr.mGroupStatistic.mNumMsgsNew;
req->mServiceStatistic.mNumMsgsUnread += gr.mGroupStatistic.mNumMsgsUnread;
delete m;
}

View File

@ -139,6 +139,8 @@ public:
RsGxsGroupId mGrpId;
uint32_t mNumMsgs;
uint32_t mTotalSizeOfMsgs;
uint32_t mNumMsgsNew;
uint32_t mNumMsgsUnread;
};
class GxsServiceStatistic
@ -150,6 +152,8 @@ public:
uint32_t mSizeOfMsgs;
uint32_t mSizeOfGrps;
uint32_t mNumGrpsSubscribed;
uint32_t mNumMsgsNew;
uint32_t mNumMsgsUnread;
uint32_t mSizeStore;
};

View File

@ -82,6 +82,7 @@ GxsGroupFrameDialog::GxsGroupFrameDialog(RsGxsIfaceHelper *ifaceImpl, QWidget *p
/* Setup Queue */
mInterface = ifaceImpl;
mTokenService = mInterface->getTokenService();
mTokenQueue = new TokenQueue(mInterface->getTokenService(), this);
/* Setup UI helper */
@ -203,8 +204,13 @@ void GxsGroupFrameDialog::updateDisplay(bool complete)
/* Update group list */
requestGroupSummary();
} else {
if (!getMsgIds().empty() || !getMsgIdsMeta().empty()) {
updateMessageSummaryList(RsGxsGroupId());
/* Update all groups of changed messages */
std::map<RsGxsGroupId, std::vector<RsGxsMessageId> > msgIds;
getAllMsgIds(msgIds);
std::map<RsGxsGroupId, std::vector<RsGxsMessageId> >::iterator msgIt;
for (msgIt = msgIds.begin(); msgIt != msgIds.end(); ++msgIt) {
updateMessageSummaryList(msgIt->first);
}
}
}
@ -745,8 +751,6 @@ void GxsGroupFrameDialog::updateMessageSummaryList(RsGxsGroupId groupId)
return;
}
std::list<RsGxsGroupId> groupIds;
if (groupId.isNull()) {
QTreeWidgetItem *items[2] = { mYourGroups, mSubscribedGroups };
for (int item = 0; item < 2; item++) {
@ -759,14 +763,12 @@ void GxsGroupFrameDialog::updateMessageSummaryList(RsGxsGroupId groupId)
continue;
}
groupIds.push_back(RsGxsGroupId(childId.toLatin1().constData()));
requestGroupStatistics(RsGxsGroupId(childId.toLatin1().constData()));
}
}
} else {
groupIds.push_back(groupId);
requestGroupStatistics(groupId);
}
requestGroupStatistics(groupIds);
}
/*********************** **** **** **** ***********************/
@ -878,48 +880,24 @@ void GxsGroupFrameDialog::loadGroupSummary(const uint32_t &token)
/*********************** **** **** **** ***********************/
/*********************** **** **** **** ***********************/
void GxsGroupFrameDialog::requestGroupStatistics(const std::list<RsGxsGroupId> &groupIds)
void GxsGroupFrameDialog::requestGroupStatistics(const RsGxsGroupId &groupId)
{
// uint32_t token;
// GxsServiceStatistic stats;
// mInterface->getGroupStatistic(token, stats);
// TokenQueue->queueRequest(token, 0, RS_TOKREQ_ANSTYPE_ACK, TOKEN_TYPE_STATISTICS);
mTokenQueue->cancelActiveRequestTokens(TOKEN_TYPE_STATISTICS);
RsTokReqOptions opts;
opts.mReqType = GXS_REQUEST_TYPE_MSG_META;
uint32_t token;
mTokenQueue->requestMsgInfo(token, RS_TOKREQ_ANSTYPE_DATA, opts, groupIds, TOKEN_TYPE_STATISTICS);
mTokenService->requestGroupStatistic(token, groupId);
mTokenQueue->queueRequest(token, 0, RS_TOKREQ_ANSTYPE_ACK, TOKEN_TYPE_STATISTICS);
}
void GxsGroupFrameDialog::loadGroupStatistics(const uint32_t &token)
{
GxsMsgMetaMap msgList;
mInterface->getMsgSummary(token, msgList);
GxsGroupStatistic stats;
mInterface->getGroupStatistic(token, stats);
GxsMsgMetaMap::const_iterator groupIt;
for (groupIt = msgList.begin(); groupIt != msgList.end(); ++groupIt) {
const RsGxsGroupId &groupId = groupIt->first;
QTreeWidgetItem *item = ui->groupTreeWidget->getItemFromId(QString::fromStdString(groupId.toStdString()));
if (!item) {
continue;
}
const std::vector<RsMsgMetaData> &groupData = groupIt->second;
unsigned int newCount = 0;
std::vector<RsMsgMetaData>::const_iterator msgIt;
for (msgIt = groupData.begin(); msgIt != groupData.end(); ++msgIt) {
const RsMsgMetaData &metaData = *msgIt;
if (IS_MSG_NEW(metaData.mMsgStatus) || IS_MSG_UNREAD(metaData.mMsgStatus)) {
++newCount;
}
}
ui->groupTreeWidget->setUnreadCount(item, newCount);
QTreeWidgetItem *item = ui->groupTreeWidget->getItemFromId(QString::fromStdString(stats.mGrpId.toStdString()));
if (!item) {
return;
}
ui->groupTreeWidget->setUnreadCount(item, stats.mNumMsgsUnread);
}
/*********************** **** **** **** ***********************/

View File

@ -148,7 +148,7 @@ private:
void requestGroupSummary();
void loadGroupSummary(const uint32_t &token);
void requestGroupStatistics(const std::list<RsGxsGroupId> &groupIds);
void requestGroupStatistics(const RsGxsGroupId &groupId);
void loadGroupStatistics(const uint32_t &token);
// subscribe/unsubscribe ack.
@ -167,6 +167,7 @@ private:
QString mSettingsName;
RsGxsGroupId mGroupId;
RsGxsIfaceHelper *mInterface;
RsTokenService *mTokenService;
TokenQueue *mTokenQueue;
GxsMessageFrameWidget *mMessageWidget;

View File

@ -25,7 +25,6 @@
#include "retroshare/rsgxsifacehelper.h"
#define TOKEN_TYPE_STATISTICS 1
#define TOKEN_TYPE_GROUP_META 2
GxsUserNotify::GxsUserNotify(RsGxsIfaceHelper *ifaceImpl, QObject *parent) :
UserNotify(parent), TokenResponse()
@ -33,6 +32,7 @@ GxsUserNotify::GxsUserNotify(RsGxsIfaceHelper *ifaceImpl, QObject *parent) :
mNewMessageCount = 0;
mInterface = ifaceImpl;
mTokenService = mInterface->getTokenService();
mTokenQueue = new TokenQueue(mInterface->getTokenService(), this);
mBase = new RsGxsUpdateBroadcastBase(ifaceImpl);
@ -51,22 +51,11 @@ GxsUserNotify::~GxsUserNotify()
void GxsUserNotify::startUpdate()
{
// uint32_t token;
// GxsServiceStatistic stats;
// mInterface->getServiceStatistic(token, stats);
// TokenQueue->queueRequest(token, 0, RS_TOKREQ_ANSTYPE_ACK, TOKEN_TYPE_STATISTICS);
mNewMessageCount = 0;
/* Get all messages until statistics are available */
mTokenQueue->cancelActiveRequestTokens(TOKEN_TYPE_GROUP_META);
mTokenQueue->cancelActiveRequestTokens(TOKEN_TYPE_STATISTICS);
RsTokReqOptions opts;
opts.mReqType = GXS_REQUEST_TYPE_GROUP_META;
uint32_t token;
mTokenQueue->requestGroupInfo(token, RS_TOKREQ_ANSTYPE_DATA, opts, TOKEN_TYPE_GROUP_META);
mTokenService->requestServiceStatistic(token);
mTokenQueue->queueRequest(token, 0, RS_TOKREQ_ANSTYPE_ACK, TOKEN_TYPE_STATISTICS);
}
void GxsUserNotify::loadRequest(const TokenQueue *queue, const TokenRequest &req)
@ -76,56 +65,14 @@ void GxsUserNotify::loadRequest(const TokenQueue *queue, const TokenRequest &req
switch(req.mUserType) {
case TOKEN_TYPE_STATISTICS:
{
GxsMsgMetaMap msgList;
mInterface->getMsgSummary(req.mToken, msgList);
GxsServiceStatistic stats;
mInterface->getServiceStatistic(req.mToken, stats);
GxsMsgMetaMap::const_iterator groupIt;
for (groupIt = msgList.begin(); groupIt != msgList.end(); ++groupIt) {
const std::vector<RsMsgMetaData> &groupData = groupIt->second;
std::vector<RsMsgMetaData>::const_iterator msgIt;
for (msgIt = groupData.begin(); msgIt != groupData.end(); ++msgIt) {
const RsMsgMetaData &metaData = *msgIt;
if (IS_MSG_NEW(metaData.mMsgStatus)) {
++mNewMessageCount;
}
}
}
mNewMessageCount = stats.mNumMsgsNew;
update();
}
break;
case TOKEN_TYPE_GROUP_META:
{
std::list<RsGroupMetaData> groupMeta;
mInterface->getGroupSummary(req.mToken, groupMeta);
if (!groupMeta.size()) {
update();
return;
}
std::list<RsGxsGroupId> groupIds;
std::list<RsGroupMetaData>::const_iterator groupIt;
for (groupIt = groupMeta.begin(); groupIt != groupMeta.end(); groupIt++) {
uint32_t flags = groupIt->mSubscribeFlags;
if (IS_GROUP_SUBSCRIBED(flags)) {
groupIds.push_back(groupIt->mGroupId);
}
}
if (!groupIds.size()) {
update();
return;
}
RsTokReqOptions opts;
opts.mReqType = GXS_REQUEST_TYPE_MSG_META;
uint32_t token;
mTokenQueue->requestMsgInfo(token, RS_TOKREQ_ANSTYPE_DATA, opts, groupIds, TOKEN_TYPE_STATISTICS);
}
break;
}
}
}

View File

@ -48,6 +48,7 @@ private:
private:
RsGxsIfaceHelper *mInterface;
RsTokenService *mTokenService;
TokenQueue *mTokenQueue;
RsGxsUpdateBroadcastBase *mBase;
unsigned int mNewMessageCount;