diff --git a/retroshare-gui/src/gui/gxschannels/GxsChannelPostsWidget.cpp b/retroshare-gui/src/gui/gxschannels/GxsChannelPostsWidget.cpp index 9a3afbc3c..3ec13eb1c 100644 --- a/retroshare-gui/src/gui/gxschannels/GxsChannelPostsWidget.cpp +++ b/retroshare-gui/src/gui/gxschannels/GxsChannelPostsWidget.cpp @@ -128,6 +128,35 @@ GxsChannelPostsWidget::GxsChannelPostsWidget(const RsGxsGroupId &channelId, QWid setAutoDownload(false); settingsChanged(); setGroupId(channelId); + + mEventHandlerId = 0; + // Needs to be asynced because this function is likely to be called by another thread! + + rsEvents->registerEventsHandler( [this](std::shared_ptr event) { RsQThreadUtils::postToObject( [=]() { handleEvent_main_thread(event); }, this ); }, mEventHandlerId ); +} + +void GxsChannelPostsWidget::handleEvent_main_thread(std::shared_ptr event) +{ + if(event->mType == RsEventType::GXS_CHANNELS) + { + const RsGxsChannelEvent *e = dynamic_cast(event.get()); + + if(!e) + return; + + switch(e->mChannelEventCode) + { + case RsGxsChannelEvent::UPDATED_CHANNEL: + case RsGxsChannelEvent::NEW_CHANNEL: + case RsGxsChannelEvent::UPDATED_MESSAGE: + case RsGxsChannelEvent::NEW_MESSAGE: + if(e->mChannelGroupId == mChannelGroupId) + updateDisplay(true); + break; + default: + break; + } + } } GxsChannelPostsWidget::~GxsChannelPostsWidget() @@ -712,6 +741,7 @@ bool GxsChannelPostsWidget::insertGroupData(const uint32_t &token, RsGroupMetaDa { insertChannelDetails(groups[0]); metaData = groups[0].mMeta; + mChannelGroupId = groups[0].mMeta.mGroupId; return true; } else @@ -721,6 +751,7 @@ bool GxsChannelPostsWidget::insertGroupData(const uint32_t &token, RsGroupMetaDa { insertChannelDetails(distant_group); metaData = distant_group.mMeta; + mChannelGroupId = distant_group.mMeta.mGroupId; return true ; } } diff --git a/retroshare-gui/src/gui/gxschannels/GxsChannelPostsWidget.h b/retroshare-gui/src/gui/gxschannels/GxsChannelPostsWidget.h index 40160146c..a4723c18f 100644 --- a/retroshare-gui/src/gui/gxschannels/GxsChannelPostsWidget.h +++ b/retroshare-gui/src/gui/gxschannels/GxsChannelPostsWidget.h @@ -97,11 +97,14 @@ private: void insertChannelPosts(std::vector &posts, GxsMessageFramePostThread *thread, bool related); void createPostItem(const RsGxsChannelPost &post, bool related); + void handleEvent_main_thread(std::shared_ptr event); private: QAction *mAutoDownloadAction; bool mUseThread; + RsGxsGroupId mChannelGroupId; + RsEventsHandlerId_t mEventHandlerId ; /* UI - from Designer */ Ui::GxsChannelPostsWidget *ui; diff --git a/retroshare-gui/src/gui/gxsforums/GxsForumThreadWidget.cpp b/retroshare-gui/src/gui/gxsforums/GxsForumThreadWidget.cpp index 37681273d..8cd399b48 100644 --- a/retroshare-gui/src/gui/gxsforums/GxsForumThreadWidget.cpp +++ b/retroshare-gui/src/gui/gxsforums/GxsForumThreadWidget.cpp @@ -432,6 +432,35 @@ GxsForumThreadWidget::GxsForumThreadWidget(const RsGxsGroupId &forumId, QWidget #ifdef SUSPENDED_CODE ui->threadTreeWidget->enableColumnCustomize(true); #endif + + mEventHandlerId = 0; + // Needs to be asynced because this function is likely to be called by another thread! + + rsEvents->registerEventsHandler( [this](std::shared_ptr event) { RsQThreadUtils::postToObject( [=]() { handleEvent_main_thread(event); }, this ); }, mEventHandlerId ); +} + +void GxsForumThreadWidget::handleEvent_main_thread(std::shared_ptr event) +{ + if(event->mType == RsEventType::GXS_FORUMS) + { + const RsGxsForumEvent *e = dynamic_cast(event.get()); + + if(!e) + return; + + switch(e->mForumEventCode) + { + case RsGxsForumEvent::UPDATED_FORUM: + case RsGxsForumEvent::NEW_FORUM: + case RsGxsForumEvent::UPDATED_MESSAGE: + case RsGxsForumEvent::NEW_MESSAGE: + if(e->mForumGroupId == mForumGroup.mMeta.mGroupId) + updateDisplay(true); + break; + default: + break; + } + } } void GxsForumThreadWidget::blank() diff --git a/retroshare-gui/src/gui/gxsforums/GxsForumThreadWidget.h b/retroshare-gui/src/gui/gxsforums/GxsForumThreadWidget.h index 83fb0ea37..a548cda07 100644 --- a/retroshare-gui/src/gui/gxsforums/GxsForumThreadWidget.h +++ b/retroshare-gui/src/gui/gxsforums/GxsForumThreadWidget.h @@ -172,6 +172,8 @@ private: void updateMessageData(const RsGxsMessageId& msgId); void updateForumDescription(); + void handleEvent_main_thread(std::shared_ptr event); + private: RsGxsGroupId mLastForumID; RsGxsMessageId mThreadId; @@ -201,6 +203,7 @@ private: QList mSavedExpandedMessages; Ui::GxsForumThreadWidget *ui; + RsEventsHandlerId_t mEventHandlerId; }; #endif // GXSFORUMTHREADWIDGET_H