mirror of
https://github.com/RetroShare/RetroShare.git
synced 2025-02-25 01:10:19 -05:00
fixed updating of data after read status change
This commit is contained in:
parent
ebaf5e63c3
commit
f8deebfc5a
@ -43,7 +43,76 @@ std::ostream& operator<<(std::ostream& o, const QModelIndex& i);// defined elsew
|
|||||||
RsGxsChannelPostsModel::RsGxsChannelPostsModel(QObject *parent)
|
RsGxsChannelPostsModel::RsGxsChannelPostsModel(QObject *parent)
|
||||||
: QAbstractItemModel(parent), mTreeMode(TREE_MODE_PLAIN), mColumns(6)
|
: QAbstractItemModel(parent), mTreeMode(TREE_MODE_PLAIN), mColumns(6)
|
||||||
{
|
{
|
||||||
initEmptyHierarchy();
|
initEmptyHierarchy();
|
||||||
|
|
||||||
|
mEventHandlerId = 0;
|
||||||
|
// Needs to be asynced because this function is called by another thread!
|
||||||
|
|
||||||
|
rsEvents->registerEventsHandler( [this](std::shared_ptr<const RsEvent> event)
|
||||||
|
{
|
||||||
|
RsQThreadUtils::postToObject([=](){ handleEvent_main_thread(event); }, this );
|
||||||
|
}, mEventHandlerId, RsEventType::GXS_CHANNELS );
|
||||||
|
}
|
||||||
|
|
||||||
|
RsGxsChannelPostsModel::~RsGxsChannelPostsModel()
|
||||||
|
{
|
||||||
|
rsEvents->unregisterEventsHandler(mEventHandlerId);
|
||||||
|
}
|
||||||
|
|
||||||
|
void RsGxsChannelPostsModel::handleEvent_main_thread(std::shared_ptr<const RsEvent> event)
|
||||||
|
{
|
||||||
|
const RsGxsChannelEvent *e = dynamic_cast<const RsGxsChannelEvent*>(event.get());
|
||||||
|
|
||||||
|
if(!e)
|
||||||
|
return;
|
||||||
|
|
||||||
|
switch(e->mChannelEventCode)
|
||||||
|
{
|
||||||
|
case RsChannelEventCode::UPDATED_MESSAGE:
|
||||||
|
case RsChannelEventCode::READ_STATUS_CHANGED:
|
||||||
|
{
|
||||||
|
// Normally we should just emit dataChanged() on the index of the data that has changed:
|
||||||
|
//
|
||||||
|
// We need to update the data!
|
||||||
|
|
||||||
|
if(e->mChannelGroupId == mChannelGroup.mMeta.mGroupId)
|
||||||
|
RsThread::async([this, e]()
|
||||||
|
{
|
||||||
|
// 1 - get message data from p3GxsChannels
|
||||||
|
|
||||||
|
std::vector<RsGxsChannelPost> posts;
|
||||||
|
std::vector<RsGxsComment> comments;
|
||||||
|
std::vector<RsGxsVote> votes;
|
||||||
|
|
||||||
|
if(!rsGxsChannels->getChannelContent(mChannelGroup.mMeta.mGroupId,std::set<RsGxsMessageId>{ e->mChannelMsgId }, posts,comments,votes))
|
||||||
|
{
|
||||||
|
std::cerr << __PRETTY_FUNCTION__ << " failed to retrieve channel message data for channel/msg " << e->mChannelGroupId << "/" << e->mChannelMsgId << std::endl;
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
// 2 - update the model in the UI thread.
|
||||||
|
|
||||||
|
RsQThreadUtils::postToObject( [posts,comments,votes,this]()
|
||||||
|
{
|
||||||
|
for(uint32_t i=0;i<posts.size();++i)
|
||||||
|
{
|
||||||
|
// linear search. Not good at all, but normally this is for a single post.
|
||||||
|
|
||||||
|
for(uint32_t j=0;j<mPosts.size();++j)
|
||||||
|
if(mPosts[j].mMeta.mMsgId == posts[i].mMeta.mMsgId)
|
||||||
|
{
|
||||||
|
mPosts[j] = posts[i];
|
||||||
|
|
||||||
|
emit dataChanged(createIndex(0,0,(void*)NULL), createIndex(mFilteredPosts.size(),mColumns-1,(void*)NULL));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
},this);
|
||||||
|
});
|
||||||
|
|
||||||
|
default:
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void RsGxsChannelPostsModel::initEmptyHierarchy()
|
void RsGxsChannelPostsModel::initEmptyHierarchy()
|
||||||
|
@ -20,6 +20,7 @@
|
|||||||
|
|
||||||
#include "retroshare/rsgxschannels.h"
|
#include "retroshare/rsgxschannels.h"
|
||||||
#include "retroshare/rsgxsifacetypes.h"
|
#include "retroshare/rsgxsifacetypes.h"
|
||||||
|
#include "retroshare/rsevents.h"
|
||||||
#include <QModelIndex>
|
#include <QModelIndex>
|
||||||
#include <QColor>
|
#include <QColor>
|
||||||
|
|
||||||
@ -62,7 +63,7 @@ class RsGxsChannelPostsModel : public QAbstractItemModel
|
|||||||
|
|
||||||
public:
|
public:
|
||||||
explicit RsGxsChannelPostsModel(QObject *parent = NULL);
|
explicit RsGxsChannelPostsModel(QObject *parent = NULL);
|
||||||
~RsGxsChannelPostsModel(){}
|
virtual ~RsGxsChannelPostsModel() override;
|
||||||
|
|
||||||
static const int COLUMN_THREAD_NB_COLUMNS = 0x01;
|
static const int COLUMN_THREAD_NB_COLUMNS = 0x01;
|
||||||
|
|
||||||
@ -217,6 +218,7 @@ private:
|
|||||||
void createPostsArray(std::vector<RsGxsChannelPost> &posts);
|
void createPostsArray(std::vector<RsGxsChannelPost> &posts);
|
||||||
void setPosts(const RsGxsChannelGroup& group, std::vector<RsGxsChannelPost> &posts);
|
void setPosts(const RsGxsChannelGroup& group, std::vector<RsGxsChannelPost> &posts);
|
||||||
void initEmptyHierarchy();
|
void initEmptyHierarchy();
|
||||||
|
void handleEvent_main_thread(std::shared_ptr<const RsEvent> event);
|
||||||
|
|
||||||
std::vector<int> mFilteredPosts; // stores the list of displayes indices due to filtering.
|
std::vector<int> mFilteredPosts; // stores the list of displayes indices due to filtering.
|
||||||
std::vector<RsGxsChannelPost> mPosts ; // store the list of posts updated from rsForums.
|
std::vector<RsGxsChannelPost> mPosts ; // store the list of posts updated from rsForums.
|
||||||
@ -229,5 +231,6 @@ private:
|
|||||||
QColor mTextColorNotSubscribed ;
|
QColor mTextColorNotSubscribed ;
|
||||||
QColor mTextColorMissing ;
|
QColor mTextColorMissing ;
|
||||||
|
|
||||||
|
RsEventsHandlerId_t mEventHandlerId ;
|
||||||
friend class const_iterator;
|
friend class const_iterator;
|
||||||
};
|
};
|
||||||
|
@ -428,10 +428,11 @@ void GxsChannelPostsWidgetWithModel::handleEvent_main_thread(std::shared_ptr<con
|
|||||||
case RsChannelEventCode::UPDATED_CHANNEL: // [[fallthrough]];
|
case RsChannelEventCode::UPDATED_CHANNEL: // [[fallthrough]];
|
||||||
case RsChannelEventCode::NEW_MESSAGE: // [[fallthrough]];
|
case RsChannelEventCode::NEW_MESSAGE: // [[fallthrough]];
|
||||||
case RsChannelEventCode::UPDATED_MESSAGE:
|
case RsChannelEventCode::UPDATED_MESSAGE:
|
||||||
case RsChannelEventCode::READ_STATUS_CHANGED:
|
{
|
||||||
if(e->mChannelGroupId == groupId())
|
if(e->mChannelGroupId == groupId())
|
||||||
updateDisplay(true);
|
updateDisplay(true);
|
||||||
break;
|
}
|
||||||
|
|
||||||
default:
|
default:
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user