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);
}
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)
{
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 setCommentHeader(QWidget *header);
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; }
RsGxsMessageId messageId() { return mMostRecentMsgId; }

View File

@ -76,24 +76,18 @@ void updateCommentCounts( std::vector<RsGxsChannelPost>& posts, std::vector<RsGx
{
// 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;
for(uint32_t i=0;i<posts.size();++i)
{
post_indices[posts[i].mMeta.mMsgId] = i;
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
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;
}
}
@ -128,6 +122,9 @@ void RsGxsChannelPostsModel::handleEvent_main_thread(std::shared_ptr<const RsEve
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))
{
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();
std::cerr << "After filtering: " << count << " posts remain." << std::endl;
beginInsertRows(QModelIndex(),0,rowCount()-1);
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));
}
std::cerr << "mCommentCount=" << post.mCommentCount << std::endl;
if(post.mCommentCount)
{
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;
#endif
whileBlocking(ui->postsTree->selectionModel())->clear();
whileBlocking(ui->commentsDialog)->commentClear();
updateCommentsCount(0);
}
mGroup = group;