From 0e4d438066fb45929b01d88d98cfd00247a082f7 Mon Sep 17 00:00:00 2001 From: csoler Date: Thu, 17 Sep 2020 21:08:07 +0200 Subject: [PATCH] fixed model update when new vote is posted by user --- libretroshare/src/gxs/rsgxsnotify.h | 2 +- libretroshare/src/retroshare/rsposted.h | 2 + libretroshare/src/services/p3postbase.cc | 171 ++++++++++-------- .../src/gui/Posted/PostedPostsModel.cpp | 11 +- 4 files changed, 108 insertions(+), 78 deletions(-) diff --git a/libretroshare/src/gxs/rsgxsnotify.h b/libretroshare/src/gxs/rsgxsnotify.h index a6fd4c6fb..71db32ebc 100644 --- a/libretroshare/src/gxs/rsgxsnotify.h +++ b/libretroshare/src/gxs/rsgxsnotify.h @@ -48,7 +48,7 @@ public: TYPE_UPDATED = 0x07, TYPE_MESSAGE_DELETED = 0x08, TYPE_GROUP_DELETED = 0x09, - }; + }; virtual NotifyType getType() = 0; diff --git a/libretroshare/src/retroshare/rsposted.h b/libretroshare/src/retroshare/rsposted.h index 71350a826..142707eb7 100644 --- a/libretroshare/src/retroshare/rsposted.h +++ b/libretroshare/src/retroshare/rsposted.h @@ -115,6 +115,7 @@ enum class RsPostedEventCode: uint8_t UPDATED_MESSAGE = 0x05, READ_STATUS_CHANGED = 0x06, STATISTICS_CHANGED = 0x07, + MESSAGE_VOTES_UPDATED = 0x08, }; @@ -127,6 +128,7 @@ struct RsGxsPostedEvent: RsEvent RsPostedEventCode mPostedEventCode; RsGxsGroupId mPostedGroupId; RsGxsMessageId mPostedMsgId; + RsGxsMessageId mPostedThreadId; ///* @see RsEvent @see RsSerializable void serial_process( RsGenericSerializer::SerializeJob j,RsGenericSerializer::SerializeContext& ctx) override diff --git a/libretroshare/src/services/p3postbase.cc b/libretroshare/src/services/p3postbase.cc index c4c96f3b5..5c25ca52c 100644 --- a/libretroshare/src/services/p3postbase.cc +++ b/libretroshare/src/services/p3postbase.cc @@ -38,6 +38,7 @@ /**** * #define POSTBASE_DEBUG 1 ****/ +#define POSTBASE_DEBUG 1 #define POSTBASE_BACKGROUND_PROCESSING 0x0002 #define PROCESSING_START_PERIOD 30 @@ -88,101 +89,123 @@ void p3PostBase::notifyChanges(std::vector &changes) #endif for(auto it = changes.begin(); it != changes.end(); ++it) - { - RsGxsMsgChange *msgChange = dynamic_cast(*it); + { + RsGxsMsgChange *msgChange = dynamic_cast(*it); - if (msgChange) - { + if(msgChange) + { + // To start with we are just going to trigger updates on these groups. + // FUTURE OPTIMISATION. + // It could be taken a step further and directly request these msgs for an update. + addGroupForProcessing(msgChange->mGroupId); + + if (rsEvents) + { + switch(msgChange->getType()) + { + case RsGxsNotify::TYPE_RECEIVED_NEW: + case RsGxsNotify::TYPE_PUBLISHED: + { + auto ev = std::make_shared(); + ev->mPostedMsgId = msgChange->mMsgId; + ev->mPostedThreadId = msgChange->mNewMsgItem->meta.mThreadId; + ev->mPostedGroupId = msgChange->mGroupId; + ev->mPostedEventCode = RsPostedEventCode::NEW_MESSAGE; + rsEvents->postEvent(ev); #ifdef POSTBASE_DEBUG - std::cerr << "p3PostBase::notifyChanges() Found Message Change Notification"; - std::cerr << std::endl; + std::cerr << "p3PostBase::notifyChanges() Found Message Change Notification: NEW/PUBLISHED ID=" << msgChange->mMsgId << " in group " << msgChange->mGroupId << ", thread ID = " << msgChange->mNewMsgItem->meta.mThreadId << std::endl; #endif + } + break; + + case RsGxsNotify::TYPE_PROCESSED: + { + auto ev = std::make_shared(); + ev->mPostedMsgId = msgChange->mMsgId; + ev->mPostedGroupId = msgChange->mGroupId; + ev->mPostedEventCode = RsPostedEventCode::MESSAGE_VOTES_UPDATED; + rsEvents->postEvent(ev); #ifdef POSTBASE_DEBUG - std::cerr << "p3PostBase::notifyChanges() Msgs for Group: " << mit->first; - std::cerr << std::endl; + std::cerr << "p3PostBase::notifyChanges() Found Message Change Notification: PROCESSED ID=" << msgChange->mMsgId << " in group " << msgChange->mGroupId << std::endl; #endif - // To start with we are just going to trigger updates on these groups. - // FUTURE OPTIMISATION. - // It could be taken a step further and directly request these msgs for an update. - addGroupForProcessing(msgChange->mGroupId); - - if (rsEvents && (msgChange->getType() == RsGxsNotify::TYPE_RECEIVED_NEW || msgChange->getType() == RsGxsNotify::TYPE_PUBLISHED)) - { - auto ev = std::make_shared(); - ev->mPostedMsgId = msgChange->mMsgId; - ev->mPostedGroupId = msgChange->mGroupId; - ev->mPostedEventCode = RsPostedEventCode::NEW_MESSAGE; - rsEvents->postEvent(ev); - } - } - - RsGxsGroupChange *grpChange = dynamic_cast(*it); - - /* pass on Group Changes to GUI */ - if (grpChange && rsEvents) - { + } + break; + default: #ifdef POSTBASE_DEBUG - std::cerr << "p3PostBase::notifyChanges() Found Group Change Notification"; - std::cerr << std::endl; + std::cerr << "p3PostBase::notifyChanges() Found Message Change Notification: type " << msgChange->getType() << " (ignored) " << msgChange->mMsgId << std::endl; +#endif + break; + } + } + } + + RsGxsGroupChange *grpChange = dynamic_cast(*it); + + /* pass on Group Changes to GUI */ + if (grpChange && rsEvents) + { +#ifdef POSTBASE_DEBUG + std::cerr << "p3PostBase::notifyChanges() Found Group Change Notification"; + std::cerr << std::endl; #endif const RsGxsGroupId& group_id(grpChange->mGroupId); switch(grpChange->getType()) - { - case RsGxsNotify::TYPE_PROCESSED: // happens when the group is subscribed - { - auto ev = std::make_shared(); - ev->mPostedGroupId = group_id; - ev->mPostedEventCode = RsPostedEventCode::SUBSCRIBE_STATUS_CHANGED; - rsEvents->postEvent(ev); - } - break; + { + case RsGxsNotify::TYPE_PROCESSED: // happens when the group is subscribed + { + auto ev = std::make_shared(); + ev->mPostedGroupId = group_id; + ev->mPostedEventCode = RsPostedEventCode::SUBSCRIBE_STATUS_CHANGED; + rsEvents->postEvent(ev); + } + break; - case RsGxsNotify::TYPE_STATISTICS_CHANGED: - { - auto ev = std::make_shared(); - ev->mPostedGroupId = group_id; - ev->mPostedEventCode = RsPostedEventCode::STATISTICS_CHANGED; - rsEvents->postEvent(ev); - } - break; + case RsGxsNotify::TYPE_STATISTICS_CHANGED: + { + auto ev = std::make_shared(); + ev->mPostedGroupId = group_id; + ev->mPostedEventCode = RsPostedEventCode::STATISTICS_CHANGED; + rsEvents->postEvent(ev); + } + break; - case RsGxsNotify::TYPE_PUBLISHED: - case RsGxsNotify::TYPE_RECEIVED_NEW: - { - /* group received */ + case RsGxsNotify::TYPE_PUBLISHED: + case RsGxsNotify::TYPE_RECEIVED_NEW: + { + /* group received */ - if(mKnownPosted.find(group_id) == mKnownPosted.end()) - { - mKnownPosted.insert(std::make_pair(group_id, time(nullptr))); - IndicateConfigChanged(); + if(mKnownPosted.find(group_id) == mKnownPosted.end()) + { + mKnownPosted.insert(std::make_pair(group_id, time(nullptr))); + IndicateConfigChanged(); - auto ev = std::make_shared(); - ev->mPostedGroupId = group_id; - ev->mPostedEventCode = RsPostedEventCode::NEW_POSTED_GROUP; - rsEvents->postEvent(ev); + auto ev = std::make_shared(); + ev->mPostedGroupId = group_id; + ev->mPostedEventCode = RsPostedEventCode::NEW_POSTED_GROUP; + rsEvents->postEvent(ev); #ifdef POSTBASE_DEBUG - std::cerr << "p3PostBase::notifyChanges() Incoming Group: " << group_id; - std::cerr << std::endl; + std::cerr << "p3PostBase::notifyChanges() Incoming Group: " << group_id; + std::cerr << std::endl; #endif - } - else - RsInfo() << __PRETTY_FUNCTION__ - << " Not notifying already known forum " - << group_id << std::endl; - } - break; + } + else + RsInfo() << __PRETTY_FUNCTION__ + << " Not notifying already known forum " + << group_id << std::endl; + } + break; - default: - RsErr() << " Got a GXS event of type " << grpChange->getType() << " Currently not handled." << std::endl; - break; - } - } + default: + RsErr() << " Got a GXS event of type " << grpChange->getType() << " Currently not handled." << std::endl; + break; + } + } delete *it; - } + } } void p3PostBase::service_tick() diff --git a/retroshare-gui/src/gui/Posted/PostedPostsModel.cpp b/retroshare-gui/src/gui/Posted/PostedPostsModel.cpp index 751bd5db6..94eea0ae1 100644 --- a/retroshare-gui/src/gui/Posted/PostedPostsModel.cpp +++ b/retroshare-gui/src/gui/Posted/PostedPostsModel.cpp @@ -53,7 +53,7 @@ RsPostedPostsModel::RsPostedPostsModel(QObject *parent) rsEvents->registerEventsHandler( [this](std::shared_ptr event) { RsQThreadUtils::postToObject([=](){ handleEvent_main_thread(event); }, this ); - }, mEventHandlerId, RsEventType::GXS_CHANNELS ); + }, mEventHandlerId, RsEventType::GXS_POSTED); } RsPostedPostsModel::~RsPostedPostsModel() @@ -71,7 +71,9 @@ void RsPostedPostsModel::handleEvent_main_thread(std::shared_ptr switch(e->mPostedEventCode) { case RsPostedEventCode::UPDATED_MESSAGE: - case RsPostedEventCode::READ_STATUS_CHANGED: + case RsPostedEventCode::READ_STATUS_CHANGED: + case RsPostedEventCode::MESSAGE_VOTES_UPDATED: + case RsPostedEventCode::NEW_MESSAGE: { // Normally we should just emit dataChanged() on the index of the data that has changed: // @@ -105,7 +107,10 @@ void RsPostedPostsModel::handleEvent_main_thread(std::shared_ptr { mPosts[j] = posts[i]; - emit dataChanged(createIndex(0,0,(void*)NULL), createIndex(mFilteredPosts.size(),0,(void*)NULL)); + //emit dataChanged(createIndex(0,0,(void*)NULL), createIndex(mFilteredPosts.size(),0,(void*)NULL)); + + preMods(); + postMods(); } } },this);