clear comments when switching channels

This commit is contained in:
csoler 2020-11-08 15:38:37 +01:00
parent d472053960
commit 0a6e15c524
4 changed files with 13 additions and 9 deletions

View file

@ -86,6 +86,13 @@ GxsCommentDialog::~GxsCommentDialog()
delete(ui); delete(ui);
} }
void GxsCommentDialog::commentClear()
{
ui->treeWidget->clear();
mGrpId.clear();
mMostRecentMsgId.clear();
mMsgVersions.clear();
}
void GxsCommentDialog::commentLoad(const RsGxsGroupId &grpId, const std::set<RsGxsMessageId>& msg_versions,const RsGxsMessageId& most_recent_msgId,bool use_cache) void GxsCommentDialog::commentLoad(const RsGxsGroupId &grpId, const std::set<RsGxsMessageId>& msg_versions,const RsGxsMessageId& most_recent_msgId,bool use_cache)
{ {
std::cerr << "GxsCommentDialog::commentLoad(" << grpId << ", most recent msg version: " << most_recent_msgId << ")"; std::cerr << "GxsCommentDialog::commentLoad(" << grpId << ", most recent msg version: " << most_recent_msgId << ")";

View file

@ -39,6 +39,7 @@ public:
void setTokenService(RsTokenService *token_service, RsGxsCommentService *comment_service); void setTokenService(RsTokenService *token_service, RsGxsCommentService *comment_service);
void setCommentHeader(QWidget *header); void setCommentHeader(QWidget *header);
void commentLoad(const RsGxsGroupId &grpId, const std::set<RsGxsMessageId> &msg_versions, const RsGxsMessageId &most_recent_msgId, bool use_cache=false); void commentLoad(const RsGxsGroupId &grpId, const std::set<RsGxsMessageId> &msg_versions, const RsGxsMessageId &most_recent_msgId, bool use_cache=false);
void commentClear();
RsGxsGroupId groupId() { return mGrpId; } RsGxsGroupId groupId() { return mGrpId; }
RsGxsMessageId messageId() { return mMostRecentMsgId; } RsGxsMessageId messageId() { return mMostRecentMsgId; }

View file

@ -76,25 +76,19 @@ void updateCommentCounts( std::vector<RsGxsChannelPost>& posts, std::vector<RsGx
{ {
// Store posts IDs in a std::map to avoid a quadratic cost // Store posts IDs in a std::map to avoid a quadratic cost
std::cerr << "Updating comment counts for " << posts.size() << " posts." << std::endl;
std::map<RsGxsMessageId,uint32_t> post_indices; std::map<RsGxsMessageId,uint32_t> post_indices;
for(uint32_t i=0;i<posts.size();++i) for(uint32_t i=0;i<posts.size();++i)
{ {
post_indices[posts[i].mMeta.mMsgId] = i; post_indices[posts[i].mMeta.mMsgId] = i;
posts[i].mCommentCount = 0; // should be 0 already, but we secure that value. posts[i].mCommentCount = 0; // should be 0 already, but we secure that value.
std::cerr << " Zeroing comments for post " << posts[i].mMeta.mMsgId << std::endl;
} }
// now look into comments and increase the count // now look into comments and increase the count
for(uint32_t i=0;i<comments.size();++i) for(uint32_t i=0;i<comments.size();++i)
{
std::cerr << " Found new comment " << comments[i].mMeta.mMsgId << " for post" << comments[i].mMeta.mThreadId << std::endl;
++posts[post_indices[comments[i].mMeta.mThreadId]].mCommentCount; ++posts[post_indices[comments[i].mMeta.mThreadId]].mCommentCount;
} }
}
void RsGxsChannelPostsModel::handleEvent_main_thread(std::shared_ptr<const RsEvent> event) void RsGxsChannelPostsModel::handleEvent_main_thread(std::shared_ptr<const RsEvent> event)
@ -128,6 +122,9 @@ void RsGxsChannelPostsModel::handleEvent_main_thread(std::shared_ptr<const RsEve
return; return;
} }
// Need to call this in order to get the actuall 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(mChannelGroup.mMeta.mGroupId,std::set<RsGxsMessageId>{ e->mChannelMsgId },comments)) if(!rsGxsChannels->getChannelComments(mChannelGroup.mMeta.mGroupId,std::set<RsGxsMessageId>{ e->mChannelMsgId },comments))
{ {
std::cerr << __PRETTY_FUNCTION__ << " failed to retrieve message comment data for channel/msg " << e->mChannelGroupId << "/" << e->mChannelMsgId << std::endl; std::cerr << __PRETTY_FUNCTION__ << " failed to retrieve message comment data for channel/msg " << e->mChannelGroupId << "/" << e->mChannelMsgId << std::endl;
@ -228,8 +225,6 @@ void RsGxsChannelPostsModel::setFilter(const QStringList& strings,bool only_unre
count = mFilteredPosts.size(); count = mFilteredPosts.size();
std::cerr << "After filtering: " << count << " posts remain." << std::endl;
beginInsertRows(QModelIndex(),0,rowCount()-1); beginInsertRows(QModelIndex(),0,rowCount()-1);
endInsertRows(); endInsertRows();

View file

@ -183,7 +183,6 @@ void ChannelPostDelegate::paint(QPainter * painter, const QStyleOptionViewItem &
p.drawPixmap(mZoom*QPoint(0.1*fm.height(),-3.4*fm.height()),FilesDefs::getPixmapFromQtResourcePath(STAR_OVERLAY_IMAGE).scaled(mZoom*6*fm.height(),mZoom*6*fm.height(),Qt::KeepAspectRatio,Qt::SmoothTransformation)); p.drawPixmap(mZoom*QPoint(0.1*fm.height(),-3.4*fm.height()),FilesDefs::getPixmapFromQtResourcePath(STAR_OVERLAY_IMAGE).scaled(mZoom*6*fm.height(),mZoom*6*fm.height(),Qt::KeepAspectRatio,Qt::SmoothTransformation));
} }
std::cerr << "mCommentCount=" << post.mCommentCount << std::endl;
if(post.mCommentCount) if(post.mCommentCount)
{ {
QPainter p(&pixmap); QPainter p(&pixmap);
@ -856,6 +855,8 @@ void GxsChannelPostsWidgetWithModel::updateGroupData()
std::cerr << "Old group: " << mGroup.mMeta.mGroupId << ", new group: " << group.mMeta.mGroupId << ". Celaring selection" << std::endl; std::cerr << "Old group: " << mGroup.mMeta.mGroupId << ", new group: " << group.mMeta.mGroupId << ". Celaring selection" << std::endl;
#endif #endif
whileBlocking(ui->postsTree->selectionModel())->clear(); whileBlocking(ui->postsTree->selectionModel())->clear();
whileBlocking(ui->commentsDialog)->commentClear();
updateCommentsCount(0);
} }
mGroup = group; mGroup = group;