mirror of
https://github.com/RetroShare/RetroShare.git
synced 2025-02-04 17:15:31 -05:00
fixed bug in updating filtered posts
This commit is contained in:
parent
aba0ffa581
commit
141ee0b7e0
@ -140,7 +140,31 @@ void RsGxsChannelPostsModel::getFilesList(std::list<ChannelPostFileInfo>& files)
|
|||||||
files.push_back(it.second);
|
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)
|
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();
|
preMods();
|
||||||
|
|
||||||
@ -151,18 +175,8 @@ void RsGxsChannelPostsModel::setFilter(const QStringList& strings,bool only_unre
|
|||||||
endResetModel();
|
endResetModel();
|
||||||
|
|
||||||
for(size_t i=0;i<mPosts.size();++i)
|
for(size_t i=0;i<mPosts.size();++i)
|
||||||
{
|
if(postPassesFilter(mPosts[i],mFilteredStrings,mFilterUnread))
|
||||||
bool passes_strings = true;
|
|
||||||
|
|
||||||
for(auto& s:strings)
|
|
||||||
passes_strings = passes_strings && QString::fromStdString(mPosts[i].mMeta.mMsgName).contains(s,Qt::CaseInsensitive);
|
|
||||||
|
|
||||||
if(strings.empty())
|
|
||||||
passes_strings = true;
|
|
||||||
|
|
||||||
if(passes_strings && (!only_unread || (IS_MSG_UNREAD(mPosts[i].mMeta.mMsgStatus) || IS_MSG_NEW(mPosts[i].mMeta.mMsgStatus))))
|
|
||||||
mFilteredPosts.push_back(i);
|
mFilteredPosts.push_back(i);
|
||||||
}
|
|
||||||
|
|
||||||
count = mFilteredPosts.size();
|
count = mFilteredPosts.size();
|
||||||
|
|
||||||
@ -514,20 +528,13 @@ void RsGxsChannelPostsModel::updateSinglePost(const RsGxsChannelPost& post,std::
|
|||||||
#endif
|
#endif
|
||||||
added_files.insert(post.mFiles.begin(),post.mFiles.end());
|
added_files.insert(post.mFiles.begin(),post.mFiles.end());
|
||||||
mPosts.push_back(post);
|
mPosts.push_back(post);
|
||||||
|
}
|
||||||
std::sort(mPosts.begin(),mPosts.end());
|
std::sort(mPosts.begin(),mPosts.end());
|
||||||
|
|
||||||
// We don't do that, because otherwise the filtered posts will be changed dynamically when browsing, which is bad.
|
uint32_t count;
|
||||||
//
|
updateFilter(count);
|
||||||
// mFilteredPosts.clear();
|
|
||||||
// for(uint32_t i=0;i<mPosts.size();++i)
|
|
||||||
// mFilteredPosts.push_back(i);
|
|
||||||
}
|
|
||||||
|
|
||||||
triggerViewUpdate();
|
triggerViewUpdate();
|
||||||
|
|
||||||
emit layoutChanged();
|
|
||||||
emit channelPostsLoaded();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void RsGxsChannelPostsModel::setPosts(const RsGxsChannelGroup& group, std::vector<RsGxsChannelPost>& posts)
|
void RsGxsChannelPostsModel::setPosts(const RsGxsChannelGroup& group, std::vector<RsGxsChannelPost>& posts)
|
||||||
|
@ -141,6 +141,8 @@ public:
|
|||||||
void setAllMsgReadStatus(bool read_status);
|
void setAllMsgReadStatus(bool read_status);
|
||||||
|
|
||||||
void setFilter(const QStringList &strings, bool only_unread,uint32_t &count) ;
|
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
|
#ifdef TODO
|
||||||
void setAuthorOpinion(const QModelIndex& indx,RsOpinion op);
|
void setAuthorOpinion(const QModelIndex& indx,RsOpinion op);
|
||||||
@ -239,6 +241,9 @@ public:
|
|||||||
private:
|
private:
|
||||||
void initEmptyHierarchy();
|
void initEmptyHierarchy();
|
||||||
|
|
||||||
|
QStringList mFilteredStrings;
|
||||||
|
bool mFilterUnread;
|
||||||
|
|
||||||
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.
|
||||||
|
|
||||||
|
@ -784,6 +784,7 @@ void GxsChannelPostsWidgetWithModel::handleEvent_main_thread(std::shared_ptr<con
|
|||||||
{
|
{
|
||||||
if(e->mChannelGroupId == groupId())
|
if(e->mChannelGroupId == groupId())
|
||||||
{
|
{
|
||||||
|
RsDbg() << "Received new message in current channel, msgId=" << e->mChannelMsgId ;
|
||||||
|
|
||||||
RsThread::async([this,e]()
|
RsThread::async([this,e]()
|
||||||
{
|
{
|
||||||
@ -803,6 +804,7 @@ void GxsChannelPostsWidgetWithModel::handleEvent_main_thread(std::shared_ptr<con
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#ifdef TO_REMOVE
|
||||||
// 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.
|
// 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.
|
// another way to go would be to save the comment ids of the existing message and re-insert them before calling getChannelContent.
|
||||||
|
|
||||||
@ -815,6 +817,7 @@ void GxsChannelPostsWidgetWithModel::handleEvent_main_thread(std::shared_ptr<con
|
|||||||
// Normally, there's a single post in the "post" array. The function below takes a full array of posts however.
|
// Normally, there's a single post in the "post" array. The function below takes a full array of posts however.
|
||||||
|
|
||||||
RsGxsChannelPostsModel::computeCommentCounts(posts,comments);
|
RsGxsChannelPostsModel::computeCommentCounts(posts,comments);
|
||||||
|
#endif
|
||||||
|
|
||||||
// 2 - update the model in the UI thread.
|
// 2 - update the model in the UI thread.
|
||||||
|
|
||||||
@ -831,8 +834,6 @@ void GxsChannelPostsWidgetWithModel::handleEvent_main_thread(std::shared_ptr<con
|
|||||||
|
|
||||||
mChannelFilesModel->update_files(added_filesi,removed_filesi);
|
mChannelFilesModel->update_files(added_filesi,removed_filesi);
|
||||||
|
|
||||||
updateDisplay(true,false);
|
|
||||||
|
|
||||||
},this);
|
},this);
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
@ -994,6 +995,8 @@ void GxsChannelPostsWidgetWithModel::updateData(bool update_group_data, bool upd
|
|||||||
|
|
||||||
if(update_posts)
|
if(update_posts)
|
||||||
{
|
{
|
||||||
|
blank();
|
||||||
|
|
||||||
ui->postsTree->setPlaceholderText(tr("Loading..."));
|
ui->postsTree->setPlaceholderText(tr("Loading..."));
|
||||||
|
|
||||||
mChannelPostsModel->updateChannel(groupId());
|
mChannelPostsModel->updateChannel(groupId());
|
||||||
@ -1068,7 +1071,7 @@ void GxsChannelPostsWidgetWithModel::postChannelPostLoad()
|
|||||||
void GxsChannelPostsWidgetWithModel::updateDisplay(bool update_group_data,bool update_posts)
|
void GxsChannelPostsWidgetWithModel::updateDisplay(bool update_group_data,bool update_posts)
|
||||||
{
|
{
|
||||||
// First, clear all widget
|
// First, clear all widget
|
||||||
blank();
|
|
||||||
#ifdef DEBUG_CHANNEL
|
#ifdef DEBUG_CHANNEL
|
||||||
std::cerr << "udateDisplay: groupId()=" << groupId()<< std::endl;
|
std::cerr << "udateDisplay: groupId()=" << groupId()<< std::endl;
|
||||||
#endif
|
#endif
|
||||||
|
Loading…
x
Reference in New Issue
Block a user