From 315fb77d6346dfd45ec242e63b21507c625a7b61 Mon Sep 17 00:00:00 2001 From: csoler Date: Sat, 28 Oct 2023 21:03:21 +0200 Subject: [PATCH] fixed forum and chnanel group feed items reacting to changes to the channel/forum group --- .../src/gui/feeds/GxsChannelGroupItem.cpp | 24 +++++++++++++++ .../src/gui/feeds/GxsChannelGroupItem.h | 1 + .../src/gui/feeds/GxsChannelGroupItem.ui | 2 +- .../src/gui/feeds/GxsForumGroupItem.cpp | 29 +++++++++++++++++-- .../src/gui/feeds/GxsForumGroupItem.h | 11 ++++--- 5 files changed, 60 insertions(+), 7 deletions(-) diff --git a/retroshare-gui/src/gui/feeds/GxsChannelGroupItem.cpp b/retroshare-gui/src/gui/feeds/GxsChannelGroupItem.cpp index e9c38a022..dc20c3aee 100644 --- a/retroshare-gui/src/gui/feeds/GxsChannelGroupItem.cpp +++ b/retroshare-gui/src/gui/feeds/GxsChannelGroupItem.cpp @@ -39,6 +39,29 @@ GxsChannelGroupItem::GxsChannelGroupItem(FeedHolder *feedHolder, uint32_t feedId setup(); requestGroup(); + + mEventHandlerId = 0; + rsEvents->registerEventsHandler( [this](std::shared_ptr event) + { + RsQThreadUtils::postToObject([=]() + { + const auto *e = dynamic_cast(event.get()); + + if(!e || e->mChannelGroupId != this->groupId()) + return; + + switch(e->mChannelEventCode) + { + case RsChannelEventCode::SUBSCRIBE_STATUS_CHANGED: + case RsChannelEventCode::UPDATED_CHANNEL: + case RsChannelEventCode::RECEIVED_PUBLISH_KEY: + loadGroup(); + break; + default: + break; + } + }, this ); + }, mEventHandlerId, RsEventType::GXS_CHANNELS ); } GxsChannelGroupItem::GxsChannelGroupItem(FeedHolder *feedHolder, uint32_t feedId, const RsGxsChannelGroup &group, bool isHome, bool autoUpdate) : @@ -51,6 +74,7 @@ GxsChannelGroupItem::GxsChannelGroupItem(FeedHolder *feedHolder, uint32_t feedId GxsChannelGroupItem::~GxsChannelGroupItem() { + rsEvents->unregisterEventsHandler(mEventHandlerId); delete(ui); } diff --git a/retroshare-gui/src/gui/feeds/GxsChannelGroupItem.h b/retroshare-gui/src/gui/feeds/GxsChannelGroupItem.h index cd7f6510b..8f0a6e332 100644 --- a/retroshare-gui/src/gui/feeds/GxsChannelGroupItem.h +++ b/retroshare-gui/src/gui/feeds/GxsChannelGroupItem.h @@ -66,6 +66,7 @@ private: /** Qt Designer generated object */ Ui::GxsChannelGroupItem *ui; + RsEventsHandlerId_t mEventHandlerId; }; #endif diff --git a/retroshare-gui/src/gui/feeds/GxsChannelGroupItem.ui b/retroshare-gui/src/gui/feeds/GxsChannelGroupItem.ui index 151e6920b..e17f53c48 100644 --- a/retroshare-gui/src/gui/feeds/GxsChannelGroupItem.ui +++ b/retroshare-gui/src/gui/feeds/GxsChannelGroupItem.ui @@ -251,7 +251,7 @@ Qt::NoFocus - Subscribe to Channel + Subscribe this Channel Subscribe diff --git a/retroshare-gui/src/gui/feeds/GxsForumGroupItem.cpp b/retroshare-gui/src/gui/feeds/GxsForumGroupItem.cpp index 43c94a377..23c9c35ac 100644 --- a/retroshare-gui/src/gui/feeds/GxsForumGroupItem.cpp +++ b/retroshare-gui/src/gui/feeds/GxsForumGroupItem.cpp @@ -35,8 +35,9 @@ GxsForumGroupItem::GxsForumGroupItem(FeedHolder *feedHolder, uint32_t feedId, co GxsGroupFeedItem(feedHolder, feedId, groupId, isHome, rsGxsForums, autoUpdate) { setup(); - requestGroup(); + + } GxsForumGroupItem::GxsForumGroupItem(FeedHolder *feedHolder, uint32_t feedId, const RsGxsGroupId &groupId, const std::list& added_moderators,const std::list& removed_moderators,bool isHome, bool autoUpdate): @@ -47,6 +48,29 @@ GxsForumGroupItem::GxsForumGroupItem(FeedHolder *feedHolder, uint32_t feedId, co setup(); requestGroup(); + + mEventHandlerId = 0; + rsEvents->registerEventsHandler( [this](std::shared_ptr event) + { + RsQThreadUtils::postToObject([=]() + { + const auto *e = dynamic_cast(event.get()); + + if(!e || e->mForumGroupId != this->groupId()) + return; + + switch(e->mForumEventCode) + { + case RsForumEventCode::SUBSCRIBE_STATUS_CHANGED: + case RsForumEventCode::UPDATED_FORUM: + case RsForumEventCode::MODERATOR_LIST_CHANGED: + loadGroup(); + break; + default: + break; + } + }, this ); + }, mEventHandlerId, RsEventType::GXS_FORUMS ); } GxsForumGroupItem::GxsForumGroupItem(FeedHolder *feedHolder, uint32_t feedId, const RsGxsForumGroup &group, bool isHome, bool autoUpdate) : @@ -59,7 +83,8 @@ GxsForumGroupItem::GxsForumGroupItem(FeedHolder *feedHolder, uint32_t feedId, co GxsForumGroupItem::~GxsForumGroupItem() { - delete(ui); + rsEvents->unregisterEventsHandler(mEventHandlerId); + delete(ui); } void GxsForumGroupItem::setup() diff --git a/retroshare-gui/src/gui/feeds/GxsForumGroupItem.h b/retroshare-gui/src/gui/feeds/GxsForumGroupItem.h index bfe24f2a7..e09a3cb13 100644 --- a/retroshare-gui/src/gui/feeds/GxsForumGroupItem.h +++ b/retroshare-gui/src/gui/feeds/GxsForumGroupItem.h @@ -22,6 +22,7 @@ #define _GXSFORUMGROUPITEM_H #include +#include #include "gui/gxs/GxsGroupFeedItem.h" namespace Ui { @@ -39,19 +40,19 @@ public: GxsForumGroupItem(FeedHolder *feedHolder, uint32_t feedId, const RsGxsGroupId &groupId, bool isHome, bool autoUpdate); GxsForumGroupItem(FeedHolder *feedHolder, uint32_t feedId, const RsGxsGroupId &groupId, const std::list& added_moderators,const std::list& removed_moderators,bool isHome, bool autoUpdate); GxsForumGroupItem(FeedHolder *feedHolder, uint32_t feedId, const RsGxsForumGroup &group, bool isHome, bool autoUpdate); - ~GxsForumGroupItem(); + virtual ~GxsForumGroupItem() override; bool setGroup(const RsGxsForumGroup &group); uint64_t uniqueIdentifier() const override { return hash_64bits("GxsForumGroupItem " + groupId().toStdString()) ; } protected: /* FeedItem */ - virtual void doExpand(bool open); + virtual void doExpand(bool open) override; /* GxsGroupFeedItem */ - virtual QString groupName(); + virtual QString groupName() override; virtual void loadGroup() override; - virtual RetroShareLink::enumType getLinkType() { return RetroShareLink::TYPE_FORUM; } + virtual RetroShareLink::enumType getLinkType() override { return RetroShareLink::TYPE_FORUM; } private slots: void subscribeForum(); @@ -69,6 +70,8 @@ private: std::list mAddedModerators; std::list mRemovedModerators; + + RsEventsHandlerId_t mEventHandlerId; }; #endif