From 595df993107d5f39a9bbbc9d5b7ca8d520db7d64 Mon Sep 17 00:00:00 2001 From: csoler Date: Mon, 3 Feb 2020 21:39:05 +0100 Subject: [PATCH] fixed notifications for distant search results in channels --- libretroshare/src/retroshare/rsgxschannels.h | 32 ++--- libretroshare/src/retroshare/rsgxsservice.h | 9 +- libretroshare/src/services/p3gxschannels.cc | 134 ++++++++++-------- .../src/gui/gxs/GxsGroupFrameDialog.h | 4 +- .../src/gui/gxs/RsGxsUpdateBroadcastPage.cpp | 5 - .../src/gui/gxs/RsGxsUpdateBroadcastPage.h | 3 +- .../src/gui/gxschannels/GxsChannelDialog.cpp | 5 + .../src/gui/gxschannels/GxsChannelDialog.h | 3 + 8 files changed, 103 insertions(+), 92 deletions(-) diff --git a/libretroshare/src/retroshare/rsgxschannels.h b/libretroshare/src/retroshare/rsgxschannels.h index 9fa2f8638..615ff30f7 100644 --- a/libretroshare/src/retroshare/rsgxschannels.h +++ b/libretroshare/src/retroshare/rsgxschannels.h @@ -105,27 +105,15 @@ struct RsGxsChannelPost : RsSerializable enum class RsChannelEventCode: uint8_t { - UNKNOWN = 0x00, - NEW_CHANNEL = 0x01, /// emitted when new channel is received - - /// emitted when existing channel is updated - UPDATED_CHANNEL = 0x02, - - /// new message reeived in a particular channel (group and msg id) - NEW_MESSAGE = 0x03, - - /// existing message has been updated in a particular channel - UPDATED_MESSAGE = 0x04, - - /// publish key for this channel has been received - RECEIVED_PUBLISH_KEY = 0x05, - - /// subscription for channel mChannelGroupId changed. - SUBSCRIBE_STATUS_CHANGED = 0x06, - - /// existing message has been read or set to unread - READ_STATUS_CHANGED = 0x07, - + UNKNOWN = 0x00, + NEW_CHANNEL = 0x01, // emitted when new channel is received + UPDATED_CHANNEL = 0x02, // emitted when existing channel is updated + NEW_MESSAGE = 0x03, // new message reeived in a particular channel (group and msg id) + UPDATED_MESSAGE = 0x04, // existing message has been updated in a particular channel + RECEIVED_PUBLISH_KEY = 0x05, // publish key for this channel has been received + SUBSCRIBE_STATUS_CHANGED = 0x06, // subscription for channel mChannelGroupId changed. + READ_STATUS_CHANGED = 0x07, // existing message has been read or set to unread + RECEIVED_DISTANT_SEARCH_RESULT = 0x08, // result for the given group id available for the given turtle request id }; struct RsGxsChannelEvent: RsEvent @@ -137,6 +125,7 @@ struct RsGxsChannelEvent: RsEvent RsChannelEventCode mChannelEventCode; RsGxsGroupId mChannelGroupId; RsGxsMessageId mChannelMsgId; + TurtleRequestId mDistantSearchRequestId; ///* @see RsEvent @see RsSerializable void serial_process( RsGenericSerializer::SerializeJob j,RsGenericSerializer::SerializeContext& ctx) override @@ -146,6 +135,7 @@ struct RsGxsChannelEvent: RsEvent RS_SERIAL_PROCESS(mChannelEventCode); RS_SERIAL_PROCESS(mChannelGroupId); RS_SERIAL_PROCESS(mChannelMsgId); + RS_SERIAL_PROCESS(mDistantSearchRequestId); } }; diff --git a/libretroshare/src/retroshare/rsgxsservice.h b/libretroshare/src/retroshare/rsgxsservice.h index aab18b60b..cb4fcf7eb 100644 --- a/libretroshare/src/retroshare/rsgxsservice.h +++ b/libretroshare/src/retroshare/rsgxsservice.h @@ -40,7 +40,14 @@ typedef std::map > GxsMsgRelatedMe struct RsGxsNotify { enum NotifyType - { TYPE_PUBLISHED, TYPE_RECEIVED_NEW, TYPE_PROCESSED, TYPE_RECEIVED_PUBLISHKEY, TYPE_RECEIVED_DISTANT_SEARCH_RESULTS }; + { + TYPE_UNKNOWN = 0x00, + TYPE_PUBLISHED = 0x01, + TYPE_RECEIVED_NEW = 0x02, + TYPE_PROCESSED = 0x03, + TYPE_RECEIVED_PUBLISHKEY = 0x04, + TYPE_RECEIVED_DISTANT_SEARCH_RESULTS = 0x05 + }; virtual ~RsGxsNotify() {} virtual NotifyType getType() = 0; diff --git a/libretroshare/src/services/p3gxschannels.cc b/libretroshare/src/services/p3gxschannels.cc index 0ccdafc03..2a63b3cdb 100644 --- a/libretroshare/src/services/p3gxschannels.cc +++ b/libretroshare/src/services/p3gxschannels.cc @@ -245,6 +245,7 @@ void p3GxsChannels::notifyChanges(std::vector &changes) for(it = changes.begin(); it != changes.end(); ++it) { RsGxsMsgChange *msgChange = dynamic_cast(*it); + if (msgChange) { if (msgChange->getType() == RsGxsNotify::TYPE_RECEIVED_NEW|| msgChange->getType() == RsGxsNotify::TYPE_PUBLISHED) @@ -294,75 +295,84 @@ void p3GxsChannels::notifyChanges(std::vector &changes) } } } - else + + RsGxsGroupChange *grpChange = dynamic_cast(*it); + + if (grpChange && rsEvents) { - if (rsEvents) + switch (grpChange->getType()) { - RsGxsGroupChange *grpChange = dynamic_cast(*it); - if (grpChange) + default: + case RsGxsNotify::TYPE_PROCESSED: // happens when the group is subscribed + { + std::list &grpList = grpChange->mGrpIdList; + std::list::iterator git; + for (git = grpList.begin(); git != grpList.end(); ++git) { - switch (grpChange->getType()) - { - default: - case RsGxsNotify::TYPE_PROCESSED: // happens when the group is subscribed - { - std::list &grpList = grpChange->mGrpIdList; - std::list::iterator git; - for (git = grpList.begin(); git != grpList.end(); ++git) - { - auto ev = std::make_shared(); - ev->mChannelGroupId = *git; - ev->mChannelEventCode = RsChannelEventCode::SUBSCRIBE_STATUS_CHANGED; - rsEvents->postEvent(ev); - } - - } - break; - - case RsGxsNotify::TYPE_PUBLISHED: - case RsGxsNotify::TYPE_RECEIVED_NEW: - { - /* group received */ - std::list &grpList = grpChange->mGrpIdList; - std::list::iterator git; - RS_STACK_MUTEX(mKnownChannelsMutex); - for (git = grpList.begin(); git != grpList.end(); ++git) - { - if(mKnownChannels.find(*git) == mKnownChannels.end()) - { - mKnownChannels.insert(std::make_pair(*git,time(NULL))) ; - IndicateConfigChanged(); - - auto ev = std::make_shared(); - ev->mChannelGroupId = *git; - ev->mChannelEventCode = RsChannelEventCode::NEW_CHANNEL; - rsEvents->postEvent(ev); - } - else - std::cerr << "(II) Not notifying already known channel " << *git << std::endl; - } - break; - } - - case RsGxsNotify::TYPE_RECEIVED_PUBLISHKEY: - { - /* group received */ - std::list &grpList = grpChange->mGrpIdList; - std::list::iterator git; - for (git = grpList.begin(); git != grpList.end(); ++git) - { - auto ev = std::make_shared(); - ev->mChannelGroupId = *git; - ev->mChannelEventCode = RsChannelEventCode::RECEIVED_PUBLISH_KEY; - rsEvents->postEvent(ev); - } - break; - } - } + auto ev = std::make_shared(); + ev->mChannelGroupId = *git; + ev->mChannelEventCode = RsChannelEventCode::SUBSCRIBE_STATUS_CHANGED; + rsEvents->postEvent(ev); } + + } + break; + + case RsGxsNotify::TYPE_PUBLISHED: + case RsGxsNotify::TYPE_RECEIVED_NEW: + { + /* group received */ + std::list &grpList = grpChange->mGrpIdList; + std::list::iterator git; + RS_STACK_MUTEX(mKnownChannelsMutex); + for (git = grpList.begin(); git != grpList.end(); ++git) + { + if(mKnownChannels.find(*git) == mKnownChannels.end()) + { + mKnownChannels.insert(std::make_pair(*git,time(NULL))) ; + IndicateConfigChanged(); + + auto ev = std::make_shared(); + ev->mChannelGroupId = *git; + ev->mChannelEventCode = RsChannelEventCode::NEW_CHANNEL; + rsEvents->postEvent(ev); + } + else + std::cerr << "(II) Not notifying already known channel " << *git << std::endl; + } + break; + } + + case RsGxsNotify::TYPE_RECEIVED_PUBLISHKEY: + { + /* group received */ + std::list &grpList = grpChange->mGrpIdList; + std::list::iterator git; + for (git = grpList.begin(); git != grpList.end(); ++git) + { + auto ev = std::make_shared(); + ev->mChannelGroupId = *git; + ev->mChannelEventCode = RsChannelEventCode::RECEIVED_PUBLISH_KEY; + + rsEvents->postEvent(ev); + } + break; + } } } + RsGxsDistantSearchResultChange *dsrChange = dynamic_cast(*it); + + if(dsrChange && rsEvents) + { + auto ev = std::make_shared(); + 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; } diff --git a/retroshare-gui/src/gui/gxs/GxsGroupFrameDialog.h b/retroshare-gui/src/gui/gxs/GxsGroupFrameDialog.h index cc1fa7843..29a22d781 100644 --- a/retroshare-gui/src/gui/gxs/GxsGroupFrameDialog.h +++ b/retroshare-gui/src/gui/gxs/GxsGroupFrameDialog.h @@ -155,8 +155,6 @@ private: void initUi(); - void updateSearchResults(); - void openGroupInNewTab(const RsGxsGroupId &groupId); void groupSubscribe(bool subscribe); @@ -185,6 +183,8 @@ private: // void loadGroupSummary_CurrentGroup(const uint32_t &token); protected: + void updateSearchResults(); + bool mCountChildMsgs; // Count unread child messages? private: diff --git a/retroshare-gui/src/gui/gxs/RsGxsUpdateBroadcastPage.cpp b/retroshare-gui/src/gui/gxs/RsGxsUpdateBroadcastPage.cpp index 70a9a6fe5..bbb768bcc 100644 --- a/retroshare-gui/src/gui/gxs/RsGxsUpdateBroadcastPage.cpp +++ b/retroshare-gui/src/gui/gxs/RsGxsUpdateBroadcastPage.cpp @@ -42,11 +42,6 @@ void RsGxsUpdateBroadcastPage::setUpdateWhenInvisible(bool update) mBase->setUpdateWhenInvisible(update); } -const std::set& RsGxsUpdateBroadcastPage::getSearchResults() -{ - return mBase->getSearchResults(); -} - const std::set &RsGxsUpdateBroadcastPage::getGrpIdsMeta() { return mBase->getGrpIdsMeta(); diff --git a/retroshare-gui/src/gui/gxs/RsGxsUpdateBroadcastPage.h b/retroshare-gui/src/gui/gxs/RsGxsUpdateBroadcastPage.h index 3a37c06cd..ebf1000af 100644 --- a/retroshare-gui/src/gui/gxs/RsGxsUpdateBroadcastPage.h +++ b/retroshare-gui/src/gui/gxs/RsGxsUpdateBroadcastPage.h @@ -51,7 +51,8 @@ public: const std::map > &getMsgIds(); const std::map > &getMsgIdsMeta(); void getAllMsgIds(std::map > &msgIds); - const std::set& getSearchResults(); + + virtual const std::set getSearchResults() const { return std::set(); } // overload this for subclasses that provide distant search protected: virtual void showEvent(QShowEvent *event); diff --git a/retroshare-gui/src/gui/gxschannels/GxsChannelDialog.cpp b/retroshare-gui/src/gui/gxschannels/GxsChannelDialog.cpp index 64ed0f8e6..e8534e8f7 100644 --- a/retroshare-gui/src/gui/gxschannels/GxsChannelDialog.cpp +++ b/retroshare-gui/src/gui/gxschannels/GxsChannelDialog.cpp @@ -76,6 +76,11 @@ void GxsChannelDialog::handleEvent_main_thread(std::shared_ptr ev updateMessageSummaryList(e->mChannelGroupId); 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); diff --git a/retroshare-gui/src/gui/gxschannels/GxsChannelDialog.h b/retroshare-gui/src/gui/gxschannels/GxsChannelDialog.h index 4c9c6eb95..1ab59ca1e 100644 --- a/retroshare-gui/src/gui/gxschannels/GxsChannelDialog.h +++ b/retroshare-gui/src/gui/gxschannels/GxsChannelDialog.h @@ -48,6 +48,7 @@ protected: virtual QString getHelpString() const ; virtual void groupInfoToGroupItemInfo(const RsGroupMetaData &groupInfo, GroupItemInfo &groupItemInfo, const RsUserdata *userdata); virtual bool getDistantSearchResults(TurtleRequestId id, std::map& group_infos); + virtual const std::set getSearchResults() const override { return mSearchResults ; } virtual TurtleRequestId distantSearch(const QString& search_string) ; virtual void checkRequestGroup(const RsGxsGroupId& grpId) ; @@ -76,6 +77,8 @@ private: void handleEvent_main_thread(std::shared_ptr event); + std::set mSearchResults; + RsEventsHandlerId_t mEventHandlerId; };