diff --git a/libretroshare/src/gxs/rsgxsdataaccess.cc b/libretroshare/src/gxs/rsgxsdataaccess.cc index 2be2aeab4..1a4e1a86b 100644 --- a/libretroshare/src/gxs/rsgxsdataaccess.cc +++ b/libretroshare/src/gxs/rsgxsdataaccess.cc @@ -1460,12 +1460,25 @@ bool RsGxsDataAccess::getGroupStatistic(GroupStatisticRequest *req) std::vector& 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; } diff --git a/libretroshare/src/retroshare/rsgxsifacetypes.h b/libretroshare/src/retroshare/rsgxsifacetypes.h index 5334fd57c..87f474ada 100644 --- a/libretroshare/src/retroshare/rsgxsifacetypes.h +++ b/libretroshare/src/retroshare/rsgxsifacetypes.h @@ -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; }; diff --git a/retroshare-gui/src/gui/gxs/GxsGroupFrameDialog.cpp b/retroshare-gui/src/gui/gxs/GxsGroupFrameDialog.cpp index 7e86f5ed4..6ba47e9f4 100644 --- a/retroshare-gui/src/gui/gxs/GxsGroupFrameDialog.cpp +++ b/retroshare-gui/src/gui/gxs/GxsGroupFrameDialog.cpp @@ -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 > msgIds; + getAllMsgIds(msgIds); + + std::map >::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 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 &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 &groupData = groupIt->second; - - unsigned int newCount = 0; - std::vector::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); } /*********************** **** **** **** ***********************/ diff --git a/retroshare-gui/src/gui/gxs/GxsGroupFrameDialog.h b/retroshare-gui/src/gui/gxs/GxsGroupFrameDialog.h index 892be3f95..f3242fdd5 100644 --- a/retroshare-gui/src/gui/gxs/GxsGroupFrameDialog.h +++ b/retroshare-gui/src/gui/gxs/GxsGroupFrameDialog.h @@ -148,7 +148,7 @@ private: void requestGroupSummary(); void loadGroupSummary(const uint32_t &token); - void requestGroupStatistics(const std::list &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; diff --git a/retroshare-gui/src/gui/gxs/GxsUserNotify.cpp b/retroshare-gui/src/gui/gxs/GxsUserNotify.cpp index d8e9e1a85..e1f88a620 100644 --- a/retroshare-gui/src/gui/gxs/GxsUserNotify.cpp +++ b/retroshare-gui/src/gui/gxs/GxsUserNotify.cpp @@ -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 &groupData = groupIt->second; - - std::vector::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 groupMeta; - mInterface->getGroupSummary(req.mToken, groupMeta); - - if (!groupMeta.size()) { - update(); - return; - } - - std::list groupIds; - std::list::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; } } } diff --git a/retroshare-gui/src/gui/gxs/GxsUserNotify.h b/retroshare-gui/src/gui/gxs/GxsUserNotify.h index 8c42da20e..1ac7d8ff5 100644 --- a/retroshare-gui/src/gui/gxs/GxsUserNotify.h +++ b/retroshare-gui/src/gui/gxs/GxsUserNotify.h @@ -48,6 +48,7 @@ private: private: RsGxsIfaceHelper *mInterface; + RsTokenService *mTokenService; TokenQueue *mTokenQueue; RsGxsUpdateBroadcastBase *mBase; unsigned int mNewMessageCount;