added notifications for channel posts

This commit is contained in:
csoler 2019-12-16 23:52:09 +01:00
parent a54cf981a6
commit c348366eef
No known key found for this signature in database
GPG Key ID: 7BCA522266C0804C
4 changed files with 66 additions and 0 deletions

View File

@ -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<const RsEvent> event) { RsQThreadUtils::postToObject( [=]() { handleEvent_main_thread(event); }, this ); }, mEventHandlerId );
}
void GxsChannelPostsWidget::handleEvent_main_thread(std::shared_ptr<const RsEvent> event)
{
if(event->mType == RsEventType::GXS_CHANNELS)
{
const RsGxsChannelEvent *e = dynamic_cast<const RsGxsChannelEvent*>(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 ;
}
}

View File

@ -97,11 +97,14 @@ private:
void insertChannelPosts(std::vector<RsGxsChannelPost> &posts, GxsMessageFramePostThread *thread, bool related);
void createPostItem(const RsGxsChannelPost &post, bool related);
void handleEvent_main_thread(std::shared_ptr<const RsEvent> event);
private:
QAction *mAutoDownloadAction;
bool mUseThread;
RsGxsGroupId mChannelGroupId;
RsEventsHandlerId_t mEventHandlerId ;
/* UI - from Designer */
Ui::GxsChannelPostsWidget *ui;

View File

@ -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<const RsEvent> event) { RsQThreadUtils::postToObject( [=]() { handleEvent_main_thread(event); }, this ); }, mEventHandlerId );
}
void GxsForumThreadWidget::handleEvent_main_thread(std::shared_ptr<const RsEvent> event)
{
if(event->mType == RsEventType::GXS_FORUMS)
{
const RsGxsForumEvent *e = dynamic_cast<const RsGxsForumEvent*>(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()

View File

@ -172,6 +172,8 @@ private:
void updateMessageData(const RsGxsMessageId& msgId);
void updateForumDescription();
void handleEvent_main_thread(std::shared_ptr<const RsEvent> event);
private:
RsGxsGroupId mLastForumID;
RsGxsMessageId mThreadId;
@ -201,6 +203,7 @@ private:
QList<RsGxsMessageId> mSavedExpandedMessages;
Ui::GxsForumThreadWidget *ui;
RsEventsHandlerId_t mEventHandlerId;
};
#endif // GXSFORUMTHREADWIDGET_H