fixed notifications in posted

This commit is contained in:
csoler 2020-02-09 20:54:11 +01:00
parent 62c5cda7f0
commit 41a81fa5d1
No known key found for this signature in database
GPG key ID: 7BCA522266C0804C
3 changed files with 30 additions and 7 deletions

View file

@ -44,13 +44,6 @@ class p3Posted: public p3PostBase, public RsPosted
p3Posted(RsGeneralDataService* gds, RsNetworkExchangeService* nes, RsGixs* gixs); p3Posted(RsGeneralDataService* gds, RsNetworkExchangeService* nes, RsGixs* gixs);
virtual RsServiceInfo getServiceInfo(); virtual RsServiceInfo getServiceInfo();
protected:
virtual void notifyChanges(std::vector<RsGxsNotify*>& changes)
{
return p3PostBase::notifyChanges(changes);
}
public: public:
// Posted Specific DataTypes. // Posted Specific DataTypes.

View file

@ -105,6 +105,11 @@ PostedListWidget::PostedListWidget(const RsGxsGroupId &postedId, QWidget *parent
/* load settings */ /* load settings */
processSettings(true); processSettings(true);
mEventHandlerId = 0;
// Needs to be asynced because this function is likely to be called by another thread!
rsEvents->registerEventsHandler(RsEventType::GXS_POSTED, [this](std::shared_ptr<const RsEvent> event) { RsQThreadUtils::postToObject( [=]() { handleEvent_main_thread(event); }, this ); }, mEventHandlerId );
/* Initialize GUI */ /* Initialize GUI */
setGroupId(postedId); setGroupId(postedId);
} }
@ -116,6 +121,28 @@ PostedListWidget::~PostedListWidget()
delete(ui); delete(ui);
} }
void PostedListWidget::handleEvent_main_thread(std::shared_ptr<const RsEvent> event)
{
const RsGxsPostedEvent *e = dynamic_cast<const RsGxsPostedEvent*>(event.get());
if(!e)
return;
switch(e->mPostedEventCode)
{
case RsPostedEventCode::UPDATED_POSTED_GROUP:
case RsPostedEventCode::NEW_POSTED_GROUP:
case RsPostedEventCode::UPDATED_MESSAGE:
case RsPostedEventCode::NEW_MESSAGE:
if(e->mPostedGroupId == groupId())
updateDisplay(true);
break;
default:
break;
}
}
void PostedListWidget::processSettings(bool load) void PostedListWidget::processSettings(bool load)
{ {
Settings->beginGroup(QString("PostedListWidget")); Settings->beginGroup(QString("PostedListWidget"));

View file

@ -57,6 +57,8 @@ public:
virtual void loadRequest(const TokenQueue *queue, const TokenRequest &req); virtual void loadRequest(const TokenQueue *queue, const TokenRequest &req);
protected: protected:
void handleEvent_main_thread(std::shared_ptr<const RsEvent> event);
/* GxsMessageFramePostWidget */ /* GxsMessageFramePostWidget */
virtual bool insertGroupData(const uint32_t &token, RsGroupMetaData &metaData); virtual bool insertGroupData(const uint32_t &token, RsGroupMetaData &metaData);
virtual void insertAllPosts(const uint32_t &token, GxsMessageFramePostThread *thread); virtual void insertAllPosts(const uint32_t &token, GxsMessageFramePostThread *thread);
@ -126,6 +128,7 @@ private:
/* UI - from Designer */ /* UI - from Designer */
Ui::PostedListWidget *ui; Ui::PostedListWidget *ui;
RsEventsHandlerId_t mEventHandlerId ;
}; };
#endif #endif