From e63ff4d7db27b9d6fa125c18f3eac9e82ab45a3b Mon Sep 17 00:00:00 2001 From: csoler Date: Sun, 26 Mar 2023 22:49:08 +0200 Subject: [PATCH] made setAllMsgAsRead faster in channels, avoiding to reload all posts --- .../gxschannels/GxsChannelPostFilesModel.cpp | 2 +- .../gui/gxschannels/GxsChannelPostsModel.cpp | 23 +++++++++++++-- .../GxsChannelPostsWidgetWithModel.cpp | 29 +++++++++++++------ 3 files changed, 42 insertions(+), 12 deletions(-) diff --git a/retroshare-gui/src/gui/gxschannels/GxsChannelPostFilesModel.cpp b/retroshare-gui/src/gui/gxschannels/GxsChannelPostFilesModel.cpp index ee1bc5fe2..856ef32e1 100644 --- a/retroshare-gui/src/gui/gxschannels/GxsChannelPostFilesModel.cpp +++ b/retroshare-gui/src/gui/gxschannels/GxsChannelPostFilesModel.cpp @@ -33,7 +33,7 @@ #include "GxsChannelPostFilesModel.h" -#define DEBUG_CHANNEL_FILES_MODEL +//#define DEBUG_CHANNEL_FILES_MODEL Q_DECLARE_METATYPE(ChannelPostFileInfo) diff --git a/retroshare-gui/src/gui/gxschannels/GxsChannelPostsModel.cpp b/retroshare-gui/src/gui/gxschannels/GxsChannelPostsModel.cpp index 0fe8265f6..b7f9f53d1 100644 --- a/retroshare-gui/src/gui/gxschannels/GxsChannelPostsModel.cpp +++ b/retroshare-gui/src/gui/gxschannels/GxsChannelPostsModel.cpp @@ -39,7 +39,6 @@ #define DEBUG_CHANNEL_MODEL Q_DECLARE_METATYPE(RsMsgMetaData) - Q_DECLARE_METATYPE(RsGxsChannelPost) std::ostream& operator<<(std::ostream& o, const QModelIndex& i);// defined elsewhere @@ -206,7 +205,7 @@ int RsGxsChannelPostsModel::rowCount(const QModelIndex& parent) const return mFilteredPosts.size(); } - RsErr() << __PRETTY_FUNCTION__ << " rowCount cannot figure out the porper number of rows." << std::endl; + RsErr() << __PRETTY_FUNCTION__ << " rowCount cannot figure out the proper number of rows." ; return 0; } @@ -790,6 +789,16 @@ void RsGxsChannelPostsModel::setAllMsgReadStatus(bool read_status) if(!rsGxsChannels->setMessageReadStatus(p,read_status)) RsErr() << "setAllMsgReadStatus: failed to change status of msg " << p.first << " in group " << p.second << " to status " << read_status << std::endl; }); + + // 3 - update the local model data, since we don't catch the READ_STATUS_CHANGED event later, to avoid re-loading the msg. + + for(uint32_t i=0;isetMessageReadStatus(RsGxsGrpMsgIdPair(mPosts[mFilteredPosts[entry]].mMeta.mGroupId,mPosts[mFilteredPosts[entry]].mMeta.mMsgId),read_status); + + // Quick update to the msg itself. Normally setMsgReadStatus will launch an event, + // that we can catch to update the msg, but all the information is already here. + + if(read_status) + mPosts[mFilteredPosts[entry]].mMeta.mMsgStatus &= ~GXS_SERV::GXS_MSG_STATUS_GUI_UNREAD; + else + mPosts[mFilteredPosts[entry]].mMeta.mMsgStatus |= GXS_SERV::GXS_MSG_STATUS_GUI_UNREAD; + + emit dataChanged(i,i); } QModelIndex RsGxsChannelPostsModel::getIndexOfMessage(const RsGxsMessageId& mid) const diff --git a/retroshare-gui/src/gui/gxschannels/GxsChannelPostsWidgetWithModel.cpp b/retroshare-gui/src/gui/gxschannels/GxsChannelPostsWidgetWithModel.cpp index c8a0fd117..9198ed73a 100644 --- a/retroshare-gui/src/gui/gxschannels/GxsChannelPostsWidgetWithModel.cpp +++ b/retroshare-gui/src/gui/gxschannels/GxsChannelPostsWidgetWithModel.cpp @@ -119,6 +119,7 @@ void ChannelPostDelegate::paint(QPainter * painter, const QStyleOptionViewItem & painter->save(); painter->setClipRect(option.rect); + std::cerr << "option.rect=" << option.rect.width() << " x " << option.rect.height() << std::endl; RsGxsChannelPost post = index.data(Qt::UserRole).value() ; // if(index.row() & 0x01) @@ -262,6 +263,9 @@ QSize ChannelPostDelegate::sizeHint(const QStyleOptionViewItem& option, const QM float cell_width = mZoom*COLUMN_SIZE_FONT_FACTOR_W*fm.height(); float cell_height = mZoom*COLUMN_SIZE_FONT_FACTOR_W*fm.height()*aspect_ratio; +#ifdef DEBUG_CHANNEL_POSTS_WIDGET + RsDbg() << "SizeHint: mUseGrid=" << mUseGrid << " cell_width=" << cell_width << " cell_height=" << cell_height << " mZoom=" << mZoom ; +#endif if(mUseGrid || index.column()==0) return QSize(cell_width,cell_height); @@ -743,7 +747,7 @@ void GxsChannelPostsWidgetWithModel::handlePostsTreeSizeChange(QSize s,bool forc return; int n_columns = std::max(1,(int)floor(s.width() / (mChannelPostsDelegate->cellSize(0,font(),ui->postsTree->width())))); - std::cerr << "nb columns: " << n_columns << " current count=" << mChannelPostsModel->columnCount() << std::endl; + RsDbg() << "nb columns: " << n_columns << " current count=" << mChannelPostsModel->columnCount() ; // save current post. The setNumColumns() indeed loses selection @@ -780,7 +784,9 @@ void GxsChannelPostsWidgetWithModel::handleEvent_main_thread(std::shared_ptrmChannelGroupId == groupId()) @@ -857,7 +863,7 @@ void GxsChannelPostsWidgetWithModel::showPostDetails() QModelIndex index = ui->postsTree->selectionModel()->currentIndex(); RsGxsChannelPost post = index.data(Qt::UserRole).value() ; #ifdef DEBUG_CHANNEL_POSTS_WIDGET - std::cerr << "showPostDetails: current index is " << index.row() << "," << index.column() << std::endl; + RsDbg() << "showPostDetails: current index is " << index.row() << "," << index.column() ; #endif //QTextDocument doc; @@ -882,7 +888,7 @@ void GxsChannelPostsWidgetWithModel::showPostDetails() ui->postTime_LB->show(); #ifdef DEBUG_CHANNEL_POSTS_WIDGET - std::cerr << "showPostDetails: setting mLastSelectedPosts[groupId()] to current post Id " << post.mMeta.mMsgId << ". Previous value: " << mLastSelectedPosts[groupId()] << std::endl; + RsDbg() << "showPostDetails: setting mLastSelectedPosts[groupId()] to current post Id " << post.mMeta.mMsgId << ". Previous value: " << mLastSelectedPosts[groupId()] ; #endif mLastSelectedPosts[groupId()] = post.mMeta.mMsgId; @@ -898,7 +904,7 @@ void GxsChannelPostsWidgetWithModel::showPostDetails() ui->commentsDialog->commentLoad(post.mMeta.mGroupId, all_msgs_versions, post.mMeta.mMsgId,true); #ifdef DEBUG_CHANNEL_POSTS_WIDGET - std::cerr << "Showing details about selected index : "<< index.row() << "," << index.column() << std::endl; + RsDbg() << "Showing details about selected index : "<< index.row() << "," << index.column() ; #endif ui->postDetails_TE->setText(RsHtml().formatText(NULL, QString::fromUtf8(post.mMsg.c_str()), /* RSHTML_FORMATTEXT_EMBED_SMILEYS |*/ RSHTML_FORMATTEXT_EMBED_LINKS)); @@ -930,11 +936,16 @@ void GxsChannelPostsWidgetWithModel::showPostDetails() if(IS_MSG_UNREAD(post.mMeta.mMsgStatus) || IS_MSG_NEW(post.mMeta.mMsgStatus)) { - RsGxsGrpMsgIdPair postId; - postId.second = post.mMeta.mMsgId; - postId.first = post.mMeta.mGroupId; + mChannelPostsModel->setMsgReadStatus(index,true); - RsThread::async([postId]() { rsGxsChannels->setMessageReadStatus(postId, true) ; } ); + //RsGxsGrpMsgIdPair postId; + //postId.second = post.mMeta.mMsgId; + //postId.first = post.mMeta.mGroupId; + + //RsThread::async([postId]() + //{ + //rsGxsChannels->setMessageReadStatus(postId, true) ; + //} ); } updateDAll_PB();