mirror of
https://github.com/RetroShare/RetroShare.git
synced 2024-12-26 07:59:35 -05:00
added sorting based on most recent TS from children
This commit is contained in:
parent
37f721f305
commit
91321725e6
@ -42,6 +42,16 @@ void RsGxsForumModel::setTreeMode(TreeMode mode)
|
||||
emit layoutChanged();
|
||||
}
|
||||
|
||||
void RsGxsForumModel::setSortMode(SortMode mode)
|
||||
{
|
||||
emit layoutAboutToBeChanged();
|
||||
|
||||
mSortMode = mode;
|
||||
|
||||
emit dataChanged(createIndex(0,0,(void*)NULL), createIndex(0,COLUMN_THREAD_NB_COLUMNS-1,(void*)NULL));
|
||||
emit layoutChanged();
|
||||
}
|
||||
|
||||
void RsGxsForumModel::initEmptyHierarchy(std::vector<ForumModelPostEntry>& posts)
|
||||
{
|
||||
emit layoutAboutToBeChanged();
|
||||
@ -552,7 +562,11 @@ QVariant RsGxsForumModel::sortRole(const ForumModelPostEntry& fmpe,int column) c
|
||||
{
|
||||
switch(column)
|
||||
{
|
||||
case COLUMN_THREAD_DATE: return QVariant(QString::number(fmpe.mPublishTs)); // we should probably have leading zeroes here
|
||||
case COLUMN_THREAD_DATE: if(mSortMode == SORT_MODE_PUBLISH_TS)
|
||||
return QVariant(QString::number(fmpe.mPublishTs)); // we should probably have leading zeroes here
|
||||
else
|
||||
return QVariant(QString::number(fmpe.mMostRecentTsInThread)); // we should probably have leading zeroes here
|
||||
|
||||
case COLUMN_THREAD_READ: return QVariant((bool)IS_MSG_UNREAD(fmpe.mMsgStatus));
|
||||
case COLUMN_THREAD_DISTRIBUTION: return decorationRole(fmpe,column);
|
||||
case COLUMN_THREAD_AUTHOR:
|
||||
@ -657,8 +671,10 @@ void RsGxsForumModel::setPosts(const RsGxsForumGroup& group, const std::vector<F
|
||||
mPosts[0].prow = 0;
|
||||
|
||||
bool has_unread_below,has_read_below ;
|
||||
recursUpdateReadStatus(0,has_unread_below,has_read_below) ;
|
||||
|
||||
recursUpdateReadStatusAndTimes(0,has_unread_below,has_read_below) ;
|
||||
recursUpdateFilterStatus(0,0,QStringList());
|
||||
|
||||
#ifndef DEBUG_FORUMMODEL
|
||||
debug_dump();
|
||||
#endif
|
||||
@ -1129,7 +1145,7 @@ void RsGxsForumModel::setMsgReadStatus(const QModelIndex& i,bool read_status,boo
|
||||
|
||||
bool has_unread_below,has_read_below;
|
||||
recursSetMsgReadStatus(entry,read_status,with_children) ;
|
||||
recursUpdateReadStatus(0,has_unread_below,has_read_below);
|
||||
recursUpdateReadStatusAndTimes(0,has_unread_below,has_read_below);
|
||||
|
||||
emit dataChanged(createIndex(0,0,(void*)NULL), createIndex(0,COLUMN_THREAD_NB_COLUMNS-1,(void*)NULL));
|
||||
}
|
||||
@ -1151,20 +1167,25 @@ void RsGxsForumModel::recursSetMsgReadStatus(ForumModelIndex i,bool read_status,
|
||||
recursSetMsgReadStatus(mPosts[i].mChildren[j],read_status,with_children);
|
||||
}
|
||||
|
||||
void RsGxsForumModel::recursUpdateReadStatus(ForumModelIndex i,bool& has_unread_below,bool& has_read_below)
|
||||
void RsGxsForumModel::recursUpdateReadStatusAndTimes(ForumModelIndex i,bool& has_unread_below,bool& has_read_below)
|
||||
{
|
||||
has_unread_below = IS_MSG_UNREAD(mPosts[i].mMsgStatus);
|
||||
has_read_below = !IS_MSG_UNREAD(mPosts[i].mMsgStatus);
|
||||
|
||||
mPosts[i].mMostRecentTsInThread = mPosts[i].mPublishTs;
|
||||
|
||||
for(uint32_t j=0;j<mPosts[i].mChildren.size();++j)
|
||||
{
|
||||
bool ub,rb;
|
||||
|
||||
recursUpdateReadStatus(mPosts[i].mChildren[j],ub,rb);
|
||||
recursUpdateReadStatusAndTimes(mPosts[i].mChildren[j],ub,rb);
|
||||
|
||||
has_unread_below = has_unread_below || ub ;
|
||||
has_read_below = has_read_below || rb ;
|
||||
|
||||
if(mPosts[i].mMostRecentTsInThread < mPosts[mPosts[i].mChildren[j]].mMostRecentTsInThread)
|
||||
mPosts[i].mMostRecentTsInThread = mPosts[mPosts[i].mChildren[j]].mMostRecentTsInThread;
|
||||
|
||||
if(ub && rb) // optimization
|
||||
break;
|
||||
}
|
||||
|
@ -28,7 +28,7 @@ typedef uint32_t ForumModelIndex;
|
||||
|
||||
struct ForumModelPostEntry
|
||||
{
|
||||
ForumModelPostEntry() : mPublishTs(0),mPostFlags(0),mReputationWarningLevel(0),mMsgStatus(0),prow(0) {}
|
||||
ForumModelPostEntry() : mPublishTs(0),mMostRecentTsInThread(0),mPostFlags(0),mReputationWarningLevel(0),mMsgStatus(0),prow(0) {}
|
||||
|
||||
enum { // flags for display of posts. To be used in mPostFlags
|
||||
FLAG_POST_IS_PINNED = 0x0001,
|
||||
@ -44,6 +44,7 @@ struct ForumModelPostEntry
|
||||
RsGxsId mAuthorId ;
|
||||
RsGxsMessageId mMsgId;
|
||||
uint32_t mPublishTs;
|
||||
uint32_t mMostRecentTsInThread;
|
||||
uint32_t mPostFlags;
|
||||
int mReputationWarningLevel;
|
||||
int mMsgStatus;
|
||||
@ -87,6 +88,10 @@ public:
|
||||
TREE_MODE_TREE = 0x01,
|
||||
};
|
||||
|
||||
enum SortMode{ SORT_MODE_PUBLISH_TS = 0x00,
|
||||
SORT_MODE_CHILDREN_PUBLISH_TS = 0x01,
|
||||
};
|
||||
|
||||
QModelIndex root() const{ return createIndex(0,0,(void*)NULL) ;}
|
||||
QModelIndex getIndexOfMessage(const RsGxsMessageId& mid) const;
|
||||
|
||||
@ -119,6 +124,7 @@ public:
|
||||
// This method will asynchroneously update the data
|
||||
void setForum(const RsGxsGroupId& forumGroup);
|
||||
void setTreeMode(TreeMode mode) ;
|
||||
void setSortMode(SortMode mode) ;
|
||||
|
||||
void setTextColorRead (QColor color) { mTextColorRead = color;}
|
||||
void setTextColorUnread (QColor color) { mTextColorUnread = color;}
|
||||
@ -172,6 +178,7 @@ private:
|
||||
bool mUseChildTS;
|
||||
bool mFilteringEnabled;
|
||||
TreeMode mTreeMode;
|
||||
SortMode mSortMode;
|
||||
|
||||
void *getParentRef(void *ref,int& row) const;
|
||||
void *getChildRef(void *ref,int row) const;
|
||||
@ -183,9 +190,9 @@ private:
|
||||
|
||||
void update_posts(const RsGxsGroupId &group_id);
|
||||
void setForumMessageSummary(const std::vector<RsGxsForumMsg>& messages);
|
||||
void recursUpdateReadStatus(ForumModelIndex i,bool& has_unread_below,bool& has_read_below);
|
||||
void recursSetMsgReadStatus(ForumModelIndex i,bool read_status,bool with_children);
|
||||
void recursUpdateReadStatusAndTimes(ForumModelIndex i,bool& has_unread_below,bool& has_read_below);
|
||||
uint32_t recursUpdateFilterStatus(ForumModelIndex i,int column,const QStringList& strings);
|
||||
void recursSetMsgReadStatus(ForumModelIndex i,bool read_status,bool with_children);
|
||||
|
||||
static void generateMissingItem(const RsGxsMessageId &msgId,ForumModelPostEntry& entry);
|
||||
static ForumModelIndex addEntry(std::vector<ForumModelPostEntry>& posts,const ForumModelPostEntry& entry,ForumModelIndex parent);
|
||||
|
@ -2655,16 +2655,15 @@ void GxsForumThreadWidget::changedViewBox()
|
||||
// save index
|
||||
Settings->setValueToGroup("ForumThreadWidget", "viewBox", ui->viewBox->currentIndex());
|
||||
|
||||
switch(ui->viewBox->currentIndex())
|
||||
{
|
||||
default:
|
||||
case VIEW_THREADED:
|
||||
case VIEW_LAST_POST: mThreadModel->setTreeMode(RsGxsForumModel::TREE_MODE_TREE);
|
||||
break;
|
||||
if(ui->viewBox->currentIndex() == VIEW_FLAT)
|
||||
mThreadModel->setTreeMode(RsGxsForumModel::TREE_MODE_FLAT);
|
||||
else
|
||||
mThreadModel->setTreeMode(RsGxsForumModel::TREE_MODE_TREE);
|
||||
|
||||
case VIEW_FLAT: mThreadModel->setTreeMode(RsGxsForumModel::TREE_MODE_FLAT);
|
||||
break;
|
||||
}
|
||||
if(ui->viewBox->currentIndex() == VIEW_LAST_POST)
|
||||
mThreadModel->setSortMode(RsGxsForumModel::SORT_MODE_CHILDREN_PUBLISH_TS);
|
||||
else
|
||||
mThreadModel->setSortMode(RsGxsForumModel::SORT_MODE_PUBLISH_TS);
|
||||
}
|
||||
|
||||
void GxsForumThreadWidget::filterColumnChanged(int column)
|
||||
|
Loading…
Reference in New Issue
Block a user