diff --git a/libretroshare/src/gxs/rsgxsnetservice.cc b/libretroshare/src/gxs/rsgxsnetservice.cc index 480e9dc2e..3c97cf95d 100644 --- a/libretroshare/src/gxs/rsgxsnetservice.cc +++ b/libretroshare/src/gxs/rsgxsnetservice.cc @@ -5130,6 +5130,20 @@ bool RsGxsNetService::retrieveDistantSearchResults(TurtleRequestId req,std::map< group_infos = it->second; return true ; } +bool RsGxsNetService::retrieveDistantGroupSummary(const RsGxsGroupId& group_id,RsGxsGroupSummary& gs) +{ + for(auto it(mDistantSearchResults.begin());it!=mDistantSearchResults.end();++it) + { + auto it2 = it->second.find(group_id) ; + + if(it2 != it->second.end()) + { + gs = it2->second; + return true ; + } + } + return false ; +} bool RsGxsNetService::clearDistantSearchResults(const TurtleRequestId& id) { RS_STACK_MUTEX(mNxsMutex) ; @@ -5139,7 +5153,6 @@ bool RsGxsNetService::clearDistantSearchResults(const TurtleRequestId& id) void RsGxsNetService::receiveTurtleSearchResults(TurtleRequestId req, const std::list& group_infos) { RS_STACK_MUTEX(mNxsMutex) ; -#warning We should use some central way to do that. This might be very costly if done often. RsGxsGrpMetaTemporaryMap grpMeta; std::map& search_results_map(mDistantSearchResults[req]) ; @@ -5159,7 +5172,22 @@ void RsGxsNetService::receiveTurtleSearchResults(TurtleRequestId req, const std: // if(grpMeta[(*it).group_id] == NULL) { filtered_results.push_back(*it) ; - search_results_map[(*it).group_id] = *it; + + auto it2 = search_results_map.find((*it).group_id) ; + + if(it2 != search_results_map.end()) + { + // update existing data + + it2->second.popularity++ ; + it2->second.number_of_messages = std::max(it2->second.number_of_messages,(*it).number_of_messages) ; + } + else + { + search_results_map[(*it).group_id] = *it; + search_results_map[(*it).group_id].popularity = 1; // number of results so far + } + mObserver->receiveDistantSearchResults(req,(*it).group_id) ; } } @@ -5184,10 +5212,12 @@ bool RsGxsNetService::search(const std::string& substring,std::listsecond->mGroupName ; s.group_description = it->second->mGroupName ; // to be filled with something better when we use the real search s.search_context = it->second->mGroupName ; - s.author_id = it->second->mAuthorId; + s.sign_flags = it->second->mSignFlags; s.publish_ts = it->second->mPublishTs; + s.author_id = it->second->mAuthorId; s.number_of_messages = stats.mMaxVisibleCount ; s.last_message_ts = stats.mLastGroupModificationTS ; + s.popularity = it->second->mPop; group_infos.push_back(s) ; } diff --git a/libretroshare/src/gxs/rsgxsnetservice.h b/libretroshare/src/gxs/rsgxsnetservice.h index 05031feb3..d6496e795 100644 --- a/libretroshare/src/gxs/rsgxsnetservice.h +++ b/libretroshare/src/gxs/rsgxsnetservice.h @@ -134,6 +134,7 @@ public: virtual void receiveTurtleSearchResults(TurtleRequestId req,const std::list& group_infos); virtual bool retrieveDistantSearchResults(TurtleRequestId req, std::map &group_infos); virtual bool clearDistantSearchResults(const TurtleRequestId& id); + virtual bool retrieveDistantGroupSummary(const RsGxsGroupId&,RsGxsGroupSummary&); /*! * pauses synchronisation of subscribed groups and request for group id diff --git a/libretroshare/src/gxs/rsgxsnettunnel.cc b/libretroshare/src/gxs/rsgxsnettunnel.cc index eabc32e3a..cce855165 100644 --- a/libretroshare/src/gxs/rsgxsnettunnel.cc +++ b/libretroshare/src/gxs/rsgxsnettunnel.cc @@ -203,8 +203,11 @@ void RsTypeSerializer::serial_process( RsGenericSerializer::SerializeJob j, RsGe RsTypeSerializer::serial_process(j,ctx,gs.publish_ts ,member_name+"-publish_ts") ; // time_t publish_ts ; RsTypeSerializer::serial_process(j,ctx,gs.number_of_messages,member_name+"-number_of_messages") ; // uint32_t number_of_messages ; RsTypeSerializer::serial_process(j,ctx,gs.last_message_ts,member_name+"-last_message_ts") ; // time_t last_message_ts ; + RsTypeSerializer::serial_process(j,ctx,gs.sign_flags,member_name+"-sign_flags") ; // uint32_t sign_flags ; + RsTypeSerializer::serial_process(j,ctx,gs.popularity,member_name+"-popularity") ; // uint32_t popularity ; } + //===========================================================================================================================================// // Interface with rest of the software // //===========================================================================================================================================// diff --git a/libretroshare/src/gxs/rsnxs.h b/libretroshare/src/gxs/rsnxs.h index b483e5748..046b2e80f 100644 --- a/libretroshare/src/gxs/rsnxs.h +++ b/libretroshare/src/gxs/rsnxs.h @@ -130,6 +130,7 @@ public: * \return */ virtual bool clearDistantSearchResults(const TurtleRequestId& id)=0; + virtual bool retrieveDistantGroupSummary(const RsGxsGroupId&,RsGxsGroupSummary&)=0; virtual bool search(const std::string& substring,std::list& group_infos) =0; diff --git a/libretroshare/src/retroshare/rsgxschannels.h b/libretroshare/src/retroshare/rsgxschannels.h index af08f4bb4..a23275b3b 100644 --- a/libretroshare/src/retroshare/rsgxschannels.h +++ b/libretroshare/src/retroshare/rsgxschannels.h @@ -99,6 +99,7 @@ virtual bool getPostData(const uint32_t &token, std::vector &p virtual TurtleRequestId turtleSearchRequest(const std::string& match_string)=0; virtual bool retrieveDistantSearchResults(TurtleRequestId req, std::map &results) =0; virtual bool clearDistantSearchResults(TurtleRequestId req)=0; + virtual bool retrieveDistantGroup(const RsGxsGroupId& group_id,RsGxsChannelGroup& distant_group)=0; ////////////////////////////////////////////////////////////////////////////// virtual void setMessageReadStatus(uint32_t& token, const RsGxsGrpMsgIdPair& msgId, bool read) = 0; diff --git a/libretroshare/src/retroshare/rsgxsiface.h b/libretroshare/src/retroshare/rsgxsiface.h index e822d70d4..bdf65c115 100644 --- a/libretroshare/src/retroshare/rsgxsiface.h +++ b/libretroshare/src/retroshare/rsgxsiface.h @@ -40,6 +40,8 @@ */ struct RsGxsGroupSummary { + RsGxsGroupSummary() : publish_ts(0), number_of_messages(0),last_message_ts(0),sign_flags(0),popularity(0) {} + RsGxsGroupId group_id ; std::string group_name ; @@ -49,6 +51,8 @@ struct RsGxsGroupSummary time_t publish_ts ; uint32_t number_of_messages ; time_t last_message_ts ; + uint32_t sign_flags ; + uint32_t popularity ; }; diff --git a/libretroshare/src/retroshare/rsgxsifacetypes.h b/libretroshare/src/retroshare/rsgxsifacetypes.h index 071b6bd46..0b0bb3322 100644 --- a/libretroshare/src/retroshare/rsgxsifacetypes.h +++ b/libretroshare/src/retroshare/rsgxsifacetypes.h @@ -69,18 +69,18 @@ struct RsGroupMetaData : RsSerializable RsGxsGroupId mGroupId; std::string mGroupName; - uint32_t mGroupFlags; // Combination of FLAG_PRIVACY_PRIVATE | FLAG_PRIVACY_RESTRICTED | FLAG_PRIVACY_PUBLIC - uint32_t mSignFlags; // Combination of RSGXS_GROUP_SIGN_PUBLISH_MASK & RSGXS_GROUP_SIGN_AUTHOR_MASK. + uint32_t mGroupFlags; // Combination of FLAG_PRIVACY_PRIVATE | FLAG_PRIVACY_RESTRICTED | FLAG_PRIVACY_PUBLIC: diffusion + uint32_t mSignFlags; // Combination of RSGXS_GROUP_SIGN_PUBLISH_MASK & RSGXS_GROUP_SIGN_AUTHOR_MASK, i.e. what signatures are required for parent and child msgs time_t mPublishTs; // Mandatory. - RsGxsId mAuthorId; // Optional. + RsGxsId mAuthorId; // Author of the group. Left to "000....0" if anonymous // for circles - RsGxsCircleId mCircleId; - uint32_t mCircleType; + RsGxsCircleId mCircleId; // Id of the circle to which the group is restricted + uint32_t mCircleType; // combination of CIRCLE_TYPE_{ PUBLIC,EXTERNAL,YOUR_FRIENDS_ONLY,LOCAL,EXT_SELF,YOUR_EYES_ONLY } // other stuff. - uint32_t mAuthenFlags; + uint32_t mAuthenFlags; // Actually not used yet. RsGxsGroupId mParentGrpId; // BELOW HERE IS LOCAL DATA, THAT IS NOT FROM MSG. diff --git a/libretroshare/src/services/p3gxschannels.cc b/libretroshare/src/services/p3gxschannels.cc index e4f89861e..ee4c89f2f 100644 --- a/libretroshare/src/services/p3gxschannels.cc +++ b/libretroshare/src/services/p3gxschannels.cc @@ -1705,4 +1705,39 @@ bool p3GxsChannels::retrieveDistantSearchResults(TurtleRequestId req,std::mapretrieveDistantSearchResults(req,results); } +bool p3GxsChannels::retrieveDistantGroup(const RsGxsGroupId& group_id,RsGxsChannelGroup& distant_group) +{ + RsGxsGroupSummary gs ; + + if(netService()->retrieveDistantGroupSummary(group_id,gs)) + { + // This is a placeholder information by the time we receive the full group meta data. + + distant_group.mDescription = gs.group_description; + + distant_group.mMeta.mGroupId = gs.group_id ; + distant_group.mMeta.mGroupName = gs.group_name; + distant_group.mMeta.mGroupFlags = GXS_SERV::FLAG_PRIVACY_PUBLIC ; + distant_group.mMeta.mSignFlags = gs.sign_flags; + + distant_group.mMeta.mPublishTs = gs.publish_ts; + distant_group.mMeta.mAuthorId = gs.author_id; + + distant_group.mMeta.mCircleType = GXS_CIRCLE_TYPE_PUBLIC ;// guessed, otherwise the group would not be search-able. + + // other stuff. + distant_group.mMeta.mAuthenFlags = 0; // wild guess... + + distant_group.mMeta.mSubscribeFlags = GXS_SERV::GROUP_SUBSCRIBE_NOT_SUBSCRIBED ; + + distant_group.mMeta.mPop = gs.popularity; // Popularity = number of friend subscribers + distant_group.mMeta.mVisibleMsgCount = gs.number_of_messages; // Max messages reported by friends + distant_group.mMeta.mLastPost = gs.last_message_ts; // Timestamp for last message. Not used yet. + + return true ; + } + else + return false ; +} + diff --git a/libretroshare/src/services/p3gxschannels.h b/libretroshare/src/services/p3gxschannels.h index 2243e57ee..7a5e19423 100644 --- a/libretroshare/src/services/p3gxschannels.h +++ b/libretroshare/src/services/p3gxschannels.h @@ -76,6 +76,7 @@ virtual void service_tick(); virtual TurtleRequestId turtleSearchRequest(const std::string& match_string); virtual bool retrieveDistantSearchResults(TurtleRequestId req, std::map &results) ; virtual bool clearDistantSearchResults(TurtleRequestId req); + virtual bool retrieveDistantGroup(const RsGxsGroupId& group_id,RsGxsChannelGroup& distant_group); // Overloaded to cache new groups. virtual RsGenExchange::ServiceCreate_Return service_CreateGroup(RsGxsGrpItem* grpItem, RsTlvSecurityKeySet& keySet); diff --git a/retroshare-gui/src/gui/gxschannels/GxsChannelPostsWidget.cpp b/retroshare-gui/src/gui/gxschannels/GxsChannelPostsWidget.cpp index 379b20823..d238c7007 100644 --- a/retroshare-gui/src/gui/gxschannels/GxsChannelPostsWidget.cpp +++ b/retroshare-gui/src/gui/gxschannels/GxsChannelPostsWidget.cpp @@ -657,12 +657,22 @@ bool GxsChannelPostsWidget::insertGroupData(const uint32_t &token, RsGroupMetaDa std::vector groups; rsGxsChannels->getGroupData(token, groups); - if (groups.size() == 1) + if(groups.size() == 1) { insertChannelDetails(groups[0]); metaData = groups[0].mMeta; return true; } + else + { + RsGxsChannelGroup distant_group; + if(rsGxsChannels->retrieveDistantGroup(groupId(),distant_group)) + { + insertChannelDetails(distant_group); + metaData = distant_group.mMeta; + return true ; + } + } return false; }