fixed mark as read/unread and display of read status in forum model

This commit is contained in:
csoler 2018-11-24 20:50:09 +01:00
parent 9cec56f1ec
commit 6f83bb520e
No known key found for this signature in database
GPG Key ID: 7BCA522266C0804C
4 changed files with 122 additions and 35 deletions

View File

@ -259,11 +259,6 @@ QVariant RsGxsForumModel::data(const QModelIndex &index, int role) const
switch(role) switch(role)
{ {
case Qt::SizeHintRole: return sizeHintRole(index.column()) ; case Qt::SizeHintRole: return sizeHintRole(index.column()) ;
case Qt::FontRole:
case Qt::TextAlignmentRole:
case Qt::TextColorRole:
case Qt::WhatsThisRole:
case Qt::EditRole:
case Qt::StatusTipRole:return QVariant(); case Qt::StatusTipRole:return QVariant();
default: break; default: break;
} }
@ -297,7 +292,7 @@ QVariant RsGxsForumModel::data(const QModelIndex &index, int role) const
{ {
QFont font ; QFont font ;
font.setBold(IS_MSG_UNREAD(fmpe.mMsgStatus)); font.setBold(fmpe.mPostFlags & ForumModelPostEntry::FLAG_POST_HAS_UNREAD_CHILDREN);
return QVariant(font); return QVariant(font);
} }
@ -311,6 +306,7 @@ QVariant RsGxsForumModel::data(const QModelIndex &index, int role) const
case Qt::DecorationRole: return decorationRole(fmpe,index.column()) ; case Qt::DecorationRole: return decorationRole(fmpe,index.column()) ;
case Qt::ToolTipRole: return toolTipRole (fmpe,index.column()) ; case Qt::ToolTipRole: return toolTipRole (fmpe,index.column()) ;
case Qt::UserRole: return userRole (fmpe,index.column()) ; case Qt::UserRole: return userRole (fmpe,index.column()) ;
case Qt::TextColorRole: return textColorRole (fmpe,index.column()) ;
case ThreadPinnedRole: return pinnedRole (fmpe,index.column()) ; case ThreadPinnedRole: return pinnedRole (fmpe,index.column()) ;
case MissingRole: return missingRole (fmpe,index.column()) ; case MissingRole: return missingRole (fmpe,index.column()) ;
@ -320,6 +316,14 @@ QVariant RsGxsForumModel::data(const QModelIndex &index, int role) const
} }
} }
QVariant RsGxsForumModel::textColorRole(const ForumModelPostEntry& fmpe,int column) const
{
if( (fmpe.mPostFlags & ForumModelPostEntry::FLAG_POST_HAS_UNREAD_CHILDREN) && !IS_MSG_UNREAD(fmpe.mMsgStatus))
return QVariant(mTextColorUnreadChildren);
return QVariant();
}
QVariant RsGxsForumModel::statusRole(const ForumModelPostEntry& fmpe,int column) const QVariant RsGxsForumModel::statusRole(const ForumModelPostEntry& fmpe,int column) const
{ {
if(column != COLUMN_THREAD_DATA) if(column != COLUMN_THREAD_DATA)
@ -476,6 +480,9 @@ void RsGxsForumModel::setPosts(const RsGxsForumGroup& group, const std::vector<F
mPosts[0].prow = 0; mPosts[0].prow = 0;
bool has_unread_below,has_read_below ;
recursUpdateReadStatus(0,has_unread_below,has_read_below) ;
debug_dump(); debug_dump();
emit layoutChanged(); emit layoutChanged();
@ -923,12 +930,41 @@ void RsGxsForumModel::computeMessagesHierarchy(const RsGxsForumGroup& forum_grou
std::cerr << "GxsForumsFillThread::run() stopped: " << (wasStopped() ? "yes" : "no") << std::endl; std::cerr << "GxsForumsFillThread::run() stopped: " << (wasStopped() ? "yes" : "no") << std::endl;
#endif #endif
}
void RsGxsForumModel::setMsgReadStatus(const QModelIndex& i,bool read_status,bool with_children)
{
if(!i.isValid())
return ;
void *ref = i.internalPointer();
uint32_t entry = 0;
if(!convertRefPointerToTabEntry(ref,entry) || entry >= mPosts.size())
return ;
bool has_unread_below,has_read_below; bool has_unread_below,has_read_below;
recursSetMsgReadStatus(entry,read_status,with_children) ;
recursUpdateReadStatus(0,has_unread_below,has_read_below); recursUpdateReadStatus(0,has_unread_below,has_read_below);
} }
void RsGxsForumModel::recursSetMsgReadStatus(ForumModelIndex i,bool read_status,bool with_children)
{
if(read_status)
mPosts[i].mMsgStatus = 0;
else
mPosts[i].mMsgStatus = GXS_SERV::GXS_MSG_STATUS_GUI_UNREAD;
uint32_t token;
rsGxsForums->setMessageReadStatus(token,std::make_pair( mForumGroup.mMeta.mGroupId, mPosts[i].mMsgId ), read);
if(!with_children)
return;
for(uint32_t j=0;j<mPosts[i].mChildren.size();++j)
recursSetMsgReadStatus(mPosts[i].mChildren[j],read_status,with_children);
}
void RsGxsForumModel::recursUpdateReadStatus(ForumModelIndex i,bool& has_unread_below,bool& has_read_below) void RsGxsForumModel::recursUpdateReadStatus(ForumModelIndex i,bool& has_unread_below,bool& has_read_below)
{ {
has_unread_below = IS_MSG_UNREAD(mPosts[i].mMsgStatus); has_unread_below = IS_MSG_UNREAD(mPosts[i].mMsgStatus);
@ -962,8 +998,10 @@ static void recursPrintModel(const std::vector<ForumModelPostEntry>& entries,For
{ {
const ForumModelPostEntry& e(entries[index]); const ForumModelPostEntry& e(entries[index]);
std::cerr << std::string(depth*2,' ') << e.mAuthorId.toStdString() << " " << QString("%1").arg((uint32_t)e.mPostFlags,8,16,QChar('0')).toStdString() std::cerr << std::string(depth*2,' ') << e.mAuthorId.toStdString() << " "
<< " " << QDateTime::fromSecsSinceEpoch(e.mPublishTs).toString().toStdString() << " \"" << e.mTitle << "\"" << std::endl; << QString("%1").arg((uint32_t)e.mPostFlags,8,16,QChar('0')).toStdString() << " "
<< QString("%1").arg((uint32_t)e.mMsgStatus,8,16,QChar('0')).toStdString() << " "
<< QDateTime::fromSecsSinceEpoch(e.mPublishTs).toString().toStdString() << " \"" << e.mTitle << "\"" << std::endl;
for(uint32_t i=0;i<e.mChildren.size();++i) for(uint32_t i=0;i<e.mChildren.size();++i)
recursPrintModel(entries,e.mChildren[i],depth+1); recursPrintModel(entries,e.mChildren[i],depth+1);
@ -980,7 +1018,9 @@ void RsGxsForumModel::debug_dump()
{ {
const ForumModelPostEntry& e(mPosts[i]); const ForumModelPostEntry& e(mPosts[i]);
std::cerr << " " << i << " : " << e.mMsgId << " (from " << e.mAuthorId.toStdString() << ") " << QString("%1").arg((uint32_t)e.mPostFlags,8,16,QChar('0')).toStdString(); std::cerr << " " << i << " : " << e.mMsgId << " (from " << e.mAuthorId.toStdString() << ") "
<< QString("%1").arg((uint32_t)e.mPostFlags,8,16,QChar('0')).toStdString() << " "
<< QString("%1").arg((uint32_t)e.mMsgStatus,8,16,QChar('0')).toStdString() << " ";
for(uint32_t i=0;i<e.mChildren.size();++i) for(uint32_t i=0;i<e.mChildren.size();++i)
std::cerr << " " << e.mChildren[i] ; std::cerr << " " << e.mChildren[i] ;

View File

@ -16,6 +16,7 @@ struct RsMsgMetaData
#include "retroshare/rsgxsforums.h" #include "retroshare/rsgxsforums.h"
#include "retroshare/rsgxsifacetypes.h" #include "retroshare/rsgxsifacetypes.h"
#include <QModelIndex> #include <QModelIndex>
#include <QColor>
// This class holds the actual hierarchy of posts, represented by identifiers // This class holds the actual hierarchy of posts, represented by identifiers
// It is responsible for auto-updating when necessary and holds a mutex to allow the Model to // It is responsible for auto-updating when necessary and holds a mutex to allow the Model to
@ -77,9 +78,19 @@ public:
StatusRole = Qt::UserRole+4, StatusRole = Qt::UserRole+4,
}; };
QModelIndex root() const{ return createIndex(0,0,(void*)NULL) ;}
// This method will asynchroneously update the data // This method will asynchroneously update the data
void setForum(const RsGxsGroupId& forumGroup); void setForum(const RsGxsGroupId& forumGroup);
void setTextColorRead (QColor color) { mTextColorRead = color;}
void setTextColorUnread (QColor color) { mTextColorUnread = color;}
void setTextColorUnreadChildren(QColor color) { mTextColorUnreadChildren = color;}
void setTextColorNotSubscribed (QColor color) { mTextColorNotSubscribed = color;}
void setTextColorMissing (QColor color) { mTextColorMissing = color;}
void setMsgReadStatus(const QModelIndex &i, bool read_status, bool with_children);
int rowCount(const QModelIndex& parent = QModelIndex()) const override; int rowCount(const QModelIndex& parent = QModelIndex()) const override;
int columnCount(const QModelIndex &parent = QModelIndex()) const override; int columnCount(const QModelIndex &parent = QModelIndex()) const override;
bool hasChildren(const QModelIndex &parent = QModelIndex()) const override; bool hasChildren(const QModelIndex &parent = QModelIndex()) const override;
@ -104,6 +115,7 @@ public:
QVariant authorRole (const ForumModelPostEntry& fmpe, int col) const; QVariant authorRole (const ForumModelPostEntry& fmpe, int col) const;
QVariant sortRole (const ForumModelPostEntry& fmpe, int col) const; QVariant sortRole (const ForumModelPostEntry& fmpe, int col) const;
QVariant fontRole (const ForumModelPostEntry& fmpe, int col) const; QVariant fontRole (const ForumModelPostEntry& fmpe, int col) const;
QVariant textColorRole(const ForumModelPostEntry& fmpe, int col) const;
/*! /*!
* \brief debug_dump * \brief debug_dump
@ -128,6 +140,7 @@ private:
void update_posts(const RsGxsGroupId &group_id); void update_posts(const RsGxsGroupId &group_id);
void setForumMessageSummary(const std::vector<RsGxsForumMsg>& messages); void setForumMessageSummary(const std::vector<RsGxsForumMsg>& messages);
void recursUpdateReadStatus(ForumModelIndex i,bool& has_unread_below,bool& has_read_below); void recursUpdateReadStatus(ForumModelIndex i,bool& has_unread_below,bool& has_read_below);
void recursSetMsgReadStatus(ForumModelIndex i,bool read_status,bool with_children);
static void generateMissingItem(const RsGxsMessageId &msgId,ForumModelPostEntry& entry); static void generateMissingItem(const RsGxsMessageId &msgId,ForumModelPostEntry& entry);
static ForumModelIndex addEntry(std::vector<ForumModelPostEntry>& posts,const ForumModelPostEntry& entry,ForumModelIndex parent); static ForumModelIndex addEntry(std::vector<ForumModelPostEntry>& posts,const ForumModelPostEntry& entry,ForumModelIndex parent);
@ -138,4 +151,10 @@ private:
void initEmptyHierarchy(std::vector<ForumModelPostEntry>& posts); void initEmptyHierarchy(std::vector<ForumModelPostEntry>& posts);
std::vector<ForumModelPostEntry> mPosts ; // store the list of posts updated from rsForums. std::vector<ForumModelPostEntry> mPosts ; // store the list of posts updated from rsForums.
QColor mTextColorRead ;
QColor mTextColorUnread ;
QColor mTextColorUnreadChildren;
QColor mTextColorNotSubscribed ;
QColor mTextColorMissing ;
}; };

View File

@ -170,7 +170,7 @@ public:
QPixmap pix = icon.pixmap(r.size()); QPixmap pix = icon.pixmap(r.size());
return QSize(pix.width() + fm.width(str),fm.height()); return QSize(pix.width() + fm.width(str),1.2*fm.height());
} }
virtual void paint(QPainter *painter, const QStyleOptionViewItem &option, const QModelIndex& index) const override virtual void paint(QPainter *painter, const QStyleOptionViewItem &option, const QModelIndex& index) const override
@ -215,6 +215,12 @@ public:
} }
}; };
void GxsForumThreadWidget::setTextColorRead (QColor color) { mTextColorRead = color; mThreadModel->setTextColorRead (color);}
void GxsForumThreadWidget::setTextColorUnread (QColor color) { mTextColorUnread = color; mThreadModel->setTextColorUnread (color);}
void GxsForumThreadWidget::setTextColorUnreadChildren(QColor color) { mTextColorUnreadChildren = color; mThreadModel->setTextColorUnreadChildren(color);}
void GxsForumThreadWidget::setTextColorNotSubscribed (QColor color) { mTextColorNotSubscribed = color; mThreadModel->setTextColorNotSubscribed (color);}
void GxsForumThreadWidget::setTextColorMissing (QColor color) { mTextColorMissing = color; mThreadModel->setTextColorMissing (color);}
GxsForumThreadWidget::GxsForumThreadWidget(const RsGxsGroupId &forumId, QWidget *parent) : GxsForumThreadWidget::GxsForumThreadWidget(const RsGxsGroupId &forumId, QWidget *parent) :
GxsMessageFrameWidget(rsGxsForums, parent), GxsMessageFrameWidget(rsGxsForums, parent),
ui(new Ui::GxsForumThreadWidget) ui(new Ui::GxsForumThreadWidget)
@ -234,6 +240,7 @@ GxsForumThreadWidget::GxsForumThreadWidget(const RsGxsGroupId &forumId, QWidget
setUpdateWhenInvisible(true); setUpdateWhenInvisible(true);
#ifdef TODO
/* Setup UI helper */ /* Setup UI helper */
mStateHelper->addWidget(mTokenTypeGroupData, ui->subscribeToolButton); mStateHelper->addWidget(mTokenTypeGroupData, ui->subscribeToolButton);
mStateHelper->addWidget(mTokenTypeGroupData, ui->newthreadButton); mStateHelper->addWidget(mTokenTypeGroupData, ui->newthreadButton);
@ -257,6 +264,7 @@ GxsForumThreadWidget::GxsForumThreadWidget(const RsGxsGroupId &forumId, QWidget
mStateHelper->addLoadPlaceholder(mTokenTypeMessageData, ui->postText); mStateHelper->addLoadPlaceholder(mTokenTypeMessageData, ui->postText);
//mStateHelper->addLoadPlaceholder(mTokenTypeMessageData, ui->threadTitle); //mStateHelper->addLoadPlaceholder(mTokenTypeMessageData, ui->threadTitle);
#endif
mSubscribeFlags = 0; mSubscribeFlags = 0;
mSignFlags = 0; mSignFlags = 0;
@ -583,14 +591,21 @@ void GxsForumThreadWidget::updateDisplay(bool complete)
} }
} }
bool GxsForumThreadWidget::getCurrentPost(ForumModelPostEntry& fmpe) const QModelIndex GxsForumThreadWidget::GxsForumThreadWidget::getCurrentIndex() const
{ {
QModelIndexList selectedIndexes = ui->threadTreeWidget->selectionModel()->selectedIndexes(); QModelIndexList selectedIndexes = ui->threadTreeWidget->selectionModel()->selectedIndexes();
if(selectedIndexes.size() != RsGxsForumModel::COLUMN_THREAD_NB_COLUMNS) // check that a single row is selected if(selectedIndexes.size() != RsGxsForumModel::COLUMN_THREAD_NB_COLUMNS) // check that a single row is selected
return false; return QModelIndex();
QModelIndex index = *selectedIndexes.begin(); return *selectedIndexes.begin();
}
bool GxsForumThreadWidget::getCurrentPost(ForumModelPostEntry& fmpe) const
{
QModelIndex index = getCurrentIndex() ;
if(!index.isValid())
return false ;
return mThreadModel->getPostData(index,fmpe); return mThreadModel->getPostData(index,fmpe);
} }
@ -1882,25 +1897,22 @@ void GxsForumThreadWidget::insertMessageData(const RsGxsForumMsg &msg)
bool setToReadOnActive = Settings->getForumMsgSetToReadOnActivate(); bool setToReadOnActive = Settings->getForumMsgSetToReadOnActivate();
uint32_t status = msg.mMeta.mMsgStatus ;//item->data(RsGxsForumModel::COLUMN_THREAD_DATA, ROLE_THREAD_STATUS).toUInt(); uint32_t status = msg.mMeta.mMsgStatus ;//item->data(RsGxsForumModel::COLUMN_THREAD_DATA, ROLE_THREAD_STATUS).toUInt();
#ifdef TODO QModelIndex index = getCurrentIndex();
QList<QTreeWidgetItem*> row;
row.append(item);
if (IS_MSG_NEW(status)) { if (IS_MSG_NEW(status)) {
if (setToReadOnActive) { if (setToReadOnActive) {
/* set to read */ /* set to read */
setMsgReadStatus(row, true); mThreadModel->setMsgReadStatus(index,true,false);
} else { } else {
/* set to unread by user */ /* set to unread by user */
setMsgReadStatus(row, false); mThreadModel->setMsgReadStatus(index,false,false);
} }
} else { } else {
if (setToReadOnActive && IS_MSG_UNREAD(status)) { if (setToReadOnActive && IS_MSG_UNREAD(status)) {
/* set to read */ /* set to read */
setMsgReadStatus(row, true); mThreadModel->setMsgReadStatus(index, true,false);
} }
} }
#endif
ui->time_label->setText(DateTime::formatLongDateTime(msg.mMeta.mPublishTs)); ui->time_label->setText(DateTime::formatLongDateTime(msg.mMeta.mPublishTs));
ui->by_label->setId(msg.mMeta.mAuthorId); ui->by_label->setId(msg.mMeta.mAuthorId);
@ -2045,6 +2057,7 @@ int GxsForumThreadWidget::getSelectedMsgCount(QList<QTreeWidgetItem*> *rows, QLi
void GxsForumThreadWidget::setMsgReadStatus(QList<QTreeWidgetItem*> &rows, bool read) void GxsForumThreadWidget::setMsgReadStatus(QList<QTreeWidgetItem*> &rows, bool read)
{ {
#ifdef TODO #ifdef TODO
QList<QTreeWidgetItem*>::iterator row; QList<QTreeWidgetItem*>::iterator row;
std::list<QTreeWidgetItem*> changedItems; std::list<QTreeWidgetItem*> changedItems;
@ -2132,11 +2145,25 @@ void GxsForumThreadWidget::showInPeopleTab()
void GxsForumThreadWidget::markMsgAsReadUnread (bool read, bool children, bool forum) void GxsForumThreadWidget::markMsgAsReadUnread (bool read, bool children, bool forum)
{ {
#ifdef TODO
if (groupId().isNull() || !IS_GROUP_SUBSCRIBED(mSubscribeFlags)) { if (groupId().isNull() || !IS_GROUP_SUBSCRIBED(mSubscribeFlags)) {
return; return;
} }
if(forum)
mThreadModel->setMsgReadStatus(mThreadModel->root(),read,children);
else
{
QModelIndexList selectedIndexes = ui->threadTreeWidget->selectionModel()->selectedIndexes();
if(selectedIndexes.size() != RsGxsForumModel::COLUMN_THREAD_NB_COLUMNS) // check that a single row is selected
return ;
QModelIndex index = *selectedIndexes.begin();
mThreadModel->setMsgReadStatus(index,read,children);
}
#ifdef TODO
/* get selected messages */ /* get selected messages */
QList<QTreeWidgetItem*> rows; QList<QTreeWidgetItem*> rows;
if (forum) { if (forum) {

View File

@ -59,11 +59,11 @@ public:
QColor textColorNotSubscribed() const { return mTextColorNotSubscribed; } QColor textColorNotSubscribed() const { return mTextColorNotSubscribed; }
QColor textColorMissing() const { return mTextColorMissing; } QColor textColorMissing() const { return mTextColorMissing; }
void setTextColorRead(QColor color) { mTextColorRead = color; } void setTextColorRead (QColor color) ;
void setTextColorUnread(QColor color) { mTextColorUnread = color; } void setTextColorUnread (QColor color) ;
void setTextColorUnreadChildren(QColor color) { mTextColorUnreadChildren = color; } void setTextColorUnreadChildren(QColor color) ;
void setTextColorNotSubscribed(QColor color) { mTextColorNotSubscribed = color; } void setTextColorNotSubscribed (QColor color) ;
void setTextColorMissing(QColor color) { mTextColorMissing = color; } void setTextColorMissing (QColor color) ;
/* GxsMessageFrameWidget */ /* GxsMessageFrameWidget */
virtual void groupIdChanged(); virtual void groupIdChanged();
@ -151,6 +151,7 @@ private slots:
private: private:
void insertMessageData(const RsGxsForumMsg &msg); void insertMessageData(const RsGxsForumMsg &msg);
bool getCurrentPost(ForumModelPostEntry& fmpe) const ; bool getCurrentPost(ForumModelPostEntry& fmpe) const ;
QModelIndex getCurrentIndex() const;
void insertMessage(); void insertMessage();
void insertGroupData(); void insertGroupData();