fixed model update when new vote is posted by user

This commit is contained in:
csoler 2020-09-17 21:08:07 +02:00
parent 364e9ffdd2
commit 0e4d438066
4 changed files with 108 additions and 78 deletions

View File

@ -48,7 +48,7 @@ public:
TYPE_UPDATED = 0x07,
TYPE_MESSAGE_DELETED = 0x08,
TYPE_GROUP_DELETED = 0x09,
};
};
virtual NotifyType getType() = 0;

View File

@ -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

View File

@ -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<RsGxsNotify *> &changes)
#endif
for(auto it = changes.begin(); it != changes.end(); ++it)
{
RsGxsMsgChange *msgChange = dynamic_cast<RsGxsMsgChange *>(*it);
{
RsGxsMsgChange *msgChange = dynamic_cast<RsGxsMsgChange *>(*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<RsGxsPostedEvent>();
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<RsGxsPostedEvent>();
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<RsGxsPostedEvent>();
ev->mPostedMsgId = msgChange->mMsgId;
ev->mPostedGroupId = msgChange->mGroupId;
ev->mPostedEventCode = RsPostedEventCode::NEW_MESSAGE;
rsEvents->postEvent(ev);
}
}
RsGxsGroupChange *grpChange = dynamic_cast<RsGxsGroupChange *>(*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<RsGxsGroupChange *>(*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<RsGxsPostedEvent>();
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<RsGxsPostedEvent>();
ev->mPostedGroupId = group_id;
ev->mPostedEventCode = RsPostedEventCode::SUBSCRIBE_STATUS_CHANGED;
rsEvents->postEvent(ev);
}
break;
case RsGxsNotify::TYPE_STATISTICS_CHANGED:
{
auto ev = std::make_shared<RsGxsPostedEvent>();
ev->mPostedGroupId = group_id;
ev->mPostedEventCode = RsPostedEventCode::STATISTICS_CHANGED;
rsEvents->postEvent(ev);
}
break;
case RsGxsNotify::TYPE_STATISTICS_CHANGED:
{
auto ev = std::make_shared<RsGxsPostedEvent>();
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<RsGxsPostedEvent>();
ev->mPostedGroupId = group_id;
ev->mPostedEventCode = RsPostedEventCode::NEW_POSTED_GROUP;
rsEvents->postEvent(ev);
auto ev = std::make_shared<RsGxsPostedEvent>();
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()

View File

@ -53,7 +53,7 @@ RsPostedPostsModel::RsPostedPostsModel(QObject *parent)
rsEvents->registerEventsHandler( [this](std::shared_ptr<const RsEvent> 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<const RsEvent>
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<const RsEvent>
{
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);