diff --git a/libretroshare/src/retroshare/rsgxschannels.h b/libretroshare/src/retroshare/rsgxschannels.h index 0134ada9c..a506e66e5 100644 --- a/libretroshare/src/retroshare/rsgxschannels.h +++ b/libretroshare/src/retroshare/rsgxschannels.h @@ -68,12 +68,10 @@ struct RsGxsChannelGroup : RsSerializable, RsGxsGenericGroupData ~RsGxsChannelGroup() override; }; -struct RsGxsChannelPost : RsSerializable +struct RsGxsChannelPost : RsSerializable, RsGxsGenericMsgData { RsGxsChannelPost() : mCount(0), mSize(0) {} - RsMsgMetaData mMeta; - std::set mOlderVersions; std::string mMsg; // UTF8 encoded. diff --git a/libretroshare/src/retroshare/rsgxsifacehelper.h b/libretroshare/src/retroshare/rsgxsifacehelper.h index 2a9b5bba3..01716c35c 100644 --- a/libretroshare/src/retroshare/rsgxsifacehelper.h +++ b/libretroshare/src/retroshare/rsgxsifacehelper.h @@ -43,11 +43,12 @@ enum class TokenRequestType: uint8_t { GROUP_INFO = 0x01, - MSG_INFO = 0x02, - MSG_RELATED_INFO = 0x03, - GROUP_STATISTICS = 0x04, - SERVICE_STATISTICS = 0x05, - NO_KILL_TYPE = 0x06, + POSTS = 0x02, + ALL_POSTS = 0x03, + MSG_RELATED_INFO = 0x04, + GROUP_STATISTICS = 0x05, + SERVICE_STATISTICS = 0x06, + NO_KILL_TYPE = 0x07, }; class RsGxsIfaceHelper @@ -278,13 +279,12 @@ public: } /// @see RsTokenService::requestMsgInfo - bool requestMsgInfo( uint32_t& token, - const RsTokReqOptions& opts, const GxsMsgReq& msgIds ) + bool requestMsgInfo( uint32_t& token, const RsTokReqOptions& opts, const GxsMsgReq& msgIds ) { if(mTokenService.requestMsgInfo(token, 0, opts, msgIds)) { RS_STACK_MUTEX(mMtx); - mActiveTokens[token]=TokenRequestType::MSG_INFO; + mActiveTokens[token]= msgIds.empty()?(TokenRequestType::ALL_POSTS):(TokenRequestType::POSTS); locked_dumpTokens(); return true; } @@ -298,7 +298,7 @@ public: if(mTokenService.requestMsgInfo(token, 0, opts, grpIds)) { RS_STACK_MUTEX(mMtx); - mActiveTokens[token]=TokenRequestType::MSG_INFO; + mActiveTokens[token]=TokenRequestType::ALL_POSTS; locked_dumpTokens(); return true; } diff --git a/libretroshare/src/retroshare/rsgxsifacetypes.h b/libretroshare/src/retroshare/rsgxsifacetypes.h index 36b224c01..60111d0cc 100644 --- a/libretroshare/src/retroshare/rsgxsifacetypes.h +++ b/libretroshare/src/retroshare/rsgxsifacetypes.h @@ -184,6 +184,14 @@ struct RsMsgMetaData : RsSerializable } }; +struct RsGxsGenericMsgData +{ + virtual ~RsGxsGenericMsgData() = default; // making the type polymorphic + + RsMsgMetaData mMeta; +}; + + class GxsGroupStatistic { public: diff --git a/libretroshare/src/retroshare/rsposted.h b/libretroshare/src/retroshare/rsposted.h index 11f7ac643..c2a069002 100644 --- a/libretroshare/src/retroshare/rsposted.h +++ b/libretroshare/src/retroshare/rsposted.h @@ -46,14 +46,13 @@ struct RsPostedGroup: RsGxsGenericGroupData RsGxsImage mGroupImage; }; -struct RsPostedPost +struct RsPostedPost: public RsGxsGenericMsgData { RsPostedPost(): mHaveVoted(false), mUpVotes(0), mDownVotes(0), mComments(0), mHotScore(0), mTopScore(0), mNewScore(0) {} bool calculateScores(rstime_t ref_time); - RsMsgMetaData mMeta; std::string mLink; std::string mNotes; diff --git a/retroshare-gui/src/gui/Posted/PostedListWidget.cpp b/retroshare-gui/src/gui/Posted/PostedListWidget.cpp index a35490028..b8d214eb5 100644 --- a/retroshare-gui/src/gui/Posted/PostedListWidget.cpp +++ b/retroshare-gui/src/gui/Posted/PostedListWidget.cpp @@ -885,30 +885,16 @@ void PostedListWidget::shallowClearPosts() } } -bool PostedListWidget::insertGroupData(const uint32_t &token, RsGroupMetaData &metaData) +bool PostedListWidget::insertGroupData(const RsGxsGenericGroupData *data) { - std::vector groups; - rsPosted->getGroupData(token, groups); - - if (groups.size() == 1) - { - insertPostedDetails(groups[0]); - metaData = groups[0].mMeta; - return true; - } - - return false; + insertPostedDetails(*dynamic_cast(data)); } -void PostedListWidget::insertAllPosts(const uint32_t &token, GxsMessageFramePostThread */*thread*/) +void PostedListWidget::insertAllPostedPosts(const std::vector& posts, GxsMessageFramePostThread */*thread*/) { - std::vector posts; - rsPosted->getPostData(token, posts); - - std::vector::iterator vit; - for(vit = posts.begin(); vit != posts.end(); ++vit) + for(auto vit = posts.begin(); vit != posts.end(); ++vit) { - RsPostedPost& p = *vit; + const RsPostedPost& p = *vit; loadPost(p); loadPostCardView(p); } @@ -916,15 +902,11 @@ void PostedListWidget::insertAllPosts(const uint32_t &token, GxsMessageFramePost applyRanking(); } -void PostedListWidget::insertPosts(const uint32_t &token) +void PostedListWidget::insertPostedPosts(const std::vector& posts) { - std::vector posts; - rsPosted->getPostData(token, posts); - - std::vector::iterator vit; - for(vit = posts.begin(); vit != posts.end(); ++vit) + for(auto vit = posts.begin(); vit != posts.end(); ++vit) { - RsPostedPost& p = *vit; + const RsPostedPost& p = *vit; // modify post content if(mPosts.find(p.mMeta.mMsgId) != mPosts.end()) @@ -1047,3 +1029,68 @@ void PostedListWidget::setViewMode(int viewMode) return; } } + +void PostedListWidget::getMsgData(const std::set& msgIds,std::vector& psts) +{ + std::vector posts; + std::vector comments; + + rsPosted->getBoardContent( groupId(),msgIds,posts,comments ); + + psts.clear(); + + for(auto& post: posts) + psts.push_back(new RsPostedPost(post)); +} + +void PostedListWidget::getAllMsgData(std::vector& psts) +{ + std::vector posts; + std::vector comments; + + rsPosted->getBoardContent( groupId(),std::set(),posts,comments ); + + psts.clear(); + + for(auto& post: posts) + psts.push_back(new RsPostedPost(post)); +} + +bool PostedListWidget::getGroupData(RsGxsGenericGroupData*& data) +{ + std::vector groupInfo ; + data = nullptr; + + if(! rsPosted->getBoardsInfo(std::list({groupId()}),groupInfo) || groupInfo.size() != 1) + return false; + + data = new RsPostedGroup(groupInfo[0]); + return true; +} + +void PostedListWidget::insertPosts(const std::vector& posts) +{ + std::vector cposts; + + for(auto post: posts) // This is not so nice but we have somehow to convert to RsGxsChannelPost at some timer, and the cposts list is being modified in the insert method. + { + cposts.push_back(*dynamic_cast(post)); + delete post; + } + + insertPostedPosts(cposts); +} + +void PostedListWidget::insertAllPosts(const std::vector& posts, GxsMessageFramePostThread *thread) +{ + std::vector cposts; + + for(auto post: posts) // This is not so nice but we have somehow to convert to RsGxsChannelPost at some timer, and the cposts list is being modified in the insert method. + { + cposts.push_back(*dynamic_cast(post)); + delete post; + } + + insertAllPostedPosts(cposts, NULL); +} + diff --git a/retroshare-gui/src/gui/Posted/PostedListWidget.h b/retroshare-gui/src/gui/Posted/PostedListWidget.h index 6e9a89bae..06e60493d 100644 --- a/retroshare-gui/src/gui/Posted/PostedListWidget.h +++ b/retroshare-gui/src/gui/Posted/PostedListWidget.h @@ -58,15 +58,22 @@ public: protected: void handleEvent_main_thread(std::shared_ptr event); + void insertAllPostedPosts(const std::vector& posts, GxsMessageFramePostThread *thread) ; + void insertPostedPosts(const std::vector& posts); /* GxsMessageFramePostWidget */ - virtual bool insertGroupData(const uint32_t &token, RsGroupMetaData &metaData); - virtual void insertAllPosts(const uint32_t &token, GxsMessageFramePostThread *thread); - virtual void insertPosts(const uint32_t &token); virtual void clearPosts(); virtual void blank(); virtual bool navigatePostItem(const RsGxsMessageId& msgId); + virtual void getMsgData(const std::set& msgIds,std::vector& posts) override; + virtual void getAllMsgData(std::vector& posts) override; + virtual bool getGroupData(RsGxsGenericGroupData*& data) override; + + virtual bool insertGroupData(const RsGxsGenericGroupData *data) override; + virtual void insertPosts(const std::vector& posts) override; + virtual void insertAllPosts(const std::vector& posts, GxsMessageFramePostThread *thread) override; + /* GxsMessageFrameWidget */ virtual void setAllMessagesReadDo(bool read, uint32_t &token); diff --git a/retroshare-gui/src/gui/gxs/GxsGroupDialog.cpp b/retroshare-gui/src/gui/gxs/GxsGroupDialog.cpp index 30a4e6578..62e1101c9 100644 --- a/retroshare-gui/src/gui/gxs/GxsGroupDialog.cpp +++ b/retroshare-gui/src/gui/gxs/GxsGroupDialog.cpp @@ -1009,53 +1009,3 @@ void GxsGroupDialog::loadGroup(const RsGxsGroupId& grpId) }); } -#ifdef TO_REMOVE -void GxsGroupDialog::requestGroup(const RsGxsGroupId &groupId) -{ - RsTokReqOptions opts; - opts.mReqType = GXS_REQUEST_TYPE_GROUP_DATA; - - std::list groupIds; - groupIds.push_back(groupId); - - std::cerr << "GxsGroupDialog::requestGroup() Requesting Group Summary(" << groupId << ")"; - std::cerr << std::endl; - - uint32_t token; - if (mInternalTokenQueue) - mInternalTokenQueue->requestGroupInfo(token, RS_TOKREQ_ANSTYPE_DATA, opts, groupIds, GXSGROUP_INTERNAL_LOADGROUP) ; -} - -void GxsGroupDialog::loadGroup(uint32_t token) -{ - std::cerr << "GxsGroupDialog::loadGroup(" << token << ")"; - std::cerr << std::endl; - - QString description; - if (service_loadGroup(token, mMode, mGrpMeta, description)) - { - updateFromExistingMeta(description); - } -} - -void GxsGroupDialog::loadRequest(const TokenQueue *queue, const TokenRequest &req) -{ - std::cerr << "GxsGroupDialog::loadRequest() UserType: " << req.mUserType; - std::cerr << std::endl; - - if (queue == mInternalTokenQueue) - { - /* now switch on req */ - switch(req.mUserType) - { - case GXSGROUP_INTERNAL_LOADGROUP: - loadGroup(req.mToken); - break; - default: - std::cerr << "GxsGroupDialog::loadGroup() UNKNOWN UserType "; - std::cerr << std::endl; - break; - } - } -} -#endif diff --git a/retroshare-gui/src/gui/gxs/GxsGroupFrameDialog.cpp b/retroshare-gui/src/gui/gxs/GxsGroupFrameDialog.cpp index 244676b6c..be580e965 100644 --- a/retroshare-gui/src/gui/gxs/GxsGroupFrameDialog.cpp +++ b/retroshare-gui/src/gui/gxs/GxsGroupFrameDialog.cpp @@ -1068,99 +1068,6 @@ void GxsGroupFrameDialog::updateGroupSummary() }); } -#ifdef TO_REMOVE -void GxsGroupFrameDialog::requestGroupSummary() -{ - mStateHelper->setLoading(TOKEN_TYPE_GROUP_SUMMARY, true); - -#ifdef DEBUG_GROUPFRAMEDIALOG - std::cerr << "GxsGroupFrameDialog::requestGroupSummary()"; - std::cerr << std::endl; -#endif - - mTokenQueue->cancelActiveRequestTokens(TOKEN_TYPE_GROUP_SUMMARY); - - RsTokReqOptions opts; - opts.mReqType = requestGroupSummaryType(); - - uint32_t token; - mTokenQueue->requestGroupInfo(token, RS_TOKREQ_ANSTYPE_SUMMARY, opts, TOKEN_TYPE_GROUP_SUMMARY); -} - -void GxsGroupFrameDialog::loadGroupSummaryToken(const uint32_t &token, std::list &groupInfo, RsUserdata *&/*userdata*/) -{ - /* Default implementation for request type GXS_REQUEST_TYPE_GROUP_META */ - mInterface->getGroupSummary(token, groupInfo); -} - -void GxsGroupFrameDialog::loadGroupSummary(const std::list& groupInfo) -{ -#ifdef DEBUG_GROUPFRAMEDIALOG - std::cerr << "GxsGroupFrameDialog::loadGroupSummary()"; - std::cerr << std::endl; -#endif - - -} - -/*********************** **** **** **** ***********************/ -/*********************** **** **** **** ***********************/ - -//void GxsGroupFrameDialog::acknowledgeSubscribeChange(const uint32_t &token) -//{ -//#ifdef DEBUG_GROUPFRAMEDIALOG -// std::cerr << "GxsGroupFrameDialog::acknowledgeSubscribeChange()"; -// std::cerr << std::endl; -//#endif - -// RsGxsGroupId groupId; -// mInterface->acknowledgeGrp(token, groupId); - -// fillComplete(); -//} - -/*********************** **** **** **** ***********************/ -/*********************** **** **** **** ***********************/ - -//void GxsGroupFrameDialog::requestGroupSummary_CurrentGroup(const RsGxsGroupId &groupId) -//{ -// RsTokReqOptions opts; -// opts.mReqType = GXS_REQUEST_TYPE_GROUP_META; - -// std::list grpIds; -// grpIds.push_back(groupId); - -// std::cerr << "GxsGroupFrameDialog::requestGroupSummary_CurrentGroup(" << groupId << ")"; -// std::cerr << std::endl; - -// uint32_t token; -// mInteface->requestGroupInfo(token, RS_TOKREQ_ANSTYPE_SUMMARY, opts, grpIds, TOKEN_TYPE_CURRENTGROUP); -//} - -//void GxsGroupFrameDialog::loadGroupSummary_CurrentGroup(const uint32_t &token) -//{ -// std::cerr << "GxsGroupFrameDialog::loadGroupSummary_CurrentGroup()"; -// std::cerr << std::endl; - -// std::list groupInfo; -// rsGxsForums->getGroupSummary(token, groupInfo); - -// if (groupInfo.size() == 1) -// { -// RsGroupMetaData fi = groupInfo.front(); -// mSubscribeFlags = fi.mSubscribeFlags; -// } -// else -// { -// resetData(); -// std::cerr << "GxsGroupFrameDialog::loadGroupSummary_CurrentGroup() ERROR Invalid Number of Groups..."; -// std::cerr << std::endl; -// } - -// setValid(true); -//} -#endif - /*********************** **** **** **** ***********************/ /*********************** **** **** **** ***********************/ diff --git a/retroshare-gui/src/gui/gxs/GxsMessageFramePostWidget.cpp b/retroshare-gui/src/gui/gxs/GxsMessageFramePostWidget.cpp index 4be7db243..587e607f9 100644 --- a/retroshare-gui/src/gui/gxs/GxsMessageFramePostWidget.cpp +++ b/retroshare-gui/src/gui/gxs/GxsMessageFramePostWidget.cpp @@ -25,6 +25,7 @@ #include "gui/common/UIStateHelper.h" #include "retroshare/rsgxsifacehelper.h" +#include "util/qtthreadsutils.h" //#define ENABLE_DEBUG 1 @@ -98,8 +99,8 @@ void GxsMessageFramePostWidget::updateDisplay(bool complete) { if (complete) { /* Fill complete */ - requestGroupData(); - requestAllPosts(); + loadGroupData(); + loadAllPosts(); return; } @@ -162,6 +163,7 @@ void GxsMessageFramePostWidget::fillThreadFinished() /** Request / Response of Data ********************************/ /**************************************************************/ +#ifdef TO_REMOVE void GxsMessageFramePostWidget::requestGroupData() { #ifdef ENABLE_DEBUG @@ -230,7 +232,72 @@ void GxsMessageFramePostWidget::loadGroupData(const uint32_t &token) emit groupChanged(this); } +#endif +void GxsMessageFramePostWidget::loadGroupData() +{ + mSubscribeFlags = 0; + + mTokenQueue->cancelActiveRequestTokens(mTokenTypeGroupData); + + if (groupId().isNull()) { + mStateHelper->setActive(mTokenTypeGroupData, false); + mStateHelper->setLoading(mTokenTypeGroupData, false); + mStateHelper->clear(mTokenTypeGroupData); + + mGroupName.clear(); + groupNameChanged(mGroupName); + + emit groupChanged(this); + + return; + } + + mStateHelper->setLoading(mTokenTypeGroupData, true); + emit groupChanged(this); + + RsThread::async([this]() + { + RsGxsGenericGroupData *data; + getGroupData(data); + + RsQThreadUtils::postToObject( [data,this]() + { + /* 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 */ + + bool ok = insertGroupData(data); + + mStateHelper->setLoading(mTokenTypeGroupData, false); + + if (ok) { + mSubscribeFlags = data->mMeta.mSubscribeFlags; + + mGroupName = QString::fromUtf8(data->mMeta.mGroupName.c_str()); + groupNameChanged(mGroupName); + } else { + std::cerr << "GxsMessageFramePostWidget::loadGroupData() ERROR Not just one Group"; + std::cerr << std::endl; + + mStateHelper->clear(mTokenTypeGroupData); + + mGroupName.clear(); + groupNameChanged(mGroupName); + } + + mStateHelper->setActive(mTokenTypeGroupData, ok); + + emit groupChanged(this); + + delete data; + + }, this ); + }); + +} + +#ifdef TO_REMOVE void GxsMessageFramePostWidget::requestAllPosts() { #ifdef ENABLE_DEBUG @@ -313,8 +380,142 @@ void GxsMessageFramePostWidget::loadAllPosts(const uint32_t &token) emit groupChanged(this); } +#endif -void GxsMessageFramePostWidget::requestPosts(const std::set &msgIds) +void GxsMessageFramePostWidget::loadAllPosts() +{ + mNavigatePendingMsgId.clear(); + + /* Request all posts */ + + mTokenQueue->cancelActiveRequestTokens(mTokenTypeAllPosts); + + if (mFillThread) { + /* Stop current fill thread */ + GxsMessageFramePostThread *thread = mFillThread; + mFillThread = NULL; + thread->stop(false); + + mStateHelper->setLoading(mTokenTypeAllPosts, false); + } + + clearPosts(); + + if (groupId().isNull()) { + mStateHelper->setActive(mTokenTypeAllPosts, false); + mStateHelper->setLoading(mTokenTypeAllPosts, false); + mStateHelper->clear(mTokenTypeAllPosts); + emit groupChanged(this); + return; + } + + mStateHelper->setLoading(mTokenTypeAllPosts, true); + emit groupChanged(this); + + RsThread::async([this]() + { + std::vector posts; + getAllMsgData(posts); + + RsQThreadUtils::postToObject( [posts,this]() + { + /* 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 */ + + mStateHelper->setActive(mTokenTypeAllPosts, true); + + if (useThread()) { + /* Create fill thread */ + mFillThread = new GxsMessageFramePostThread(posts,this); + + // connect thread + connect(mFillThread, SIGNAL(finished()), this, SLOT(fillThreadFinished()), Qt::BlockingQueuedConnection); + connect(mFillThread, SIGNAL(addPost(QVariant,bool,int,int)), this, SLOT(fillThreadAddPost(QVariant,bool,int,int)), Qt::BlockingQueuedConnection); + +#ifdef ENABLE_DEBUG + std::cerr << "GxsMessageFramePostWidget::loadAllPosts() Start fill thread" << std::endl; +#endif + + /* Start thread */ + mFillThread->start(); + } + else + { + insertAllPosts(posts, NULL); + + mStateHelper->setLoading(mTokenTypeAllPosts, false); + + if (!mNavigatePendingMsgId.isNull()) + { + navigate(mNavigatePendingMsgId); + + mNavigatePendingMsgId.clear(); + } + + // don't forget to delete the posts + + for(auto& ppost:posts) + delete ppost; + } + + emit groupChanged(this); + + }, this ); + }); + +} + +void GxsMessageFramePostWidget::loadPosts(const std::set& msgIds) +{ + mNavigatePendingMsgId.clear(); + + if (groupId().isNull()) + { + mStateHelper->setActive(mTokenTypePosts, false); + mStateHelper->setLoading(mTokenTypePosts, false); + mStateHelper->clear(mTokenTypePosts); + emit groupChanged(this); + return; + } + + if (msgIds.empty()) + return; + + mStateHelper->setLoading(mTokenTypePosts, true); + emit groupChanged(this); + + RsThread::async([this,msgIds]() + { + std::vector posts; + + getMsgData(msgIds,posts); + + RsQThreadUtils::postToObject( [posts,this]() + { + /* 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 */ + + mStateHelper->setActive(mTokenTypePosts, true); + + insertPosts(posts); + + mStateHelper->setLoading(mTokenTypePosts, false); + emit groupChanged(this); + + if (!mNavigatePendingMsgId.isNull()) + { + navigate(mNavigatePendingMsgId); + + mNavigatePendingMsgId.clear(); + } + }, this ); + }); +} + +#ifdef TO_REMOVE +void GxsMessageFramePostWidget::requestPosts(const std::set& msgIds) { #ifdef ENABLE_DEBUG std::cerr << "GxsMessageFramePostWidget::requestPosts()"; @@ -397,13 +598,14 @@ void GxsMessageFramePostWidget::loadRequest(const TokenQueue *queue, const Token GxsMessageFrameWidget::loadRequest(queue, req); } +#endif /**************************************************************/ /** GxsMessageFramePostThread *********************************/ /**************************************************************/ -GxsMessageFramePostThread::GxsMessageFramePostThread(uint32_t token, GxsMessageFramePostWidget *parent) - : QThread(parent), mToken(token), mParent(parent) +GxsMessageFramePostThread::GxsMessageFramePostThread(const std::vector& posts,GxsMessageFramePostWidget *parent) + : mPosts(posts),QThread(parent), mParent(parent) { mStopped = false; } @@ -417,9 +619,9 @@ GxsMessageFramePostThread::~GxsMessageFramePostThread() void GxsMessageFramePostThread::stop(bool waitForStop) { - if (waitForStop) { + if (waitForStop) disconnect(); - } + mStopped = true; QApplication::processEvents(); @@ -435,7 +637,12 @@ void GxsMessageFramePostThread::run() std::cerr << "GxsMessageFramePostThread::run()" << std::endl; #endif - mParent->insertAllPosts(mToken, this); + mParent->insertAllPosts(mPosts,this); + + for(auto& ppost:mPosts) + delete ppost; + + mPosts.clear(); // dont keep deleted pointers #ifdef ENABLE_DEBUG std::cerr << "GxsMessageFramePostThread::run() stopped: " << (stopped() ? "yes" : "no") << std::endl; diff --git a/retroshare-gui/src/gui/gxs/GxsMessageFramePostWidget.h b/retroshare-gui/src/gui/gxs/GxsMessageFramePostWidget.h index 231134d13..e43edcfa8 100644 --- a/retroshare-gui/src/gui/gxs/GxsMessageFramePostWidget.h +++ b/retroshare-gui/src/gui/gxs/GxsMessageFramePostWidget.h @@ -40,12 +40,16 @@ public: /* GxsMessageFrameWidget */ virtual void groupIdChanged(); virtual QString groupName(bool withUnreadCount); -// virtual QIcon groupIcon() = 0; virtual bool navigate(const RsGxsMessageId& msgId); virtual bool isLoading(); + // These should be derived in subclasses + virtual bool getGroupData(RsGxsGenericGroupData *& data) =0; + virtual void getMsgData(const std::set& msgIds,std::vector& posts) =0; + virtual void getAllMsgData(std::vector& posts) =0; + /* GXS functions */ - virtual void loadRequest(const TokenQueue *queue, const TokenRequest &req); +// virtual void loadRequest(const TokenQueue *queue, const TokenRequest &req); int subscribeFlags() { return mSubscribeFlags; } @@ -65,16 +69,21 @@ protected: /* GXS functions */ void requestGroupData(); - void loadGroupData(const uint32_t &token); - virtual bool insertGroupData(const uint32_t &token, RsGroupMetaData &metaData) = 0; + void loadGroupData(); + void loadAllPosts(); + void loadPosts(const std::set& msgIds); +#ifdef TO_REMOVE void requestAllPosts(); - void loadAllPosts(const uint32_t &token); + void loadAllPosts(); virtual void insertAllPosts(const uint32_t &token, GxsMessageFramePostThread *thread) = 0; - void requestPosts(const std::set &msgIds); - void loadPosts(const uint32_t &token); - virtual void insertPosts(const uint32_t &token) = 0; + //void requestPosts(const std::set &msgIds); + //void loadPosts(const uint32_t &token); +#endif + virtual bool insertGroupData(const RsGxsGenericGroupData *data) =0; + virtual void insertPosts(const std::vector& posts) =0; + virtual void insertAllPosts(const std::vector& posts, GxsMessageFramePostThread *thread) =0; private slots: void fillThreadFinished(); @@ -97,7 +106,7 @@ class GxsMessageFramePostThread : public QThread Q_OBJECT public: - GxsMessageFramePostThread(uint32_t token, GxsMessageFramePostWidget *parent); + GxsMessageFramePostThread(const std::vector& posts,GxsMessageFramePostWidget *parent); ~GxsMessageFramePostThread(); void run(); @@ -110,7 +119,7 @@ signals: void addPost(const QVariant &post, bool related, int current, int count); private: - uint32_t mToken; + std::vector mPosts; GxsMessageFramePostWidget *mParent; volatile bool mStopped; }; diff --git a/retroshare-gui/src/gui/gxschannels/GxsChannelPostsWidget.cpp b/retroshare-gui/src/gui/gxschannels/GxsChannelPostsWidget.cpp index 32f9f78cc..b21ad2d2c 100644 --- a/retroshare-gui/src/gui/gxschannels/GxsChannelPostsWidget.cpp +++ b/retroshare-gui/src/gui/gxschannels/GxsChannelPostsWidget.cpp @@ -506,7 +506,7 @@ void GxsChannelPostsWidget::fillThreadCreatePost(const QVariant &post, bool rela createPostItem(post.value(), related); } -void GxsChannelPostsWidget::insertChannelPosts(std::vector &posts, GxsMessageFramePostThread *thread, bool related) +void GxsChannelPostsWidget::insertChannelPosts(std::vector& posts, GxsMessageFramePostThread *thread, bool related) { if (related && thread) { std::cerr << "GxsChannelPostsWidget::insertChannelPosts fill only related posts as thread is not possible" << std::endl; @@ -734,25 +734,67 @@ void GxsChannelPostsWidget::toggleAutoDownload() }); } -bool GxsChannelPostsWidget::insertGroupData(const uint32_t &token, RsGroupMetaData &metaData) +bool GxsChannelPostsWidget::insertGroupData(const RsGxsGenericGroupData *data) { - std::vector groups; - rsGxsChannels->getGroupData(token, groups); + insertChannelDetails(*dynamic_cast(data)); + mChannelGroupId = data->mMeta.mGroupId; + return true; - if(groups.size() == 1) - { - insertChannelDetails(groups[0]); - metaData = groups[0].mMeta; - mChannelGroupId = groups[0].mMeta.mGroupId; - return true; - } +} + +#ifdef TO_REMOVE +void GxsChannelPostsWidget::insertAllPosts(const uint32_t &token, GxsMessageFramePostThread *thread) +{ + std::vector posts; + rsGxsChannels->getPostData(token, posts); + + insertChannelPosts(posts, thread, false); +} +#endif + +void GxsChannelPostsWidget::getMsgData(const std::set& msgIds,std::vector& psts) +{ + std::vector posts; + std::vector comments; + + rsGxsChannels->getChannelContent( mChannelGroupId,msgIds,posts,comments ); + + psts.clear(); + + for(auto& post: posts) + psts.push_back(new RsGxsChannelPost(post)); +} + +void GxsChannelPostsWidget::getAllMsgData(std::vector& psts) +{ + std::vector posts; + std::vector comments; + + rsGxsChannels->getChannelContent( mChannelGroupId,std::set(),posts,comments ); + + psts.clear(); + + for(auto& post: posts) + psts.push_back(new RsGxsChannelPost(post)); +} + +bool GxsChannelPostsWidget::getGroupData(RsGxsGenericGroupData *& data) +{ + std::vector groups; + + if(rsGxsChannels->getChannelsInfo(std::list({groupId()}),groups) && groups.size()==1) + { + data = new RsGxsChannelGroup(groups[0]); + return true; + } else { RsGxsChannelGroup distant_group; + if(rsGxsChannels->retrieveDistantGroup(groupId(),distant_group)) { insertChannelDetails(distant_group); - metaData = distant_group.mMeta; + data = new RsGxsChannelGroup(distant_group); mChannelGroupId = distant_group.mMeta.mGroupId; return true ; } @@ -761,14 +803,32 @@ bool GxsChannelPostsWidget::insertGroupData(const uint32_t &token, RsGroupMetaDa return false; } -void GxsChannelPostsWidget::insertAllPosts(const uint32_t &token, GxsMessageFramePostThread *thread) +void GxsChannelPostsWidget::insertAllPosts(const std::vector& posts, GxsMessageFramePostThread *thread) { - std::vector posts; - rsGxsChannels->getPostData(token, posts); + std::vector cposts; - insertChannelPosts(posts, thread, false); + for(auto post: posts) // This is not so nice but we have somehow to convert to RsGxsChannelPost at some timer, and the cposts list is being modified in the insert method. + { + cposts.push_back(*dynamic_cast(post)); + delete post; + } + + insertChannelPosts(cposts, thread, false); +} +void GxsChannelPostsWidget::insertPosts(const std::vector& posts) +{ + std::vector cposts; + + for(auto post: posts) // This is not so nice but we have somehow to convert to RsGxsChannelPost at some timer, and the cposts list is being modified in the insert method. + { + cposts.push_back(*dynamic_cast(post)); + delete post; + } + + insertChannelPosts(cposts, NULL, true); } +#ifdef TO_REMOVE void GxsChannelPostsWidget::insertPosts(const uint32_t &token) { std::vector posts; @@ -776,6 +836,7 @@ void GxsChannelPostsWidget::insertPosts(const uint32_t &token) insertChannelPosts(posts, NULL, true); } +#endif class GxsChannelPostsReadData { diff --git a/retroshare-gui/src/gui/gxschannels/GxsChannelPostsWidget.h b/retroshare-gui/src/gui/gxschannels/GxsChannelPostsWidget.h index 6f27ed677..1b93f1531 100644 --- a/retroshare-gui/src/gui/gxschannels/GxsChannelPostsWidget.h +++ b/retroshare-gui/src/gui/gxschannels/GxsChannelPostsWidget.h @@ -65,7 +65,7 @@ public: protected: /* GxsMessageFramePostWidget */ virtual void groupNameChanged(const QString &name); - virtual bool insertGroupData(const uint32_t &token, RsGroupMetaData &metaData); + virtual bool insertGroupData(const RsGxsGenericGroupData *data) override; virtual void insertAllPosts(const uint32_t &token, GxsMessageFramePostThread *thread); virtual void insertPosts(const uint32_t &token); virtual void clearPosts(); @@ -74,6 +74,12 @@ protected: virtual bool navigatePostItem(const RsGxsMessageId& msgId); virtual void blank() ; + virtual bool getGroupData(RsGxsGenericGroupData *& data) override; + virtual void getMsgData(const std::set& msgIds,std::vector& posts) override; + virtual void getAllMsgData(std::vector& posts) override; + virtual void insertPosts(const std::vector& posts) override; + virtual void insertAllPosts(const std::vector& posts, GxsMessageFramePostThread *thread) override; + /* GxsMessageFrameWidget */ virtual void setAllMessagesReadDo(bool read, uint32_t &token);