From dbddf7166f2d6000b21b4711f3a80f17bdf08d11 Mon Sep 17 00:00:00 2001 From: PYRET1C <88980503+PYRET1C@users.noreply.github.com> Date: Tue, 2 May 2023 23:50:37 +0530 Subject: [PATCH] This is the gui part of the commit where the wire feed is refreshed if there is any event published. --- retroshare-gui/src/gui/TheWire/WireDialog.cpp | 42 ++++++++++++++++++- retroshare-gui/src/gui/TheWire/WireDialog.h | 3 ++ 2 files changed, 43 insertions(+), 2 deletions(-) diff --git a/retroshare-gui/src/gui/TheWire/WireDialog.cpp b/retroshare-gui/src/gui/TheWire/WireDialog.cpp index 23031d6ec..98225cf7e 100644 --- a/retroshare-gui/src/gui/TheWire/WireDialog.cpp +++ b/retroshare-gui/src/gui/TheWire/WireDialog.cpp @@ -59,7 +59,7 @@ WireDialog::WireDialog(QWidget *parent) : MainPage(parent), mGroupSet(GROUP_SET_ALL) , mAddDialog(nullptr), mGroupSelected(nullptr), mWireQueue(nullptr) - , mHistoryIndex(-1) + , mHistoryIndex(-1), mEventHandlerId(0) { ui.setupUi(this); @@ -89,6 +89,42 @@ WireDialog::WireDialog(QWidget *parent) // load settings processSettings(true); + + // Needs to be asynced because this function is called by another thread! + rsEvents->registerEventsHandler( + [this](std::shared_ptr event) + { RsQThreadUtils::postToObject([=]() { handleEvent_main_thread(event); }, this ); }, + mEventHandlerId, RsEventType::WIRE ); +} + +void WireDialog::handleEvent_main_thread(std::shared_ptr event) +{ + const RsWireEvent *e = dynamic_cast(event.get()); + + if(e) + switch(e->mWireEventCode) + { + case RsWireEventCode::NEW_POST: // [[fallthrough]]; + refreshGroups(); + break; + case RsWireEventCode::NEW_REPLY: // [[fallthrough]]; + refreshGroups(); + break; + case RsWireEventCode::NEW_LIKE: // [[fallthrough]]; + refreshGroups(); + break; + case RsWireEventCode::NEW_REPUBLISH: // [[fallthrough]]; + refreshGroups(); + break; + case RsWireEventCode::NEW_WIRE: // [[fallthrough]]; + refreshGroups(); + break; + case RsWireEventCode::FOLLOW_STATUS_CHANGED: // [[fallthrough]]; + refreshGroups(); + break; + default: + break; + } } WireDialog::~WireDialog() @@ -97,7 +133,9 @@ WireDialog::~WireDialog() processSettings(false); clearTwitterView(); - delete(mWireQueue); + delete(mWireQueue); + + rsEvents->unregisterEventsHandler(mEventHandlerId); } void WireDialog::processSettings(bool load) diff --git a/retroshare-gui/src/gui/TheWire/WireDialog.h b/retroshare-gui/src/gui/TheWire/WireDialog.h index 8ccf13377..1ac7faebc 100644 --- a/retroshare-gui/src/gui/TheWire/WireDialog.h +++ b/retroshare-gui/src/gui/TheWire/WireDialog.h @@ -164,6 +164,9 @@ private: std::map mAllGroups; std::vector mOwnGroups; + void handleEvent_main_thread(std::shared_ptr event); + RsEventsHandlerId_t mEventHandlerId; + int32_t mHistoryIndex; std::vector mHistory;