diff --git a/libretroshare/src/retroshare/rsgxsforums.h b/libretroshare/src/retroshare/rsgxsforums.h index ad73a92c2..c56074e69 100644 --- a/libretroshare/src/retroshare/rsgxsforums.h +++ b/libretroshare/src/retroshare/rsgxsforums.h @@ -139,10 +139,11 @@ public: const std::list& forumIds, std::vector& forumsInfo ) = 0; + /** * @brief Get content of specified forums. Blocking API * @jsonapi{development} - * @param[in] forumIds id of the channels of which the content is requested + * @param[in] forumIds id of the forum of which the content is requested * @param[out] messages storage for the forum messages * @return false if something failed, true otherwhise */ @@ -150,6 +151,16 @@ public: const std::list& forumIds, std::vector& messages ) = 0; + /** + * @brief Get message metadatas for some messages of a specific forum. Blocking API + * @jsonapi{development} + * @param[in] forumIds id of the forum of which the content is requested + * @param[out] msg_metas storage for the forum messages meta data + * @return false if something failed, true otherwhise + */ + virtual bool getForumMsgMetaData( const RsGxsGroupId& forumId, + std::vector& msg_metas) =0; + /** * @brief Get specific list of messages from a single forums. Blocking API * @jsonapi{development} diff --git a/libretroshare/src/services/p3gxsforums.cc b/libretroshare/src/services/p3gxsforums.cc index 1760a2f2b..aaf663d92 100644 --- a/libretroshare/src/services/p3gxsforums.cc +++ b/libretroshare/src/services/p3gxsforums.cc @@ -297,6 +297,11 @@ bool p3GxsForums::getGroupData(const uint32_t &token, std::vector& forums ) +bool p3GxsForums::getForumsSummaries( std::list& forums ) { uint32_t token; RsTokReqOptions opts; @@ -482,6 +486,26 @@ bool p3GxsForums::getForumsContent( return getMsgData(token, messages); } + +bool p3GxsForums::getForumMsgMetaData(const RsGxsGroupId& forumId, std::vector& msg_metas) +{ + uint32_t token; + RsTokReqOptions opts; + opts.mReqType = GXS_REQUEST_TYPE_MSG_META; + + GxsMsgMetaMap meta_map; + std::list forumIds; + forumIds.push_back(forumId); + + if( !requestMsgInfo(token, opts, forumIds) || waitToken(token,std::chrono::milliseconds(5000)) != RsTokenService::COMPLETE ) return false; + + bool res = getMsgMetaData(token, meta_map); + + msg_metas = meta_map[forumId]; + + return res; +} + bool p3GxsForums::markRead(const RsGxsGrpMsgIdPair& msgId, bool read) { uint32_t token; diff --git a/libretroshare/src/services/p3gxsforums.h b/libretroshare/src/services/p3gxsforums.h index 29260c8cf..051368175 100644 --- a/libretroshare/src/services/p3gxsforums.h +++ b/libretroshare/src/services/p3gxsforums.h @@ -77,6 +77,9 @@ public: const std::list& forumIds, std::vector& messages ); + /// @see RsGxsForums::getForumMsgMetaData + virtual bool getForumMsgMetaData(const RsGxsGroupId& forumId, std::vector& msg_metas) ; + /// @see RsGxsForums::getForumsContent virtual bool getForumsContent( const RsGxsGroupId& forumId, std::set& msgs_to_request,std::vector& msgs) ; @@ -85,6 +88,7 @@ public: virtual bool getGroupData(const uint32_t &token, std::vector &groups); virtual bool getMsgData(const uint32_t &token, std::vector &msgs); + virtual bool getMsgMetaData(const uint32_t &token, GxsMsgMetaMap& msg_metas); virtual void setMessageReadStatus(uint32_t& token, const RsGxsGrpMsgIdPair& msgId, bool read); virtual bool createGroup(uint32_t &token, RsGxsForumGroup &group); virtual bool createMsg(uint32_t &token, RsGxsForumMsg &msg); diff --git a/retroshare-gui/src/gui/gxsforums/GxsForumModel.cpp b/retroshare-gui/src/gui/gxsforums/GxsForumModel.cpp index 975944d2a..d3713a1da 100644 --- a/retroshare-gui/src/gui/gxsforums/GxsForumModel.cpp +++ b/retroshare-gui/src/gui/gxsforums/GxsForumModel.cpp @@ -727,7 +727,7 @@ void RsGxsForumModel::update_posts(const RsGxsGroupId& group_id) // 1 - get message data from p3GxsForums std::list forumIds; - std::vector messages; + std::vector msg_metas; std::vector groups; forumIds.push_back(group_id); @@ -738,7 +738,7 @@ void RsGxsForumModel::update_posts(const RsGxsGroupId& group_id) return; } - if(!rsGxsForums->getForumsContent(forumIds,messages)) + if(!rsGxsForums->getForumMsgMetaData(group_id,msg_metas)) { std::cerr << __PRETTY_FUNCTION__ << " failed to retrieve forum message info for forum " << group_id << std::endl; return; @@ -750,7 +750,7 @@ void RsGxsForumModel::update_posts(const RsGxsGroupId& group_id) std::vector *vect = new std::vector(); RsGxsForumGroup group = groups[0]; - computeMessagesHierarchy(group,messages,*vect,*post_versions); + computeMessagesHierarchy(group,msg_metas,*vect,*post_versions); // 3 - update the model in the UI thread. @@ -798,16 +798,16 @@ void RsGxsForumModel::generateMissingItem(const RsGxsMessageId &msgId,ForumModel entry.mReputationWarningLevel = 3; } -void RsGxsForumModel::convertMsgToPostEntry(const RsGxsForumGroup& mForumGroup,const RsGxsForumMsg& msg, bool useChildTS, ForumModelPostEntry& fentry) +void RsGxsForumModel::convertMsgToPostEntry(const RsGxsForumGroup& mForumGroup,const RsMsgMetaData& msg, bool useChildTS, ForumModelPostEntry& fentry) { - fentry.mTitle = msg.mMeta.mMsgName; - fentry.mAuthorId = msg.mMeta.mAuthorId; - fentry.mMsgId = msg.mMeta.mMsgId; - fentry.mPublishTs = msg.mMeta.mPublishTs; + fentry.mTitle = msg.mMsgName; + fentry.mAuthorId = msg.mAuthorId; + fentry.mMsgId = msg.mMsgId; + fentry.mPublishTs = msg.mPublishTs; fentry.mPostFlags = 0; - fentry.mMsgStatus = msg.mMeta.mMsgStatus; + fentry.mMsgStatus = msg.mMsgStatus; - if(mForumGroup.mPinnedPosts.ids.find(msg.mMeta.mMsgId) != mForumGroup.mPinnedPosts.ids.end()) + if(mForumGroup.mPinnedPosts.ids.find(msg.mMsgId) != mForumGroup.mPinnedPosts.ids.end()) fentry.mPostFlags |= ForumModelPostEntry::FLAG_POST_IS_PINNED; // Early check for a message that should be hidden because its author @@ -842,12 +842,12 @@ void RsGxsForumModel::computeReputationLevel(uint32_t forum_sign_flags,ForumMode static bool decreasing_time_comp(const std::pair& e1,const std::pair& e2) { return e2.first < e1.first ; } void RsGxsForumModel::computeMessagesHierarchy(const RsGxsForumGroup& forum_group, - const std::vector& msgs_array, + const std::vector& msgs_metas_array, std::vector& posts, std::map > >& mPostVersions ) { - std::cerr << "updating messages data with " << msgs_array.size() << " messages" << std::endl; + std::cerr << "updating messages data with " << msgs_metas_array.size() << " messages" << std::endl; #ifdef DEBUG_FORUMS std::cerr << "Retrieved group data: " << std::endl; @@ -861,14 +861,14 @@ void RsGxsForumModel::computeMessagesHierarchy(const RsGxsForumGroup& forum_grou #endif /* get messages */ - std::map msgs; + std::map msgs; - for(uint32_t i=0;i msg_stack ; - for ( std::map::iterator msgIt = msgs.begin(); msgIt != msgs.end();++msgIt) + for ( auto msgIt = msgs.begin(); msgIt != msgs.end();++msgIt) { - if(!msgIt->second.mMeta.mOrigMsgId.isNull() && msgIt->second.mMeta.mOrigMsgId != msgIt->second.mMeta.mMsgId) + if(!msgIt->second.mOrigMsgId.isNull() && msgIt->second.mOrigMsgId != msgIt->second.mMsgId) { #ifdef DEBUG_FORUMS std::cerr << " Post " << msgIt->second.mMeta.mMsgId << " is a new version of " << msgIt->second.mMeta.mOrigMsgId << std::endl; #endif - std::map::iterator msgIt2 = msgs.find(msgIt->second.mMeta.mOrigMsgId); + auto msgIt2 = msgs.find(msgIt->second.mOrigMsgId); // Ensuring that the post exists allows to only collect the existing data. @@ -917,21 +917,21 @@ void RsGxsForumModel::computeMessagesHierarchy(const RsGxsForumGroup& forum_grou // Make sure that the author is the same than the original message, or is a moderator. This should always happen when messages are constructed using // the UI but nothing can prevent a nasty user to craft a new version of a message with his own signature. - if(msgIt2->second.mMeta.mAuthorId != msgIt->second.mMeta.mAuthorId) + if(msgIt2->second.mAuthorId != msgIt->second.mAuthorId) { - if( !IS_FORUM_MSG_MODERATION(msgIt->second.mMeta.mMsgFlags) ) // if authors are different the moderation flag needs to be set on the editing msg + if( !IS_FORUM_MSG_MODERATION(msgIt->second.mMsgFlags) ) // if authors are different the moderation flag needs to be set on the editing msg continue ; - if( forum_group.mAdminList.ids.find(msgIt->second.mMeta.mAuthorId)==forum_group.mAdminList.ids.end()) // if author is not a moderator, continue + if( forum_group.mAdminList.ids.find(msgIt->second.mAuthorId)==forum_group.mAdminList.ids.end()) // if author is not a moderator, continue continue ; } // always add the post a self version - if(mPostVersions[msgIt->second.mMeta.mOrigMsgId].empty()) - mPostVersions[msgIt->second.mMeta.mOrigMsgId].push_back(std::make_pair(msgIt2->second.mMeta.mPublishTs,msgIt2->second.mMeta.mMsgId)) ; + if(mPostVersions[msgIt->second.mOrigMsgId].empty()) + mPostVersions[msgIt->second.mOrigMsgId].push_back(std::make_pair(msgIt2->second.mPublishTs,msgIt2->second.mMsgId)) ; - mPostVersions[msgIt->second.mMeta.mOrigMsgId].push_back(std::make_pair(msgIt->second.mMeta.mPublishTs,msgIt->second.mMeta.mMsgId)) ; + mPostVersions[msgIt->second.mOrigMsgId].push_back(std::make_pair(msgIt->second.mPublishTs,msgIt->second.mMsgId)) ; } } @@ -1008,19 +1008,19 @@ void RsGxsForumModel::computeMessagesHierarchy(const RsGxsForumGroup& forum_grou // this trick is needed because while we remove messages, the parents a given msg may already have been removed // and wrongly understand as a missing parent. - std::map kept_msgs; + std::map kept_msgs; - for ( std::map::iterator msgIt = msgs.begin(); msgIt != msgs.end();++msgIt) + for ( auto msgIt = msgs.begin(); msgIt != msgs.end();++msgIt) { - if(msgIt->second.mMeta.mParentId.isNull()) + if(msgIt->second.mParentId.isNull()) { /* add all threads */ - const RsGxsForumMsg& msg = msgIt->second; + const RsMsgMetaData& msg = msgIt->second; #ifdef DEBUG_FORUMS - std::cerr << "GxsForumsFillThread::run() Adding TopLevel Thread: mId: " << msg.mMeta.mMsgId << std::endl; + std::cerr << "GxsForumsFillThread::run() Adding TopLevel Thread: mId: " << msg.mMsgId << std::endl; #endif ForumModelPostEntry entry; @@ -1029,7 +1029,7 @@ void RsGxsForumModel::computeMessagesHierarchy(const RsGxsForumGroup& forum_grou ForumModelIndex entry_index = addEntry(posts,entry,0); //if (!mFlatView) - threadStack.push_back(std::make_pair(msg.mMeta.mMsgId,entry_index)) ; + threadStack.push_back(std::make_pair(msg.mMsgId,entry_index)) ; //calculateExpand(msg, item); //mItems.append(entry_index); @@ -1037,11 +1037,11 @@ void RsGxsForumModel::computeMessagesHierarchy(const RsGxsForumGroup& forum_grou else { #ifdef DEBUG_FORUMS - std::cerr << "GxsForumsFillThread::run() Storing kid " << msgIt->first << " of message " << msgIt->second.mMeta.mParentId << std::endl; + std::cerr << "GxsForumsFillThread::run() Storing kid " << msgIt->first << " of message " << msgIt->second.mParentId << std::endl; #endif // The same missing parent may appear multiple times, so we first store them into a unique container. - RsGxsMessageId parent_msg = msgIt->second.mMeta.mParentId; + RsGxsMessageId parent_msg = msgIt->second.mParentId; if(msgs.find(parent_msg) == msgs.end()) { @@ -1101,7 +1101,7 @@ void RsGxsForumModel::computeMessagesHierarchy(const RsGxsForumGroup& forum_grou // We iterate through the top level thread items, and look for which message has the current item as parent. // When found, the item is put in the thread list itself, as a potential new parent. - std::map::iterator mit = msgs.find(*it2) ; + auto mit = msgs.find(*it2) ; if(mit == msgs.end()) { @@ -1109,9 +1109,9 @@ void RsGxsForumModel::computeMessagesHierarchy(const RsGxsForumGroup& forum_grou continue ; } - const RsGxsForumMsg& msg(mit->second) ; + const RsMsgMetaData& msg(mit->second) ; #ifdef DEBUG_FORUMS - std::cerr << "GxsForumsFillThread::run() adding sub_item " << msg.mMeta.mMsgId << std::endl; + std::cerr << "GxsForumsFillThread::run() adding sub_item " << msg.mMsgId << std::endl; #endif @@ -1122,7 +1122,7 @@ void RsGxsForumModel::computeMessagesHierarchy(const RsGxsForumGroup& forum_grou //calculateExpand(msg, item); /* add item to process list */ - threadStack.push_back(std::make_pair(msg.mMeta.mMsgId, e_index)); + threadStack.push_back(std::make_pair(msg.mMsgId, e_index)); msgs.erase(mit); } diff --git a/retroshare-gui/src/gui/gxsforums/GxsForumModel.h b/retroshare-gui/src/gui/gxsforums/GxsForumModel.h index 6a6b499b7..58953e263 100644 --- a/retroshare-gui/src/gui/gxsforums/GxsForumModel.h +++ b/retroshare-gui/src/gui/gxsforums/GxsForumModel.h @@ -186,9 +186,9 @@ private: static void generateMissingItem(const RsGxsMessageId &msgId,ForumModelPostEntry& entry); static ForumModelIndex addEntry(std::vector& posts,const ForumModelPostEntry& entry,ForumModelIndex parent); - static void convertMsgToPostEntry(const RsGxsForumGroup &mForumGroup, const RsGxsForumMsg& msg, bool useChildTS, ForumModelPostEntry& fentry); + static void convertMsgToPostEntry(const RsGxsForumGroup &mForumGroup, const RsMsgMetaData &msg, bool useChildTS, ForumModelPostEntry& fentry); - void computeMessagesHierarchy(const RsGxsForumGroup& forum_group, const std::vector& msgs_array, std::vector& posts, std::map > > &mPostVersions); + void computeMessagesHierarchy(const RsGxsForumGroup& forum_group, const std::vector &msgs_array, std::vector& posts, std::map > > &mPostVersions); void setPosts(const RsGxsForumGroup& group, const std::vector& posts,const std::map > >& post_versions); void initEmptyHierarchy(std::vector& posts);