diff --git a/libretroshare/src/retroshare/rsgxsifacetypes.h b/libretroshare/src/retroshare/rsgxsifacetypes.h index 5d3942d7f..90715dfcb 100644 --- a/libretroshare/src/retroshare/rsgxsifacetypes.h +++ b/libretroshare/src/retroshare/rsgxsifacetypes.h @@ -239,7 +239,7 @@ public: mNumChildMsgsNew = 0; mNumChildMsgsUnread = 0; mSizeStore = 0; - } + } public: uint32_t mNumMsgs; diff --git a/retroshare-gui/src/gui/Posted/PostedDialog.cpp b/retroshare-gui/src/gui/Posted/PostedDialog.cpp index cbf7426d9..b6da6024e 100644 --- a/retroshare-gui/src/gui/Posted/PostedDialog.cpp +++ b/retroshare-gui/src/gui/Posted/PostedDialog.cpp @@ -82,7 +82,7 @@ PostedDialog::~PostedDialog() UserNotify *PostedDialog::createUserNotify(QObject *parent) { - return new PostedUserNotify(rsPosted, parent); + return new PostedUserNotify(rsPosted, this, parent); } QString PostedDialog::getHelpString() const diff --git a/retroshare-gui/src/gui/Posted/PostedUserNotify.cpp b/retroshare-gui/src/gui/Posted/PostedUserNotify.cpp index 5e7d75040..ed7343557 100644 --- a/retroshare-gui/src/gui/Posted/PostedUserNotify.cpp +++ b/retroshare-gui/src/gui/Posted/PostedUserNotify.cpp @@ -22,8 +22,8 @@ #include "PostedUserNotify.h" #include "gui/MainWindow.h" -PostedUserNotify::PostedUserNotify(RsGxsIfaceHelper *ifaceImpl, QObject *parent) : - GxsUserNotify(ifaceImpl, parent) +PostedUserNotify::PostedUserNotify(RsGxsIfaceHelper *ifaceImpl, const GxsGroupFrameDialog *g, QObject *parent) : + GxsUserNotify(ifaceImpl, g, parent) { } @@ -34,10 +34,6 @@ bool PostedUserNotify::hasSetting(QString *name, QString *group) return true; } -bool PostedUserNotify::getServiceStatistics(GxsServiceStatistic& stat) -{ - return rsPosted->getBoardsServiceStatistics(stat); -} QIcon PostedUserNotify::getIcon() { diff --git a/retroshare-gui/src/gui/Posted/PostedUserNotify.h b/retroshare-gui/src/gui/Posted/PostedUserNotify.h index 8fd4ccdf9..2c12ac889 100644 --- a/retroshare-gui/src/gui/Posted/PostedUserNotify.h +++ b/retroshare-gui/src/gui/Posted/PostedUserNotify.h @@ -28,10 +28,9 @@ class PostedUserNotify : public GxsUserNotify Q_OBJECT public: - PostedUserNotify(RsGxsIfaceHelper *ifaceImpl, QObject *parent = 0); + PostedUserNotify(RsGxsIfaceHelper *ifaceImpl, const GxsGroupFrameDialog *g, QObject *parent = 0); virtual bool hasSetting(QString *name, QString *group); - virtual bool getServiceStatistics(GxsServiceStatistic& stat) override; private: virtual QIcon getIcon(); diff --git a/retroshare-gui/src/gui/gxs/GxsGroupFrameDialog.cpp b/retroshare-gui/src/gui/gxs/GxsGroupFrameDialog.cpp index 47300b83e..4d7c92c7f 100644 --- a/retroshare-gui/src/gui/gxs/GxsGroupFrameDialog.cpp +++ b/retroshare-gui/src/gui/gxs/GxsGroupFrameDialog.cpp @@ -1116,7 +1116,7 @@ void GxsGroupFrameDialog::updateGroupStatistics(const RsGxsGroupId &groupId) return; } - RsQThreadUtils::postToObject( [this,stats]() + RsQThreadUtils::postToObject( [this,stats, groupId]() { /* Here it goes any code you want to be executed on the Qt Gui * thread, for example to update the data model with new information @@ -1129,6 +1129,7 @@ void GxsGroupFrameDialog::updateGroupStatistics(const RsGxsGroupId &groupId) return; ui->groupTreeWidget->setUnreadCount(item, mCountChildMsgs ? (stats.mNumThreadMsgsUnread + stats.mNumChildMsgsUnread) : stats.mNumThreadMsgsUnread); + mCachedGroupStats[groupId] = stats; getUserNotify()->updateIcon(); @@ -1136,6 +1137,23 @@ void GxsGroupFrameDialog::updateGroupStatistics(const RsGxsGroupId &groupId) }); } +void GxsGroupFrameDialog::getServiceStatistics(GxsServiceStatistic& stats) const +{ + stats = GxsServiceStatistic(); // clears everything + + for(auto it: mCachedGroupStats) + { + const GxsGroupStatistic& s(it.second); + + stats.mNumMsgs += s.mNumMsgs; + stats.mNumGrps += 1; + stats.mSizeOfMsgs += s.mTotalSizeOfMsgs; + stats.mNumThreadMsgsNew += s.mNumThreadMsgsNew; + stats.mNumThreadMsgsUnread += s.mNumThreadMsgsUnread; + stats.mNumChildMsgsNew += s.mNumChildMsgsNew ; + stats.mNumChildMsgsUnread += s.mNumChildMsgsUnread ; + } +} TurtleRequestId GxsGroupFrameDialog::distantSearch(const QString& search_string) // this should be overloaded in the child class { diff --git a/retroshare-gui/src/gui/gxs/GxsGroupFrameDialog.h b/retroshare-gui/src/gui/gxs/GxsGroupFrameDialog.h index b34edc457..ba7581542 100644 --- a/retroshare-gui/src/gui/gxs/GxsGroupFrameDialog.h +++ b/retroshare-gui/src/gui/gxs/GxsGroupFrameDialog.h @@ -29,7 +29,6 @@ #include -#include "util/TokenQueue.h" #include "GxsIdTreeWidgetItem.h" #include "GxsGroupDialog.h" @@ -80,6 +79,8 @@ public: virtual void getGroupList(std::map &groups) ; + void getServiceStatistics(GxsServiceStatistic& stats) const ; + protected: virtual void showEvent(QShowEvent *event) override; virtual void paintEvent(QPaintEvent *pe) override; @@ -175,20 +176,13 @@ private: virtual uint32_t requestGroupSummaryType() { return GXS_REQUEST_TYPE_GROUP_META; } // request only meta data - void requestGroupStatistics(const RsGxsGroupId &groupId); - void loadGroupStatistics(const uint32_t &token); - // subscribe/unsubscribe ack. -// void acknowledgeSubscribeChange(const uint32_t &token); GxsMessageFrameWidget *messageWidget(const RsGxsGroupId &groupId, bool ownTab); GxsMessageFrameWidget *createMessageWidget(const RsGxsGroupId &groupId); GxsCommentDialog *commentWidget(const RsGxsMessageId &msgId); -// void requestGroupSummary_CurrentGroup(const RsGxsGroupId &groupId); -// void loadGroupSummary_CurrentGroup(const uint32_t &token); - protected: void updateSearchResults(); @@ -220,6 +214,7 @@ private: Ui::GxsGroupFrameDialog *ui; std::map mCachedGroupMetas; + std::map mCachedGroupStats; std::map mSearchGroupsItems ; std::map > mKnownGroups; diff --git a/retroshare-gui/src/gui/gxs/GxsUserNotify.cpp b/retroshare-gui/src/gui/gxs/GxsUserNotify.cpp index b6ebc89af..bc1afa1c1 100644 --- a/retroshare-gui/src/gui/gxs/GxsUserNotify.cpp +++ b/retroshare-gui/src/gui/gxs/GxsUserNotify.cpp @@ -26,7 +26,7 @@ #define TOKEN_TYPE_STATISTICS 1 -GxsUserNotify::GxsUserNotify(RsGxsIfaceHelper *ifaceImpl, QObject *parent) : UserNotify(parent) +GxsUserNotify::GxsUserNotify(RsGxsIfaceHelper *ifaceImpl, const GxsGroupFrameDialog *g,QObject *parent) : UserNotify(parent), mGroupFrameDialog(g) { mNewThreadMessageCount = 0; mNewChildMessageCount = 0; @@ -40,32 +40,17 @@ void GxsUserNotify::startUpdate() mNewThreadMessageCount = 0; mNewChildMessageCount = 0; - RsThread::async([this]() - { - // 1 - get message data from p3GxsForums -#ifdef DEBUG_FORUMS - std::cerr << "Retrieving post data for post " << mThreadId << std::endl; -#endif + GxsServiceStatistic stats; + mGroupFrameDialog->getServiceStatistics(stats); - GxsServiceStatistic stats; - - if(!getServiceStatistics(stats)) - return; - - RsQThreadUtils::postToObject( [stats,this]() - { - /* Here it goes any code you want to be executed on the Qt Gui + /* Here it goes any code you want to be executed on the Qt Gui * thread, for example to update the data model with new information * after a blocking call to RetroShare API complete */ - mNewThreadMessageCount = stats.mNumThreadMsgsNew; - mNewChildMessageCount = stats.mNumChildMsgsNew; + mNewThreadMessageCount = stats.mNumThreadMsgsNew; + mNewChildMessageCount = stats.mNumChildMsgsNew; - update(); - - }, this ); - - }); + update(); } diff --git a/retroshare-gui/src/gui/gxs/GxsUserNotify.h b/retroshare-gui/src/gui/gxs/GxsUserNotify.h index cc1cd3809..f9c5cd616 100644 --- a/retroshare-gui/src/gui/gxs/GxsUserNotify.h +++ b/retroshare-gui/src/gui/gxs/GxsUserNotify.h @@ -23,6 +23,7 @@ #include #include "gui/common/UserNotify.h" +#include "gui/gxs/GxsGroupFrameDialog.h" #include "util/TokenQueue.h" struct RsGxsIfaceHelper; @@ -33,12 +34,11 @@ class GxsUserNotify : public UserNotify Q_OBJECT public: - GxsUserNotify(RsGxsIfaceHelper *ifaceImpl, QObject *parent = 0); + GxsUserNotify(RsGxsIfaceHelper *ifaceImpl, const GxsGroupFrameDialog *g, QObject *parent = 0); virtual ~GxsUserNotify(); protected: virtual void startUpdate(); - virtual bool getServiceStatistics(GxsServiceStatistic& stat)=0; private: virtual unsigned int getNewCount() { return mCountChildMsgs ? (mNewThreadMessageCount + mNewChildMessageCount) : mNewThreadMessageCount; } @@ -48,6 +48,8 @@ protected: private: RsGxsUpdateBroadcastBase *mBase; + const GxsGroupFrameDialog *mGroupFrameDialog; + unsigned int mNewThreadMessageCount; unsigned int mNewChildMessageCount; }; diff --git a/retroshare-gui/src/gui/gxschannels/GxsChannelDialog.cpp b/retroshare-gui/src/gui/gxschannels/GxsChannelDialog.cpp index 395c9db31..9c3afc945 100644 --- a/retroshare-gui/src/gui/gxschannels/GxsChannelDialog.cpp +++ b/retroshare-gui/src/gui/gxschannels/GxsChannelDialog.cpp @@ -109,7 +109,7 @@ QString GxsChannelDialog::getHelpString() const UserNotify *GxsChannelDialog::createUserNotify(QObject *parent) { - return new GxsChannelUserNotify(rsGxsChannels, parent); + return new GxsChannelUserNotify(rsGxsChannels,this, parent); } void GxsChannelDialog::shareOnChannel(const RsGxsGroupId& channel_id,const QList& file_links) diff --git a/retroshare-gui/src/gui/gxschannels/GxsChannelUserNotify.cpp b/retroshare-gui/src/gui/gxschannels/GxsChannelUserNotify.cpp index 3e5212476..eb54a39c3 100644 --- a/retroshare-gui/src/gui/gxschannels/GxsChannelUserNotify.cpp +++ b/retroshare-gui/src/gui/gxschannels/GxsChannelUserNotify.cpp @@ -22,8 +22,8 @@ #include "GxsChannelUserNotify.h" #include "gui/MainWindow.h" -GxsChannelUserNotify::GxsChannelUserNotify(RsGxsIfaceHelper *ifaceImpl, QObject *parent) : - GxsUserNotify(ifaceImpl, parent) +GxsChannelUserNotify::GxsChannelUserNotify(RsGxsIfaceHelper *ifaceImpl, const GxsGroupFrameDialog *g, QObject *parent) : + GxsUserNotify(ifaceImpl, g, parent) { } @@ -35,11 +35,6 @@ bool GxsChannelUserNotify::hasSetting(QString *name, QString *group) return true; } -bool GxsChannelUserNotify::getServiceStatistics(GxsServiceStatistic& stat) -{ - return rsGxsChannels->getChannelServiceStatistics(stat); -} - QIcon GxsChannelUserNotify::getIcon() { return QIcon(":/icons/png/channel.png"); diff --git a/retroshare-gui/src/gui/gxschannels/GxsChannelUserNotify.h b/retroshare-gui/src/gui/gxschannels/GxsChannelUserNotify.h index d69848aba..df29a0202 100644 --- a/retroshare-gui/src/gui/gxschannels/GxsChannelUserNotify.h +++ b/retroshare-gui/src/gui/gxschannels/GxsChannelUserNotify.h @@ -22,16 +22,16 @@ #define GXSCHANNELUSERNOTIFY_H #include "gui/gxs/GxsUserNotify.h" +#include "gui/gxs/GxsGroupFrameDialog.h" class GxsChannelUserNotify : public GxsUserNotify { Q_OBJECT public: - GxsChannelUserNotify(RsGxsIfaceHelper *ifaceImpl, QObject *parent = 0); + GxsChannelUserNotify(RsGxsIfaceHelper *ifaceImpl, const GxsGroupFrameDialog *g, QObject *parent = 0); virtual bool hasSetting(QString *name, QString *group); - virtual bool getServiceStatistics(GxsServiceStatistic& stat) override; private: virtual QIcon getIcon(); diff --git a/retroshare-gui/src/gui/gxsforums/GxsForumUserNotify.cpp b/retroshare-gui/src/gui/gxsforums/GxsForumUserNotify.cpp index 8c07e2099..876aa3a95 100644 --- a/retroshare-gui/src/gui/gxsforums/GxsForumUserNotify.cpp +++ b/retroshare-gui/src/gui/gxsforums/GxsForumUserNotify.cpp @@ -22,8 +22,8 @@ #include "GxsForumUserNotify.h" #include "gui/MainWindow.h" -GxsForumUserNotify::GxsForumUserNotify(RsGxsIfaceHelper *ifaceImpl, QObject *parent) : - GxsUserNotify(ifaceImpl, parent) +GxsForumUserNotify::GxsForumUserNotify(RsGxsIfaceHelper *ifaceImpl, const GxsGroupFrameDialog *g, QObject *parent) : + GxsUserNotify(ifaceImpl, g, parent) { mCountChildMsgs = true; } @@ -35,10 +35,6 @@ bool GxsForumUserNotify::hasSetting(QString *name, QString *group) return true; } -bool GxsForumUserNotify::getServiceStatistics(GxsServiceStatistic& stat) -{ - return rsGxsForums->getForumServiceStatistics(stat); -} QIcon GxsForumUserNotify::getIcon() { diff --git a/retroshare-gui/src/gui/gxsforums/GxsForumUserNotify.h b/retroshare-gui/src/gui/gxsforums/GxsForumUserNotify.h index bc97550de..172a327ae 100644 --- a/retroshare-gui/src/gui/gxsforums/GxsForumUserNotify.h +++ b/retroshare-gui/src/gui/gxsforums/GxsForumUserNotify.h @@ -28,8 +28,7 @@ class GxsForumUserNotify : public GxsUserNotify Q_OBJECT public: - GxsForumUserNotify(RsGxsIfaceHelper *ifaceImpl, QObject *parent = 0); - virtual bool getServiceStatistics(GxsServiceStatistic& stat) override; + GxsForumUserNotify(RsGxsIfaceHelper *ifaceImpl, const GxsGroupFrameDialog *g, QObject *parent = 0); virtual bool hasSetting(QString *name, QString *group); diff --git a/retroshare-gui/src/gui/gxsforums/GxsForumsDialog.cpp b/retroshare-gui/src/gui/gxsforums/GxsForumsDialog.cpp index d8d300dde..e8b7f7d3d 100644 --- a/retroshare-gui/src/gui/gxsforums/GxsForumsDialog.cpp +++ b/retroshare-gui/src/gui/gxsforums/GxsForumsDialog.cpp @@ -133,7 +133,7 @@ void GxsForumsDialog::shareInMessage(const RsGxsGroupId& forum_id,const QList