added fallback for GXS GroupMessage UI to look into cached distant group data

This commit is contained in:
csoler 2018-06-26 22:20:02 +02:00
parent a5d1a154a4
commit 00dfa0f3c2
No known key found for this signature in database
GPG Key ID: 7BCA522266C0804C
10 changed files with 96 additions and 10 deletions

View File

@ -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<RsGxsGroupSummary>& 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<RsGxsGroupId,RsGxsGroupSummary>& 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::list<RsGxsGroupSu
s.group_name = it->second->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) ;
}

View File

@ -134,6 +134,7 @@ public:
virtual void receiveTurtleSearchResults(TurtleRequestId req,const std::list<RsGxsGroupSummary>& group_infos);
virtual bool retrieveDistantSearchResults(TurtleRequestId req, std::map<RsGxsGroupId, RsGxsGroupSummary> &group_infos);
virtual bool clearDistantSearchResults(const TurtleRequestId& id);
virtual bool retrieveDistantGroupSummary(const RsGxsGroupId&,RsGxsGroupSummary&);
/*!
* pauses synchronisation of subscribed groups and request for group id

View File

@ -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<time_t>(j,ctx,gs.last_message_ts,member_name+"-last_message_ts") ; // time_t last_message_ts ;
RsTypeSerializer::serial_process<uint32_t>(j,ctx,gs.sign_flags,member_name+"-sign_flags") ; // uint32_t sign_flags ;
RsTypeSerializer::serial_process<uint32_t>(j,ctx,gs.popularity,member_name+"-popularity") ; // uint32_t popularity ;
}
//===========================================================================================================================================//
// Interface with rest of the software //
//===========================================================================================================================================//

View File

@ -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<RsGxsGroupSummary>& group_infos) =0;

View File

@ -99,6 +99,7 @@ virtual bool getPostData(const uint32_t &token, std::vector<RsGxsChannelPost> &p
virtual TurtleRequestId turtleSearchRequest(const std::string& match_string)=0;
virtual bool retrieveDistantSearchResults(TurtleRequestId req, std::map<RsGxsGroupId, RsGxsGroupSummary> &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;

View File

@ -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 ;
};

View File

@ -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.

View File

@ -1705,4 +1705,39 @@ bool p3GxsChannels::retrieveDistantSearchResults(TurtleRequestId req,std::map<Rs
return netService()->retrieveDistantSearchResults(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 ;
}

View File

@ -76,6 +76,7 @@ virtual void service_tick();
virtual TurtleRequestId turtleSearchRequest(const std::string& match_string);
virtual bool retrieveDistantSearchResults(TurtleRequestId req, std::map<RsGxsGroupId, RsGxsGroupSummary> &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);

View File

@ -657,12 +657,22 @@ bool GxsChannelPostsWidget::insertGroupData(const uint32_t &token, RsGroupMetaDa
std::vector<RsGxsChannelGroup> 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;
}