removed multi-callback based distant search result handling, and use rsEvents instead

This commit is contained in:
csoler 2020-06-16 21:13:55 +02:00
parent 8e2c670716
commit 33da5c06b8
No known key found for this signature in database
GPG Key ID: 7BCA522266C0804C
15 changed files with 204 additions and 123 deletions

View File

@ -1675,13 +1675,7 @@ void RsGenExchange::receiveNewMessages(std::vector<RsNxsMsg *>& messages)
void RsGenExchange::receiveDistantSearchResults(TurtleRequestId id,const RsGxsGroupId &grpId)
{
std::cerr << __PRETTY_FUNCTION__ << " received result for request "
<< std::hex << id << std::dec << std::endl;
RS_STACK_MUTEX(mGenMtx);
RsGxsDistantSearchResultChange* gc = new RsGxsDistantSearchResultChange(id,grpId);
mNotifications.push_back(gc);
std::cerr << __PRETTY_FUNCTION__ << " received result for request " << std::hex << id << std::dec << ": this method should be overloaded in the client service, but it is not. This is a bug!" << std::endl;
}
void RsGenExchange::notifyReceivePublishKey(const RsGxsGroupId &grpId)

View File

@ -5155,7 +5155,7 @@ static bool termSearch(const std::string& src, const std::string& substring)
}
#endif // ndef RS_DEEP_CHANNEL_INDEX
bool RsGxsNetService::retrieveDistantSearchResults(TurtleRequestId req,std::map<RsGxsGroupId,RsGxsGroupSummary>& group_infos)
bool RsGxsNetService::retrieveDistantSearchResults(TurtleRequestId req,std::map<RsGxsGroupId,RsGxsGroupSearchResults>& group_infos)
{
RS_STACK_MUTEX(mNxsMutex) ;
@ -5167,7 +5167,7 @@ bool RsGxsNetService::retrieveDistantSearchResults(TurtleRequestId req,std::map<
group_infos = it->second;
return true ;
}
bool RsGxsNetService::retrieveDistantGroupSummary(const RsGxsGroupId& group_id,RsGxsGroupSummary& gs)
bool RsGxsNetService::retrieveDistantGroupSummary(const RsGxsGroupId& group_id,RsGxsGroupSearchResults& gs)
{
RS_STACK_MUTEX(mNxsMutex) ;
for(auto it(mDistantSearchResults.begin());it!=mDistantSearchResults.end();++it)
@ -5197,7 +5197,7 @@ void RsGxsNetService::receiveTurtleSearchResults( TurtleRequestId req, const std
RS_STACK_MUTEX(mNxsMutex);
RsGxsGrpMetaTemporaryMap grpMeta;
std::map<RsGxsGroupId,RsGxsGroupSummary>& search_results_map(mDistantSearchResults[req]);
std::map<RsGxsGroupId,RsGxsGroupSearchResults>& search_results_map(mDistantSearchResults[req]);
std::cerr << "Received group summary through turtle search for the following groups:" << std::endl;
@ -5236,16 +5236,30 @@ void RsGxsNetService::receiveTurtleSearchResults( TurtleRequestId req, const std
const RsGxsGroupId& grpId(gps.mGroupId);
groupsToNotifyResults.insert(grpId);
auto it2 = search_results_map.find(grpId);
RsGxsGroupSummary& eGpS(search_results_map[grpId]);
// Find search results place for this particular group
int popularity = eGpS.mPopularity + 1;
int number_of_msg = std::max( eGpS.mNumberOfMessages, gps.mNumberOfMessages );
std::cerr << " Adding gps=" << gps.mGroupId << " name=\"" << gps.mGroupName << "\" gps.mSearchContext=\"" << gps.mSearchContext << "\"" << std::endl;
RsGxsGroupSearchResults& eGpS(search_results_map[grpId]);
eGpS = gps;
eGpS.mPopularity = popularity;
eGpS.mNumberOfMessages = number_of_msg;
if(eGpS.mGroupId != grpId) // not initialized yet. So we do it now.
{
eGpS.mGroupId = gps.mGroupId;
eGpS.mGroupName = gps.mGroupName;
eGpS.mAuthorId = gps.mAuthorId;
eGpS.mPublishTs = gps.mPublishTs;
eGpS.mSignFlags = gps.mSignFlags;
}
// We should check that the above values are always the same for all info that is received. In the end, we'll
// request the group meta and check the signature, but it may be misleading to receive a forged information
// that is not the real one.
++eGpS.mPopularity; // increase popularity. This is not a real counting, but therefore some heuristic estimate.
eGpS.mNumberOfMessages = std::max( eGpS.mNumberOfMessages, gps.mNumberOfMessages );
eGpS.mLastMessageTs = std::max( eGpS.mLastMessageTs, gps.mLastMessageTs );
if(gps.mSearchContext != gps.mGroupName) // this is a bit of a hack. We should have flags to tell where the search hit happens
eGpS.mSearchContexts.insert(gps.mSearchContext);
}
} // end RS_STACK_MUTEX(mNxsMutex);

View File

@ -140,9 +140,9 @@ public:
virtual void receiveTurtleSearchResults(TurtleRequestId req,const std::list<RsGxsGroupSummary>& group_infos);
virtual void receiveTurtleSearchResults(TurtleRequestId req,const unsigned char *encrypted_group_data,uint32_t encrypted_group_data_len);
virtual bool retrieveDistantSearchResults(TurtleRequestId req, std::map<RsGxsGroupId, RsGxsGroupSummary> &group_infos);
virtual bool retrieveDistantSearchResults(TurtleRequestId req, std::map<RsGxsGroupId, RsGxsGroupSearchResults> &group_infos);
virtual bool clearDistantSearchResults(const TurtleRequestId& id);
virtual bool retrieveDistantGroupSummary(const RsGxsGroupId&,RsGxsGroupSummary&);
virtual bool retrieveDistantGroupSummary(const RsGxsGroupId&, RsGxsGroupSearchResults &);
/*!
* pauses synchronisation of subscribed groups and request for group id
@ -609,7 +609,7 @@ private:
std::set<RsGxsGroupId> mNewPublishKeysToNotify ;
// Distant search result map
std::map<TurtleRequestId,std::map<RsGxsGroupId,RsGxsGroupSummary> > mDistantSearchResults ;
std::map<TurtleRequestId,std::map<RsGxsGroupId,RsGxsGroupSearchResults> > mDistantSearchResults ;
void debugDump();

View File

@ -76,16 +76,6 @@ protected:
bool mMetaChange;
};
class RsGxsDistantSearchResultChange: public RsGxsNotify
{
public:
RsGxsDistantSearchResultChange(TurtleRequestId id,const RsGxsGroupId& gid) : RsGxsNotify(gid), mRequestId(id){}
NotifyType getType() { return TYPE_RECEIVED_DISTANT_SEARCH_RESULTS ; }
TurtleRequestId mRequestId ;
};
/*!
* Relevant to message changes
*/

View File

@ -128,7 +128,7 @@ public:
* \return
* false when the request is unknown.
*/
virtual bool retrieveDistantSearchResults(TurtleRequestId req, std::map<RsGxsGroupId, RsGxsGroupSummary> &group_infos)=0;
virtual bool retrieveDistantSearchResults(TurtleRequestId req, std::map<RsGxsGroupId, RsGxsGroupSearchResults> &group_infos)=0;
/*!
* \brief getDistantSearchResults
* \param id
@ -136,7 +136,7 @@ public:
* \return
*/
virtual bool clearDistantSearchResults(const TurtleRequestId& id)=0;
virtual bool retrieveDistantGroupSummary(const RsGxsGroupId&,RsGxsGroupSummary&)=0;
virtual bool retrieveDistantGroupSummary(const RsGxsGroupId&,RsGxsGroupSearchResults&)=0;
virtual bool search(const std::string& substring,std::list<RsGxsGroupSummary>& group_infos) =0;
virtual bool search(const Sha1CheckSum& hashed_group_id,unsigned char *& encrypted_group_data,uint32_t& encrypted_group_data_len)=0;

View File

@ -117,9 +117,7 @@ enum class RsChannelEventCode: uint8_t
struct RsGxsChannelEvent: RsEvent
{
RsGxsChannelEvent():
RsEvent(RsEventType::GXS_CHANNELS),
mChannelEventCode(RsChannelEventCode::UNKNOWN) {}
RsGxsChannelEvent(): RsEvent(RsEventType::GXS_CHANNELS), mChannelEventCode(RsChannelEventCode::UNKNOWN) {}
RsChannelEventCode mChannelEventCode;
RsGxsGroupId mChannelGroupId;
@ -138,6 +136,23 @@ struct RsGxsChannelEvent: RsEvent
}
};
// This event is used to factor multiple search results notifications in a single event.
struct RsGxsChannelSearchResultEvent: public RsEvent
{
RsGxsChannelSearchResultEvent() : RsEvent(RsEventType::GXS_CHANNELS) {}
std::map<TurtleRequestId,std::set<RsGxsGroupId> > mSearchResultsMap;
///* @see RsEvent @see RsSerializable
void serial_process( RsGenericSerializer::SerializeJob j,RsGenericSerializer::SerializeContext& ctx) override
{
RsEvent::serial_process(j, ctx);
RS_SERIAL_PROCESS(mSearchResultsMap);
}
};
class RsGxsChannels: public RsGxsIfaceHelper, public RsGxsCommentService
{
public:
@ -407,7 +422,7 @@ public:
*/
virtual bool getChannelStatistics(const RsGxsGroupId& channelId,GxsGroupStatistic& stat) =0;
#ifdef TO_REMOVE
/**
* @brief Request remote channels search
* @jsonapi{development}
@ -448,6 +463,7 @@ public:
const std::string& matchString,
const std::function<void (const RsGxsGroupSummary& result)>& multiCallback,
rstime_t maxWait = 30 ) = 0;
#endif
/// default base URL used for channels links @see exportChannelLink
static const std::string DEFAULT_CHANNEL_BASE_URL;
@ -695,16 +711,15 @@ public:
/// Distant synchronisation methods ///
//////////////////////////////////////////////////////////////////////////////
///
RS_DEPRECATED_FOR(turtleChannelRequest)
///
// This approach is much cleaner than the "multicallback" system. We should keep it and use rsEvents to warn when
// new results are received.
virtual TurtleRequestId turtleGroupRequest(const RsGxsGroupId& group_id)=0;
RS_DEPRECATED
virtual TurtleRequestId turtleSearchRequest(const std::string& match_string)=0;
RS_DEPRECATED_FOR(turtleSearchRequest)
virtual bool retrieveDistantSearchResults(TurtleRequestId req, std::map<RsGxsGroupId, RsGxsGroupSummary> &results) =0;
RS_DEPRECATED
virtual bool clearDistantSearchResults(TurtleRequestId req)=0;
RS_DEPRECATED_FOR(turtleChannelRequest)
virtual bool retrieveDistantGroup(const RsGxsGroupId& group_id,RsGxsChannelGroup& distant_group)=0;
virtual bool retrieveDistantSearchResults(TurtleRequestId req, std::map<RsGxsGroupId, RsGxsGroupSearchResults> &results) =0;
//////////////////////////////////////////////////////////////////////////////
~RsGxsChannels() override;

View File

@ -72,6 +72,46 @@ struct RsGxsGroupSummary : RsSerializable
~RsGxsGroupSummary();
};
/*!
* This structure is used to locally store group search results for a given service.
* It contains the group information as well as a context
* strings to tell where the information was found. It is more compact than a
* GroupMeta object, so as to make search responses as light as possible.
*/
struct RsGxsGroupSearchResults : RsSerializable
{
RsGxsGroupSearchResults()
: mPublishTs(0), mNumberOfMessages(0),mLastMessageTs(0), mSignFlags(0),mPopularity(0)
{}
RsGxsGroupId mGroupId;
std::string mGroupName;
RsGxsId mAuthorId;
rstime_t mPublishTs;
uint32_t mNumberOfMessages;
rstime_t mLastMessageTs;
uint32_t mSignFlags;
uint32_t mPopularity;
std::set<std::string> mSearchContexts;
/// @see RsSerializable::serial_process
void serial_process( RsGenericSerializer::SerializeJob j,
RsGenericSerializer::SerializeContext& ctx )
{
RS_SERIAL_PROCESS(mGroupId);
RS_SERIAL_PROCESS(mGroupName);
RS_SERIAL_PROCESS(mAuthorId);
RS_SERIAL_PROCESS(mPublishTs);
RS_SERIAL_PROCESS(mNumberOfMessages);
RS_SERIAL_PROCESS(mLastMessageTs);
RS_SERIAL_PROCESS(mSignFlags);
RS_SERIAL_PROCESS(mPopularity);
RS_SERIAL_PROCESS(mSearchContexts);
}
virtual ~RsGxsGroupSearchResults() = default;
};
/*!
* Stores ids of changed gxs groups and messages.

View File

@ -80,12 +80,15 @@ p3GxsChannels::p3GxsChannels(
RS_SERVICE_GXS_TYPE_CHANNELS, gixs, channelsAuthenPolicy() ),
RsGxsChannels(static_cast<RsGxsIface&>(*this)), GxsTokenQueue(this),
mSubscribedGroupsMutex("GXS channels subscribed groups cache"),
mKnownChannelsMutex("GXS channels known channels timestamp cache"),
mKnownChannelsMutex("GXS channels known channels timestamp cache")
#ifdef TO_REMOVE
mSearchCallbacksMapMutex("GXS channels search callbacks map"),
mDistantChannelsCallbacksMapMutex("GXS channels distant channels callbacks map")
#endif
{
// For Dummy Msgs.
mGenActive = false;
mLastDistantSearchNotificationTS = 0;
mCommentService = new p3GxsCommentService(this, RS_SERVICE_GXS_TYPE_CHANNELS);
RsTickEvent::schedule_in(CHANNEL_PROCESS, 0);
@ -352,18 +355,6 @@ void p3GxsChannels::notifyChanges(std::vector<RsGxsNotify *> &changes)
}
RsGxsDistantSearchResultChange *dsrChange = dynamic_cast<RsGxsDistantSearchResultChange*>(*it);
if(dsrChange && rsEvents)
{
auto ev = std::make_shared<RsGxsChannelEvent>();
ev->mChannelGroupId = dsrChange->mGroupId;
ev->mChannelEventCode = RsChannelEventCode::RECEIVED_DISTANT_SEARCH_RESULT;
ev->mDistantSearchRequestId = dsrChange->mRequestId;
rsEvents->postEvent(ev);
}
/* shouldn't need to worry about groups - as they need to be subscribed to */
delete *it;
}
@ -383,17 +374,32 @@ void p3GxsChannels::notifyChanges(std::vector<RsGxsNotify *> &changes)
void p3GxsChannels::service_tick()
{
static rstime_t last_dummy_tick = 0;
rstime_t now = time(NULL);
if (time(NULL) > last_dummy_tick + 5)
{
dummy_tick();
last_dummy_tick = time(NULL);
last_dummy_tick = now;
}
RsTickEvent::tick_events();
GxsTokenQueue::checkRequests();
mCommentService->comment_tick();
// Notify distant search results, not more than once per sec. Normally we should
// rather send one item for all, but that needs another class type
if(now > mLastDistantSearchNotificationTS+2 && !mSearchResultsToNotify.empty())
{
auto ev = std::make_shared<RsGxsChannelSearchResultEvent>();
ev->mSearchResultsMap = mSearchResultsToNotify;
mLastDistantSearchNotificationTS = now;
mSearchResultsToNotify.clear();
rsEvents->postEvent(ev);
}
}
bool p3GxsChannels::getGroupData(const uint32_t &token, std::vector<RsGxsChannelGroup> &groups)
@ -2210,7 +2216,9 @@ void p3GxsChannels::dummy_tick()
}
#ifdef TO_REMOVE
cleanTimedOutCallbacks();
#endif
}
@ -2389,18 +2397,18 @@ bool p3GxsChannels::clearDistantSearchResults(TurtleRequestId req)
{
return netService()->clearDistantSearchResults(req);
}
bool p3GxsChannels::retrieveDistantSearchResults(TurtleRequestId req,std::map<RsGxsGroupId,RsGxsGroupSummary>& results)
bool p3GxsChannels::retrieveDistantSearchResults(TurtleRequestId req,std::map<RsGxsGroupId,RsGxsGroupSearchResults>& results)
{
return netService()->retrieveDistantSearchResults(req,results);
}
bool p3GxsChannels::retrieveDistantGroup(const RsGxsGroupId& group_id,RsGxsChannelGroup& distant_group)
{
RsGxsGroupSummary gs;
RsGxsGroupSearchResults gs;
if(netService()->retrieveDistantGroupSummary(group_id,gs))
{
// This is a placeholder information by the time we receive the full group meta data.
// This is a placeholder information by the time we receive the full group meta data and check the signature.
distant_group.mMeta.mGroupId = gs.mGroupId ;
distant_group.mMeta.mGroupName = gs.mGroupName;
distant_group.mMeta.mGroupFlags = GXS_SERV::FLAG_PRIVACY_PUBLIC ;
@ -2426,6 +2434,7 @@ bool p3GxsChannels::retrieveDistantGroup(const RsGxsGroupId& group_id,RsGxsChann
return false ;
}
#ifdef TO_REMOVE
bool p3GxsChannels::turtleSearchRequest(
const std::string& matchString,
const std::function<void (const RsGxsGroupSummary&)>& multiCallback,
@ -2505,17 +2514,24 @@ bool p3GxsChannels::localSearchRequest(
return true;
}
#endif
void p3GxsChannels::receiveDistantSearchResults(
TurtleRequestId id, const RsGxsGroupId& grpId )
void p3GxsChannels::receiveDistantSearchResults( TurtleRequestId id, const RsGxsGroupId& grpId )
{
std::cerr << __PRETTY_FUNCTION__ << "(" << id << ", " << grpId << ")"
<< std::endl;
if(!rsEvents)
return;
// We temporise here, in order to avoid notifying clients with many events
// So we put some data in there and will send an event with all of them at once every 1 sec at most.
mSearchResultsToNotify[id].insert(grpId);
#ifdef TO_REMOVE
std::cerr << __PRETTY_FUNCTION__ << "(" << id << ", " << grpId << ")" << std::endl;
{
RsGenExchange::receiveDistantSearchResults(id, grpId);
RsGxsGroupSummary gs;
gs.mGroupId = grpId;
RsGxsGroupSearchResults gs;
netService()->retrieveDistantGroupSummary(grpId, gs);
{
@ -2556,8 +2572,10 @@ void p3GxsChannels::receiveDistantSearchResults(
return;
}
} // RS_STACK_MUTEX(mDistantChannelsCallbacksMapMutex);
#endif
}
#ifdef TO_REMOVE
void p3GxsChannels::cleanTimedOutCallbacks()
{
auto now = std::chrono::system_clock::now();
@ -2586,6 +2604,7 @@ void p3GxsChannels::cleanTimedOutCallbacks()
else ++cbpt;
} // RS_STACK_MUTEX(mDistantChannelsCallbacksMapMutex)
}
#endif
bool p3GxsChannels::exportChannelLink(
std::string& link, const RsGxsGroupId& chanId, bool includeGxsData,

View File

@ -68,7 +68,7 @@ protected:
virtual TurtleRequestId turtleGroupRequest(const RsGxsGroupId& group_id);
virtual TurtleRequestId turtleSearchRequest(const std::string& match_string);
virtual bool retrieveDistantSearchResults(TurtleRequestId req, std::map<RsGxsGroupId, RsGxsGroupSummary> &results) ;
virtual bool retrieveDistantSearchResults(TurtleRequestId req, std::map<RsGxsGroupId, RsGxsGroupSearchResults> &results) ;
virtual bool clearDistantSearchResults(TurtleRequestId req);
virtual bool retrieveDistantGroup(const RsGxsGroupId& group_id,RsGxsChannelGroup& distant_group);
@ -109,6 +109,7 @@ virtual bool getChannelAutoDownload(const RsGxsGroupId &groupid, bool& enabled);
virtual bool setChannelDownloadDirectory(const RsGxsGroupId &groupId, const std::string& directory);
virtual bool getChannelDownloadDirectory(const RsGxsGroupId &groupId, std::string& directory);
#ifdef TO_REMOVE
/// @see RsGxsChannels::turtleSearchRequest
virtual bool turtleSearchRequest(const std::string& matchString,
const std::function<void (const RsGxsGroupSummary&)>& multiCallback,
@ -124,6 +125,7 @@ virtual bool getChannelDownloadDirectory(const RsGxsGroupId &groupId, std::strin
virtual bool localSearchRequest(const std::string& matchString,
const std::function<void (const RsGxsGroupSummary& result)>& multiCallback,
rstime_t maxWait = 30 ) override;
#endif
/**
* Receive results from turtle search @see RsGenExchange @see RsNxsObserver
@ -374,6 +376,9 @@ bool generateGroup(uint32_t &token, std::string groupName);
std::map<RsGxsGroupId,rstime_t> mKnownChannels;
RsMutex mKnownChannelsMutex;
rstime_t mLastDistantSearchNotificationTS;
std::map<TurtleRequestId,std::set<RsGxsGroupId> > mSearchResultsToNotify;
#ifdef TO_REMOVE
/** Store search callbacks with timeout*/
std::map<
TurtleRequestId,
@ -394,4 +399,5 @@ bool generateGroup(uint32_t &token, std::string groupName);
/// Cleanup mSearchCallbacksMap and mDistantChannelsCallbacksMap
void cleanTimedOutCallbacks();
#endif
};

View File

@ -463,6 +463,12 @@ void GroupTreeWidget::fillGroupItems(QTreeWidgetItem *categoryItem, const QList<
item->setData(COLUMN_DATA, ROLE_NAME, itemInfo.name);
item->setData(COLUMN_DATA, ROLE_DESCRIPTION, itemInfo.description);
// Add children for context strings. This happens in the search.
while(nullptr != item->takeChild(0));
for(auto str:itemInfo.context_strings)
item->addChild(new QTreeWidgetItem(QStringList(QString::fromUtf8(str.c_str()))));
/* Set last post */
qlonglong lastPost = itemInfo.lastpost.toTime_t();
item->setData(COLUMN_DATA, ROLE_LASTPOST, -lastPost); // negative for correct sorting

View File

@ -21,6 +21,8 @@
#ifndef GROUPTREEWIDGET_H
#define GROUPTREEWIDGET_H
#include<set>
#include <QTreeWidgetItem>
#include <QDateTime>
@ -47,16 +49,17 @@ public:
{}
public:
QString id;
QString name;
QString description;
int popularity;
QDateTime lastpost;
QIcon icon;
bool publishKey;
bool adminKey;
quint32 subscribeFlags;
quint32 max_visible_posts ;
QString id;
QString name;
QString description;
int popularity;
QDateTime lastpost;
QIcon icon;
bool publishKey;
bool adminKey;
quint32 subscribeFlags;
quint32 max_visible_posts ;
std::set<std::string> context_strings;
};
//cppcheck-suppress noConstructor

View File

@ -286,55 +286,48 @@ void GxsGroupFrameDialog::updateDisplay(bool complete)
if(complete) // || !getGrpIds().empty() || !getGrpIdsMeta().empty()) {
updateGroupSummary(); /* Update group list */
updateSearchResults() ;
// updateSearchResults() ;
}
void GxsGroupFrameDialog::updateSearchResults()
{
const std::set<TurtleRequestId>& reqs = getSearchRequests();
for(auto& it:mSearchGroupsItems)
updateSearchResults(it.first);
}
for(auto it(reqs.begin());it!=reqs.end();++it)
{
std::cerr << "updating search ID " << std::hex << *it << std::dec << std::endl;
void GxsGroupFrameDialog::updateSearchResults(const TurtleRequestId& sid)
{
std::cerr << "updating search ID " << std::hex << sid << std::dec << std::endl;
std::map<RsGxsGroupId,RsGxsGroupSummary> group_infos;
std::map<RsGxsGroupId,RsGxsGroupSearchResults> group_infos;
getDistantSearchResults(*it,group_infos) ;
getDistantSearchResults(sid,group_infos) ;
std::cerr << "retrieved " << std::endl;
std::cerr << "retrieved " << std::endl;
auto it2 = mSearchGroupsItems.find(*it);
auto it2 = mSearchGroupsItems.find(sid);
if(mSearchGroupsItems.end() == it2)
{
std::cerr << "GxsGroupFrameDialog::updateSearchResults(): received result notification for req " << std::hex << *it << std::dec << " but no item present!" << std::endl;
continue ; // we could create the item just as well but since this situation is not supposed to happen, I prefer to make this a failure case.
}
QList<GroupItemInfo> group_items ;
QList<GroupItemInfo> group_items ;
for(auto it3(group_infos.begin());it3!=group_infos.end();++it3)
{
std::cerr << " adding group " << it3->first << " " << it3->second.mGroupId << " \"" << it3->second.mGroupName << "\"" << std::endl;
for(auto it3(group_infos.begin());it3!=group_infos.end();++it3)
if(mCachedGroupMetas.find(it3->first) == mCachedGroupMetas.end())
{
std::cerr << " adding new group " << it3->first << " "
<< it3->second.mGroupId << " \""
<< it3->second.mGroupName << "\"" << std::endl;
GroupItemInfo i;
i.id = QString(it3->second.mGroupId.toStdString().c_str());
i.name = QString::fromUtf8(it3->second.mGroupName.c_str());
i.popularity = 0; // could be set to the number of hits
i.lastpost = QDateTime::fromTime_t(it3->second.mLastMessageTs);
i.subscribeFlags = 0; // irrelevant here
i.publishKey = false ; // IS_GROUP_PUBLISHER(groupInfo.mSubscribeFlags);
i.adminKey = false ; // IS_GROUP_ADMIN(groupInfo.mSubscribeFlags);
i.max_visible_posts = it3->second.mNumberOfMessages;
i.context_strings = it3->second.mSearchContexts;
GroupItemInfo i;
i.id = QString(it3->second.mGroupId.toStdString().c_str());
i.name = QString::fromUtf8(it3->second.mGroupName.c_str());
i.popularity = 0; // could be set to the number of hits
i.lastpost = QDateTime::fromTime_t(it3->second.mLastMessageTs);
i.subscribeFlags = 0; // irrelevant here
i.publishKey = false ; // IS_GROUP_PUBLISHER(groupInfo.mSubscribeFlags);
i.adminKey = false ; // IS_GROUP_ADMIN(groupInfo.mSubscribeFlags);
i.max_visible_posts = it3->second.mNumberOfMessages;
group_items.push_back(i);
}
group_items.push_back(i);
}
ui->groupTreeWidget->fillGroupItems(it2->second, group_items);
}
ui->groupTreeWidget->fillGroupItems(it2->second, group_items);
}
void GxsGroupFrameDialog::todo()

View File

@ -161,7 +161,7 @@ private:
virtual void groupTreeCustomActions(RsGxsGroupId /*grpId*/, int /*subscribeFlags*/, QList<QAction*> &/*actions*/) {}
virtual RsGxsCommentService *getCommentService() { return NULL; }
virtual QWidget *createCommentHeaderWidget(const RsGxsGroupId &/*grpId*/, const RsGxsMessageId &/*msgId*/) { return NULL; }
virtual bool getDistantSearchResults(TurtleRequestId /* id */, std::map<RsGxsGroupId,RsGxsGroupSummary>& /* group_infos */){ return false ;}
virtual bool getDistantSearchResults(TurtleRequestId /* id */, std::map<RsGxsGroupId,RsGxsGroupSearchResults>& /* group_infos */){ return false ;}
void initUi();
@ -187,7 +187,8 @@ private:
GxsCommentDialog *commentWidget(const RsGxsMessageId &msgId);
protected:
void updateSearchResults();
void updateSearchResults(const TurtleRequestId &sid);
void updateSearchResults(); // update all searches
bool mCountChildMsgs; // Count unread child messages?

View File

@ -61,9 +61,7 @@ void GxsChannelDialog::handleEvent_main_thread(std::shared_ptr<const RsEvent> ev
{
const RsGxsChannelEvent *e = dynamic_cast<const RsGxsChannelEvent*>(event.get());
if(!e)
return;
if(e)
switch(e->mChannelEventCode)
{
case RsChannelEventCode::NEW_MESSAGE: // [[fallthrough]];
@ -72,11 +70,6 @@ void GxsChannelDialog::handleEvent_main_thread(std::shared_ptr<const RsEvent> ev
updateGroupStatisticsReal(e->mChannelGroupId); // update the list immediately
break;
case RsChannelEventCode::RECEIVED_DISTANT_SEARCH_RESULT:
mSearchResults.insert(e->mDistantSearchRequestId);
updateSearchResults();
break;
case RsChannelEventCode::NEW_CHANNEL: // [[fallthrough]];
case RsChannelEventCode::SUBSCRIBE_STATUS_CHANGED:
updateDisplay(true);
@ -89,6 +82,13 @@ void GxsChannelDialog::handleEvent_main_thread(std::shared_ptr<const RsEvent> ev
default:
break;
}
const RsGxsChannelSearchResultEvent*f = dynamic_cast<const RsGxsChannelSearchResultEvent*>(event.get());
if(nullptr != f)
for(auto it:f->mSearchResultsMap)
updateSearchResults(it.first);
}
GxsChannelDialog::~GxsChannelDialog()
@ -401,7 +401,7 @@ TurtleRequestId GxsChannelDialog::distantSearch(const QString& search_string)
return rsGxsChannels->turtleSearchRequest(search_string.toStdString()) ;
}
bool GxsChannelDialog::getDistantSearchResults(TurtleRequestId id, std::map<RsGxsGroupId,RsGxsGroupSummary>& group_infos)
bool GxsChannelDialog::getDistantSearchResults(TurtleRequestId id, std::map<RsGxsGroupId,RsGxsGroupSearchResults>& group_infos)
{
return rsGxsChannels->retrieveDistantSearchResults(id,group_infos);
}

View File

@ -43,7 +43,7 @@ public:
protected:
/* GxsGroupFrameDialog */
virtual bool getDistantSearchResults(TurtleRequestId id, std::map<RsGxsGroupId,RsGxsGroupSummary>& group_infos);
virtual bool getDistantSearchResults(TurtleRequestId id, std::map<RsGxsGroupId, RsGxsGroupSearchResults> &group_infos);
virtual TurtleRequestId distantSearch(const QString& search_string) ;
virtual void checkRequestGroup(const RsGxsGroupId& grpId) ;