mirror of
https://github.com/RetroShare/RetroShare.git
synced 2024-10-01 02:35:48 -04:00
fixed model update when new vote is posted by user
This commit is contained in:
parent
364e9ffdd2
commit
0e4d438066
@ -48,7 +48,7 @@ public:
|
|||||||
TYPE_UPDATED = 0x07,
|
TYPE_UPDATED = 0x07,
|
||||||
TYPE_MESSAGE_DELETED = 0x08,
|
TYPE_MESSAGE_DELETED = 0x08,
|
||||||
TYPE_GROUP_DELETED = 0x09,
|
TYPE_GROUP_DELETED = 0x09,
|
||||||
};
|
};
|
||||||
|
|
||||||
virtual NotifyType getType() = 0;
|
virtual NotifyType getType() = 0;
|
||||||
|
|
||||||
|
@ -115,6 +115,7 @@ enum class RsPostedEventCode: uint8_t
|
|||||||
UPDATED_MESSAGE = 0x05,
|
UPDATED_MESSAGE = 0x05,
|
||||||
READ_STATUS_CHANGED = 0x06,
|
READ_STATUS_CHANGED = 0x06,
|
||||||
STATISTICS_CHANGED = 0x07,
|
STATISTICS_CHANGED = 0x07,
|
||||||
|
MESSAGE_VOTES_UPDATED = 0x08,
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
@ -127,6 +128,7 @@ struct RsGxsPostedEvent: RsEvent
|
|||||||
RsPostedEventCode mPostedEventCode;
|
RsPostedEventCode mPostedEventCode;
|
||||||
RsGxsGroupId mPostedGroupId;
|
RsGxsGroupId mPostedGroupId;
|
||||||
RsGxsMessageId mPostedMsgId;
|
RsGxsMessageId mPostedMsgId;
|
||||||
|
RsGxsMessageId mPostedThreadId;
|
||||||
|
|
||||||
///* @see RsEvent @see RsSerializable
|
///* @see RsEvent @see RsSerializable
|
||||||
void serial_process( RsGenericSerializer::SerializeJob j,RsGenericSerializer::SerializeContext& ctx) override
|
void serial_process( RsGenericSerializer::SerializeJob j,RsGenericSerializer::SerializeContext& ctx) override
|
||||||
|
@ -38,6 +38,7 @@
|
|||||||
/****
|
/****
|
||||||
* #define POSTBASE_DEBUG 1
|
* #define POSTBASE_DEBUG 1
|
||||||
****/
|
****/
|
||||||
|
#define POSTBASE_DEBUG 1
|
||||||
|
|
||||||
#define POSTBASE_BACKGROUND_PROCESSING 0x0002
|
#define POSTBASE_BACKGROUND_PROCESSING 0x0002
|
||||||
#define PROCESSING_START_PERIOD 30
|
#define PROCESSING_START_PERIOD 30
|
||||||
@ -88,101 +89,123 @@ void p3PostBase::notifyChanges(std::vector<RsGxsNotify *> &changes)
|
|||||||
#endif
|
#endif
|
||||||
|
|
||||||
for(auto it = changes.begin(); it != changes.end(); ++it)
|
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
|
#ifdef POSTBASE_DEBUG
|
||||||
std::cerr << "p3PostBase::notifyChanges() Found Message Change Notification";
|
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;
|
||||||
std::cerr << std::endl;
|
|
||||||
#endif
|
#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
|
#ifdef POSTBASE_DEBUG
|
||||||
std::cerr << "p3PostBase::notifyChanges() Msgs for Group: " << mit->first;
|
std::cerr << "p3PostBase::notifyChanges() Found Message Change Notification: PROCESSED ID=" << msgChange->mMsgId << " in group " << msgChange->mGroupId << std::endl;
|
||||||
std::cerr << std::endl;
|
|
||||||
#endif
|
#endif
|
||||||
// To start with we are just going to trigger updates on these groups.
|
}
|
||||||
// FUTURE OPTIMISATION.
|
break;
|
||||||
// It could be taken a step further and directly request these msgs for an update.
|
default:
|
||||||
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)
|
|
||||||
{
|
|
||||||
#ifdef POSTBASE_DEBUG
|
#ifdef POSTBASE_DEBUG
|
||||||
std::cerr << "p3PostBase::notifyChanges() Found Group Change Notification";
|
std::cerr << "p3PostBase::notifyChanges() Found Message Change Notification: type " << msgChange->getType() << " (ignored) " << msgChange->mMsgId << std::endl;
|
||||||
std::cerr << 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
|
#endif
|
||||||
const RsGxsGroupId& group_id(grpChange->mGroupId);
|
const RsGxsGroupId& group_id(grpChange->mGroupId);
|
||||||
|
|
||||||
switch(grpChange->getType())
|
switch(grpChange->getType())
|
||||||
{
|
{
|
||||||
case RsGxsNotify::TYPE_PROCESSED: // happens when the group is subscribed
|
case RsGxsNotify::TYPE_PROCESSED: // happens when the group is subscribed
|
||||||
{
|
{
|
||||||
auto ev = std::make_shared<RsGxsPostedEvent>();
|
auto ev = std::make_shared<RsGxsPostedEvent>();
|
||||||
ev->mPostedGroupId = group_id;
|
ev->mPostedGroupId = group_id;
|
||||||
ev->mPostedEventCode = RsPostedEventCode::SUBSCRIBE_STATUS_CHANGED;
|
ev->mPostedEventCode = RsPostedEventCode::SUBSCRIBE_STATUS_CHANGED;
|
||||||
rsEvents->postEvent(ev);
|
rsEvents->postEvent(ev);
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case RsGxsNotify::TYPE_STATISTICS_CHANGED:
|
case RsGxsNotify::TYPE_STATISTICS_CHANGED:
|
||||||
{
|
{
|
||||||
auto ev = std::make_shared<RsGxsPostedEvent>();
|
auto ev = std::make_shared<RsGxsPostedEvent>();
|
||||||
ev->mPostedGroupId = group_id;
|
ev->mPostedGroupId = group_id;
|
||||||
ev->mPostedEventCode = RsPostedEventCode::STATISTICS_CHANGED;
|
ev->mPostedEventCode = RsPostedEventCode::STATISTICS_CHANGED;
|
||||||
rsEvents->postEvent(ev);
|
rsEvents->postEvent(ev);
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case RsGxsNotify::TYPE_PUBLISHED:
|
case RsGxsNotify::TYPE_PUBLISHED:
|
||||||
case RsGxsNotify::TYPE_RECEIVED_NEW:
|
case RsGxsNotify::TYPE_RECEIVED_NEW:
|
||||||
{
|
{
|
||||||
/* group received */
|
/* group received */
|
||||||
|
|
||||||
if(mKnownPosted.find(group_id) == mKnownPosted.end())
|
if(mKnownPosted.find(group_id) == mKnownPosted.end())
|
||||||
{
|
{
|
||||||
mKnownPosted.insert(std::make_pair(group_id, time(nullptr)));
|
mKnownPosted.insert(std::make_pair(group_id, time(nullptr)));
|
||||||
IndicateConfigChanged();
|
IndicateConfigChanged();
|
||||||
|
|
||||||
auto ev = std::make_shared<RsGxsPostedEvent>();
|
auto ev = std::make_shared<RsGxsPostedEvent>();
|
||||||
ev->mPostedGroupId = group_id;
|
ev->mPostedGroupId = group_id;
|
||||||
ev->mPostedEventCode = RsPostedEventCode::NEW_POSTED_GROUP;
|
ev->mPostedEventCode = RsPostedEventCode::NEW_POSTED_GROUP;
|
||||||
rsEvents->postEvent(ev);
|
rsEvents->postEvent(ev);
|
||||||
|
|
||||||
#ifdef POSTBASE_DEBUG
|
#ifdef POSTBASE_DEBUG
|
||||||
std::cerr << "p3PostBase::notifyChanges() Incoming Group: " << group_id;
|
std::cerr << "p3PostBase::notifyChanges() Incoming Group: " << group_id;
|
||||||
std::cerr << std::endl;
|
std::cerr << std::endl;
|
||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
RsInfo() << __PRETTY_FUNCTION__
|
RsInfo() << __PRETTY_FUNCTION__
|
||||||
<< " Not notifying already known forum "
|
<< " Not notifying already known forum "
|
||||||
<< group_id << std::endl;
|
<< group_id << std::endl;
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
|
|
||||||
default:
|
default:
|
||||||
RsErr() << " Got a GXS event of type " << grpChange->getType() << " Currently not handled." << std::endl;
|
RsErr() << " Got a GXS event of type " << grpChange->getType() << " Currently not handled." << std::endl;
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
delete *it;
|
delete *it;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void p3PostBase::service_tick()
|
void p3PostBase::service_tick()
|
||||||
|
@ -53,7 +53,7 @@ RsPostedPostsModel::RsPostedPostsModel(QObject *parent)
|
|||||||
rsEvents->registerEventsHandler( [this](std::shared_ptr<const RsEvent> event)
|
rsEvents->registerEventsHandler( [this](std::shared_ptr<const RsEvent> event)
|
||||||
{
|
{
|
||||||
RsQThreadUtils::postToObject([=](){ handleEvent_main_thread(event); }, this );
|
RsQThreadUtils::postToObject([=](){ handleEvent_main_thread(event); }, this );
|
||||||
}, mEventHandlerId, RsEventType::GXS_CHANNELS );
|
}, mEventHandlerId, RsEventType::GXS_POSTED);
|
||||||
}
|
}
|
||||||
|
|
||||||
RsPostedPostsModel::~RsPostedPostsModel()
|
RsPostedPostsModel::~RsPostedPostsModel()
|
||||||
@ -71,7 +71,9 @@ void RsPostedPostsModel::handleEvent_main_thread(std::shared_ptr<const RsEvent>
|
|||||||
switch(e->mPostedEventCode)
|
switch(e->mPostedEventCode)
|
||||||
{
|
{
|
||||||
case RsPostedEventCode::UPDATED_MESSAGE:
|
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:
|
// 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];
|
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);
|
},this);
|
||||||
|
Loading…
Reference in New Issue
Block a user