From c30c7a4dfe5259b888f03925a777f6fd54f42c80 Mon Sep 17 00:00:00 2001 From: csoler Date: Thu, 1 Oct 2020 20:25:10 +0200 Subject: [PATCH] make interactions on BoardPostWidget to mark the post as read --- .../src/gui/Posted/BoardPostDisplayWidget.cpp | 14 +++++++------- .../src/gui/Posted/BoardPostDisplayWidget.h | 3 +++ .../gui/Posted/PostedListWidgetWithModel.cpp | 17 +++++++++++++++++ .../src/gui/Posted/PostedListWidgetWithModel.h | 1 + .../src/gui/Posted/PostedPostsModel.cpp | 12 +++++++----- 5 files changed, 35 insertions(+), 12 deletions(-) diff --git a/retroshare-gui/src/gui/Posted/BoardPostDisplayWidget.cpp b/retroshare-gui/src/gui/Posted/BoardPostDisplayWidget.cpp index 7e8ced3ea..49b92de00 100644 --- a/retroshare-gui/src/gui/Posted/BoardPostDisplayWidget.cpp +++ b/retroshare-gui/src/gui/Posted/BoardPostDisplayWidget.cpp @@ -191,18 +191,14 @@ void BoardPostDisplayWidgetBase::setup() readButton()->setChecked(false); -// voteUpButton()->setIconSize(QSize(S*1.5,S*1.5)); -// voteDownButton()->setIconSize(QSize(S*1.5,S*1.5)); -// commentButton()->setIconSize(QSize(S*1.5,S*1.5)); -// readButton()->setIconSize(QSize(S*1.5,S*1.5)); -// shareButton()->setIconSize(QSize(S*1.5,S*1.5)); - QMenu *menu = new QMenu(); menu->addAction(CopyLinkAction); menu->addSeparator(); menu->addAction(showInPeopleAct); shareButton()->setMenu(menu); + connect(shareButton(),SIGNAL(pressed()),this,SLOT(handleShareButtonClicked())); + RsReputationLevel overall_reputation = rsReputations->overallReputationLevel(mPost.mMeta.mAuthorId); bool redacted = (overall_reputation == RsReputationLevel::LOCALLY_NEGATIVE); @@ -307,6 +303,10 @@ void BoardPostDisplayWidgetBase::setup() emit sizeChanged(this); #endif } +void BoardPostDisplayWidgetBase::handleShareButtonClicked() +{ + emit shareButtonClicked(); +} //=================================================================================================================================== //== class BoardPostDisplayWidget == //=================================================================================================================================== @@ -423,7 +423,7 @@ void BoardPostDisplayWidget_compact::viewPicture() PView->show(); - /* window will destroy itself! */ + emit thumbnailOpenned(); } QToolButton *BoardPostDisplayWidget_compact::voteUpButton() { return ui->voteUpButton; } diff --git a/retroshare-gui/src/gui/Posted/BoardPostDisplayWidget.h b/retroshare-gui/src/gui/Posted/BoardPostDisplayWidget.h index 2ef9233b5..edf8bf760 100644 --- a/retroshare-gui/src/gui/Posted/BoardPostDisplayWidget.h +++ b/retroshare-gui/src/gui/Posted/BoardPostDisplayWidget.h @@ -87,12 +87,15 @@ protected slots: void makeUpVote() ; void makeDownVote() ; void setCommentsSize(int comNb) ; + void handleShareButtonClicked() ; signals: void changeReadStatusRequested(const RsGxsMessageId&,bool); void vote(const RsGxsGrpMsgIdPair& msgId, bool up_or_down); void expand(RsGxsMessageId,bool); void commentsRequested(const RsGxsMessageId&,bool); + void thumbnailOpenned(); + void shareButtonClicked(); protected: RsPostedPost mPost; diff --git a/retroshare-gui/src/gui/Posted/PostedListWidgetWithModel.cpp b/retroshare-gui/src/gui/Posted/PostedListWidgetWithModel.cpp index 80543510b..d4bec080a 100644 --- a/retroshare-gui/src/gui/Posted/PostedListWidgetWithModel.cpp +++ b/retroshare-gui/src/gui/Posted/PostedListWidgetWithModel.cpp @@ -199,6 +199,13 @@ QWidget *PostedPostDelegate::createEditor(QWidget *parent, const QStyleOptionVie QObject::connect(w,SIGNAL(commentsRequested(const RsGxsMessageId&,bool)),mPostListWidget,SLOT(openComments(const RsGxsMessageId&))); QObject::connect(w,SIGNAL(changeReadStatusRequested(const RsGxsMessageId&,bool)),mPostListWidget,SLOT(changeReadStatus(const RsGxsMessageId&,bool))); + // All other interactions with the widget should cause the msg to be set as read. + QObject::connect(w,SIGNAL(thumbnailOpenned()),mPostListWidget,SLOT(markCurrentPostAsRead())); + QObject::connect(w,SIGNAL(vote(RsGxsGrpMsgIdPair,bool)),mPostListWidget,SLOT(markCurrentPostAsRead())); + QObject::connect(w,SIGNAL(expand(RsGxsMessageId,bool)),this,SLOT(markCurrentPostAsRead())); + QObject::connect(w,SIGNAL(commentsRequested(const RsGxsMessageId&,bool)),mPostListWidget,SLOT(markCurrentPostAsRead())); + QObject::connect(w,SIGNAL(shareButtonClicked()),mPostListWidget,SLOT(markCurrentPostAsRead())); + w->setFixedSize(option.rect.size()); w->adjustSize(); w->updateGeometry(); @@ -692,6 +699,16 @@ void PostedListWidgetWithModel::openComments(const RsGxsMessageId& msgId) ui->tabWidget->addTab(commentDialog,title); } +void PostedListWidgetWithModel::markCurrentPostAsRead() +{ + QModelIndex index = ui->postsTree->selectionModel()->currentIndex(); + + if(!index.isValid()) + throw std::runtime_error("No post under mouse!"); + + mPostedPostsModel->setMsgReadStatus(index,true); +} + void PostedListWidgetWithModel::changeReadStatus(const RsGxsMessageId& msgId,bool b) { QModelIndex index=mPostedPostsModel->getIndexOfMessage(msgId); diff --git a/retroshare-gui/src/gui/Posted/PostedListWidgetWithModel.h b/retroshare-gui/src/gui/Posted/PostedListWidgetWithModel.h index c07311e4d..63dcbf9e1 100644 --- a/retroshare-gui/src/gui/Posted/PostedListWidgetWithModel.h +++ b/retroshare-gui/src/gui/Posted/PostedListWidgetWithModel.h @@ -149,6 +149,7 @@ private slots: public slots: void handlePostsTreeSizeChange(QSize size); void voteMsg(RsGxsGrpMsgIdPair msg,bool up_or_down); + void markCurrentPostAsRead(); private: void processSettings(bool load); diff --git a/retroshare-gui/src/gui/Posted/PostedPostsModel.cpp b/retroshare-gui/src/gui/Posted/PostedPostsModel.cpp index 36f69e7d5..afd71d8b1 100644 --- a/retroshare-gui/src/gui/Posted/PostedPostsModel.cpp +++ b/retroshare-gui/src/gui/Posted/PostedPostsModel.cpp @@ -748,13 +748,15 @@ void RsPostedPostsModel::setMsgReadStatus(const QModelIndex& i,bool read_status) RsGxsGroupId grpId = mPosts[entry].mMeta.mGroupId; RsGxsMessageId msgId = mPosts[entry].mMeta.mMsgId; - RsThread::async([msgId,grpId,read_status]() - { - // Call blocking API + bool current_read_status = !(IS_MSG_UNREAD(mPosts[entry].mMeta.mMsgStatus) || IS_MSG_NEW(mPosts[entry].mMeta.mMsgStatus)); - rsPosted->setPostReadStatus(RsGxsGrpMsgIdPair(grpId,msgId),read_status); - } ); + if(current_read_status != read_status) + RsThread::async([msgId,grpId,read_status]() + { + // Call blocking API + rsPosted->setPostReadStatus(RsGxsGrpMsgIdPair(grpId,msgId),read_status); + } ); } QModelIndex RsPostedPostsModel::getIndexOfMessage(const RsGxsMessageId& mid) const