From a37ee4673fc4a124317acd1c265b42021658c094 Mon Sep 17 00:00:00 2001 From: csoler Date: Wed, 22 Mar 2023 09:07:27 +0100 Subject: [PATCH] half-implemented the system to perform lighter updates of channels --- .../gxschannels/GxsChannelPostFilesModel.cpp | 6 +- .../gxschannels/GxsChannelPostFilesModel.h | 3 + .../gui/gxschannels/GxsChannelPostsModel.cpp | 105 +++++++++--------- .../gui/gxschannels/GxsChannelPostsModel.h | 6 +- .../GxsChannelPostsWidgetWithModel.cpp | 15 ++- 5 files changed, 78 insertions(+), 57 deletions(-) diff --git a/retroshare-gui/src/gui/gxschannels/GxsChannelPostFilesModel.cpp b/retroshare-gui/src/gui/gxschannels/GxsChannelPostFilesModel.cpp index a0db07085..78748bcbe 100644 --- a/retroshare-gui/src/gui/gxschannels/GxsChannelPostFilesModel.cpp +++ b/retroshare-gui/src/gui/gxschannels/GxsChannelPostFilesModel.cpp @@ -426,7 +426,6 @@ QVariant RsGxsChannelPostFilesModel::userRole(const ChannelPostFileInfo& fmpe,in void RsGxsChannelPostFilesModel::clear() { - initEmptyHierarchy(); emit channelLoaded(); @@ -463,3 +462,8 @@ void RsGxsChannelPostFilesModel::setFiles(const std::list & postMods(); } + +void RsGxsChannelPostFilesModel::update_files(const std::set& added_files,const std::set& removed_files) +{ +#error TODO +} diff --git a/retroshare-gui/src/gui/gxschannels/GxsChannelPostFilesModel.h b/retroshare-gui/src/gui/gxschannels/GxsChannelPostFilesModel.h index 1aaa60fcb..8fbd6bbb1 100644 --- a/retroshare-gui/src/gui/gxschannels/GxsChannelPostFilesModel.h +++ b/retroshare-gui/src/gui/gxschannels/GxsChannelPostFilesModel.h @@ -83,6 +83,9 @@ public: void setFiles(const std::list& files); void setFilter(const QStringList &strings, uint32_t &count) ; + // This method adds/removes the given lists of files. Useful when a single post is updated + void update_files(const std::set& added_files,const std::set& removed_files); + #ifdef TODO QModelIndex getIndexOfFile(const RsFileHash& hash) const; void setSortMode(SortMode mode) ; diff --git a/retroshare-gui/src/gui/gxschannels/GxsChannelPostsModel.cpp b/retroshare-gui/src/gui/gxschannels/GxsChannelPostsModel.cpp index 0ad05b4a1..425f39a1b 100644 --- a/retroshare-gui/src/gui/gxschannels/GxsChannelPostsModel.cpp +++ b/retroshare-gui/src/gui/gxschannels/GxsChannelPostsModel.cpp @@ -35,7 +35,7 @@ #include "GxsChannelPostsModel.h" #include "GxsChannelPostFilesModel.h" -//#define DEBUG_CHANNEL_MODEL +#define DEBUG_CHANNEL_MODEL Q_DECLARE_METATYPE(RsMsgMetaData) @@ -47,14 +47,6 @@ RsGxsChannelPostsModel::RsGxsChannelPostsModel(QObject *parent) : QAbstractItemModel(parent), mTreeMode(RsGxsChannelPostsModel::TREE_MODE_GRID), mColumns(6) { initEmptyHierarchy(); - - mEventHandlerId = 0; - // Needs to be asynced because this function is called by another thread! - - rsEvents->registerEventsHandler( [this](std::shared_ptr event) - { - RsQThreadUtils::postToObject([=](){ handleEvent_main_thread(event); }, this ); - }, mEventHandlerId, RsEventType::GXS_CHANNELS ); } RsGxsChannelPostsModel::~RsGxsChannelPostsModel() @@ -108,35 +100,6 @@ void updateCommentCounts( std::vector& posts, std::vector event) -{ - const RsGxsChannelEvent *e = dynamic_cast(event.get()); - - if(!e) - return; - - switch(e->mChannelEventCode) - { - case RsChannelEventCode::UPDATED_MESSAGE: - case RsChannelEventCode::READ_STATUS_CHANGED: - case RsChannelEventCode::NEW_COMMENT: - { - // Normally we should just emit dataChanged() on the index of the data that has changed: - // We need to update the data! - - // In particular, mChannelMsgId may refer to a comment, but this will be handled correctly - // by update_single_post which will automatically retrive the correct parent msg. - - if(e->mChannelGroupId == mChannelGroup.mMeta.mGroupId) - update_single_post(e->mChannelGroupId,e->mChannelMsgId,e->mChannelThreadId); - }; - break; - - default: - break; - } -} - void RsGxsChannelPostsModel::initEmptyHierarchy() { beginResetModel(); @@ -570,9 +533,12 @@ void RsGxsChannelPostsModel::setPosts(const RsGxsChannelGroup& group, std::vecto emit channelPostsLoaded(); } -void RsGxsChannelPostsModel::update_single_post(const RsGxsGroupId& group_id,const RsGxsMessageId& msg_id,const RsGxsMessageId& thread_id) +void RsGxsChannelPostsModel::update_single_post(const RsGxsMessageId& msg_id,std::set& added_files,std::set& removed_files) { - RsThread::async([this, group_id, msg_id,thread_id]() +#ifdef DEBUG_CHANNEL_MODEL + RsDbg() << "updating single post for group id=" << currentGroupId() << " and msg id=" << msg_id ; +#endif + RsThread::async([this,&added_files,&removed_files, msg_id]() { // 1 - get message data from p3GxsChannels. No need for pointers here, because we send only a single post to postToObject() // At this point we dont know what kind of msg id we have. It can be a vote, a comment or an actual message. @@ -580,20 +546,19 @@ void RsGxsChannelPostsModel::update_single_post(const RsGxsGroupId& group_id,con std::vector posts; std::vector comments; std::vector votes; - std::set msg_ids({ (thread_id.isNull())?msg_id:thread_id } ); // we have a post message - if(!rsGxsChannels->getChannelContent(group_id,msg_ids, posts,comments,votes)) + if(!rsGxsChannels->getChannelContent(currentGroupId(), { msg_id }, posts,comments,votes) || posts.size() != 1) { - std::cerr << __PRETTY_FUNCTION__ << " failed to retrieve channel message data for channel/msg " << group_id << "/" << msg_id << std::endl; + RsErr() << " failed to retrieve channel message data for channel/msg " << currentGroupId() << "/" << msg_id ; return; } // Need to call this in order to get the actual comment count. The previous call only retrieves the message, since we supplied the message ID. // another way to go would be to save the comment ids of the existing message and re-insert them before calling getChannelContent. - if(!rsGxsChannels->getChannelComments(group_id,msg_ids,comments)) + if(!rsGxsChannels->getChannelComments(currentGroupId(),{ msg_id },comments)) { - std::cerr << __PRETTY_FUNCTION__ << " failed to retrieve message comment data for channel/msg " << group_id << "/" << msg_id << std::endl; + RsErr() << " failed to retrieve message comment data for channel/msg " << currentGroupId() << "/" << msg_id ; return; } @@ -603,20 +568,58 @@ void RsGxsChannelPostsModel::update_single_post(const RsGxsGroupId& group_id,con // 2 - update the model in the UI thread. - RsQThreadUtils::postToObject( [posts,this]() + added_files.clear(); + removed_files.clear(); + + RsQThreadUtils::postToObject( [&posts,&added_files,&removed_files,this]() { for(uint32_t i=0;i &added_files, std::set &removed_files); + +private: #ifdef TODO void setForumMessageSummary(const std::vector& messages); @@ -234,7 +237,6 @@ private: void setPosts(const RsGxsChannelGroup& group, std::vector &posts); void setSinglePost(const RsGxsChannelGroup& group, const RsGxsChannelPost& post); void initEmptyHierarchy(); - void handleEvent_main_thread(std::shared_ptr event); std::vector mFilteredPosts; // stores the list of displayes indices due to filtering. std::vector mPosts ; // store the list of posts updated from rsForums. diff --git a/retroshare-gui/src/gui/gxschannels/GxsChannelPostsWidgetWithModel.cpp b/retroshare-gui/src/gui/gxschannels/GxsChannelPostsWidgetWithModel.cpp index 74bd7361f..e4123dfc5 100644 --- a/retroshare-gui/src/gui/gxschannels/GxsChannelPostsWidgetWithModel.cpp +++ b/retroshare-gui/src/gui/gxschannels/GxsChannelPostsWidgetWithModel.cpp @@ -783,7 +783,14 @@ void GxsChannelPostsWidgetWithModel::handleEvent_main_thread(std::shared_ptrmChannelGroupId == groupId()) - updateDisplay(true,true); + { + std::set added_files,removed_files; + + mChannelPostsModel->update_single_post(e->mChannelMsgId,added_files,removed_files); + mChannelFilesModel->update_files(added_files,removed_files); + + updateDisplay(true,false); + } } break; @@ -794,11 +801,13 @@ void GxsChannelPostsWidgetWithModel::handleEvent_main_thread(std::shared_ptrcommentsDialog->refresh(); break; + case RsChannelEventCode::READ_STATUS_CHANGED: + mChannelPostsModel->triggerViewUpdate(); + break; + default: break; - // case RsChannelEventCode::UPDATED_MESSAGE: // handled in GxsChannelPostsModel - // case RsChannelEventCode::READ_STATUS_CHANGED: // handled in GxsChannelPostsModel } }