make interactions on BoardPostWidget to mark the post as read

This commit is contained in:
csoler 2020-10-01 20:25:10 +02:00
parent 4fd7f455a1
commit c30c7a4dfe
5 changed files with 35 additions and 12 deletions

View File

@ -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; }

View File

@ -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;

View File

@ -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);

View File

@ -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);

View File

@ -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