From 141ee0b7e04826f5b07f1dc9c8d8699782b22582 Mon Sep 17 00:00:00 2001 From: csoler Date: Thu, 23 Mar 2023 21:13:38 +0100 Subject: [PATCH] fixed bug in updating filtered posts --- .../gui/gxschannels/GxsChannelPostsModel.cpp | 53 +++++++++++-------- .../gui/gxschannels/GxsChannelPostsModel.h | 5 ++ .../GxsChannelPostsWidgetWithModel.cpp | 9 ++-- 3 files changed, 41 insertions(+), 26 deletions(-) diff --git a/retroshare-gui/src/gui/gxschannels/GxsChannelPostsModel.cpp b/retroshare-gui/src/gui/gxschannels/GxsChannelPostsModel.cpp index 4f3223186..508db7046 100644 --- a/retroshare-gui/src/gui/gxschannels/GxsChannelPostsModel.cpp +++ b/retroshare-gui/src/gui/gxschannels/GxsChannelPostsModel.cpp @@ -140,7 +140,31 @@ void RsGxsChannelPostsModel::getFilesList(std::list& files) files.push_back(it.second); } +bool RsGxsChannelPostsModel::postPassesFilter(const RsGxsChannelPost& post,const QStringList& strings,bool only_unread) const +{ + bool passes_strings = true; + + for(auto& s:strings) + passes_strings = passes_strings && QString::fromStdString(post.mMeta.mMsgName).contains(s,Qt::CaseInsensitive); + + if(strings.empty()) + passes_strings = true; + + if(passes_strings && (!only_unread || (IS_MSG_UNREAD(post.mMeta.mMsgStatus) || IS_MSG_NEW(post.mMeta.mMsgStatus)))) + return true; + + return false; +} + void RsGxsChannelPostsModel::setFilter(const QStringList& strings,bool only_unread, uint32_t& count) +{ + mFilteredStrings = strings; + mFilterUnread = only_unread; + + updateFilter(count); +} + +void RsGxsChannelPostsModel::updateFilter(uint32_t& count) { preMods(); @@ -151,18 +175,8 @@ void RsGxsChannelPostsModel::setFilter(const QStringList& strings,bool only_unre endResetModel(); for(size_t i=0;i& posts) diff --git a/retroshare-gui/src/gui/gxschannels/GxsChannelPostsModel.h b/retroshare-gui/src/gui/gxschannels/GxsChannelPostsModel.h index a84a4df60..4fe35e589 100644 --- a/retroshare-gui/src/gui/gxschannels/GxsChannelPostsModel.h +++ b/retroshare-gui/src/gui/gxschannels/GxsChannelPostsModel.h @@ -141,6 +141,8 @@ public: void setAllMsgReadStatus(bool read_status); void setFilter(const QStringList &strings, bool only_unread,uint32_t &count) ; + bool postPassesFilter(const RsGxsChannelPost &post, const QStringList &strings, bool only_unread) const; + void updateFilter(uint32_t& count); #ifdef TODO void setAuthorOpinion(const QModelIndex& indx,RsOpinion op); @@ -239,6 +241,9 @@ public: private: void initEmptyHierarchy(); + QStringList mFilteredStrings; + bool mFilterUnread; + 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 023732ed7..b1715d9d8 100644 --- a/retroshare-gui/src/gui/gxschannels/GxsChannelPostsWidgetWithModel.cpp +++ b/retroshare-gui/src/gui/gxschannels/GxsChannelPostsWidgetWithModel.cpp @@ -784,6 +784,7 @@ void GxsChannelPostsWidgetWithModel::handleEvent_main_thread(std::shared_ptrmChannelGroupId == groupId()) { + RsDbg() << "Received new message in current channel, msgId=" << e->mChannelMsgId ; RsThread::async([this,e]() { @@ -803,6 +804,7 @@ void GxsChannelPostsWidgetWithModel::handleEvent_main_thread(std::shared_ptrupdate_files(added_filesi,removed_filesi); - updateDisplay(true,false); - },this); }); } @@ -994,6 +995,8 @@ void GxsChannelPostsWidgetWithModel::updateData(bool update_group_data, bool upd if(update_posts) { + blank(); + ui->postsTree->setPlaceholderText(tr("Loading...")); mChannelPostsModel->updateChannel(groupId()); @@ -1068,7 +1071,7 @@ void GxsChannelPostsWidgetWithModel::postChannelPostLoad() void GxsChannelPostsWidgetWithModel::updateDisplay(bool update_group_data,bool update_posts) { // First, clear all widget - blank(); + #ifdef DEBUG_CHANNEL std::cerr << "udateDisplay: groupId()=" << groupId()<< std::endl; #endif