diff --git a/libretroshare/src/retroshare/rsgxschannels.h b/libretroshare/src/retroshare/rsgxschannels.h index d9bf6c7a7..23ffc9a6c 100644 --- a/libretroshare/src/retroshare/rsgxschannels.h +++ b/libretroshare/src/retroshare/rsgxschannels.h @@ -328,8 +328,11 @@ public: std::vector& channelsInfo ) = 0; /** - * @brief Get all channel messages and comments in a given channel - * @jsonapi{development} + * @brief Get all channel messages, comments and votes in a given channel + * @note It's the client's responsibility to figure out which message (resp. comment) + * a comment (resp. vote) refers to. + * + * @jsonapi{development} * @param[in] channelId id of the channel of which the content is requested * @param[out] posts storage for posts * @param[out] comments storage for the comments @@ -342,11 +345,13 @@ public: std::vector& votes ) = 0; /** - * @brief Get channel messages and comments corresponding to the given IDs. - * If the set is empty, nothing is returned. - * @note Since comments are internally themselves messages, it is possible - * to get comments only by supplying their IDs. - * @jsonapi{development} + * @brief Get channel messages, comments and votes corresponding to the given IDs. + * @note Since comments are internally themselves messages, this function actually + * returns the data for messages, comments or votes that have the given ID. + * It *does not* automatically retrieve the comments or votes for a given message + * which Id you supplied. + * + * @jsonapi{development} * @param[in] channelId id of the channel of which the content is requested * @param[in] contentsIds ids of requested contents * @param[out] posts storage for posts @@ -361,8 +366,9 @@ public: std::vector& votes ) = 0; /** - * @brief Get channel comments corresponding to the given IDs. + * @brief Get channel comments corresponding to the given message IDs. * If the set is empty, nothing is returned. + * * @jsonapi{development} * @param[in] channelId id of the channel of which the content is requested * @param[in] contentIds ids of requested contents diff --git a/libretroshare/src/services/p3gxschannels.cc b/libretroshare/src/services/p3gxschannels.cc index 55297b635..7d181d021 100644 --- a/libretroshare/src/services/p3gxschannels.cc +++ b/libretroshare/src/services/p3gxschannels.cc @@ -485,10 +485,9 @@ bool p3GxsChannels::groupShareKeys( * at the moment - fix it up later */ -bool p3GxsChannels::getPostData( - const uint32_t &token, std::vector &msgs, - std::vector &cmts, - std::vector &vots) +bool p3GxsChannels::getPostData( const uint32_t& token, std::vector& msgs, + std::vector& cmts, + std::vector& vots) { #ifdef GXSCHANNELS_DEBUG RsDbg() << __PRETTY_FUNCTION__ << std::endl; diff --git a/retroshare-gui/src/gui/gxschannels/GxsChannelPostsModel.cpp b/retroshare-gui/src/gui/gxschannels/GxsChannelPostsModel.cpp index d65689766..72599364c 100644 --- a/retroshare-gui/src/gui/gxschannels/GxsChannelPostsModel.cpp +++ b/retroshare-gui/src/gui/gxschannels/GxsChannelPostsModel.cpp @@ -72,6 +72,31 @@ void RsGxsChannelPostsModel::setMode(TreeMode mode) triggerViewUpdate(); } +void updateCommentCounts( std::vector& posts, std::vector& comments) +{ + // Store posts IDs in a std::map to avoid a quadratic cost + + std::cerr << "Updating comment counts for " << posts.size() << " posts." << std::endl; + std::map post_indices; + + for(uint32_t i=0;i event) { const RsGxsChannelEvent *e = dynamic_cast(event.get()); @@ -91,7 +116,7 @@ void RsGxsChannelPostsModel::handleEvent_main_thread(std::shared_ptrmChannelGroupId == mChannelGroup.mMeta.mGroupId) RsThread::async([this, e]() { - // 1 - get message data from p3GxsChannels + // 1 - get message data from p3GxsChannels. No need for pointers here, because we send only a single post to postToObject() std::vector posts; std::vector comments; @@ -103,9 +128,17 @@ void RsGxsChannelPostsModel::handleEvent_main_thread(std::shared_ptrgetChannelComments(mChannelGroup.mMeta.mGroupId,std::set{ e->mChannelMsgId },comments)) + { + std::cerr << __PRETTY_FUNCTION__ << " failed to retrieve message comment data for channel/msg " << e->mChannelGroupId << "/" << e->mChannelMsgId << std::endl; + return; + } + + updateCommentCounts(posts,comments); + // 2 - update the model in the UI thread. - RsQThreadUtils::postToObject( [posts,comments,votes,this]() + RsQThreadUtils::postToObject( [posts,this]() { for(uint32_t i=0;i& posts, std::vector& comments) -{ - // Store posts IDs in a std::map to avoid a quadratic cost - - std::map post_indices; - - for(uint32_t i=0;isize() << std::endl; + std::cerr << " comments: " << comments->size() << std::endl; + std::cerr << " votes : " << votes->size() << std::endl; // This shouldn't be needed normally. We need it until a background process computes the number of comments per // post and stores it in the service string. Since we request all data, this process isn't costing much anyway.