Commit f947dd12 authored by Tobias Koenig's avatar Tobias Koenig
Browse files

Fix sorting/grouping of incoming messages

We have to resort the message list whenever new messages
are inserted to make it work in 'most-recent-message-in-thread'
mode.

BUG: 262735
parent 3ff1ec1c
......@@ -42,6 +42,7 @@ class ThreadGrouperModelPrivate
Akonadi::Item threadRoot( const QModelIndex &index ) const;
void populateThreadGrouperModel() const;
void resort();
mutable QHash<QByteArray, QByteArray> m_childParentMap; // maps an item to its thread leader item
mutable QHash<QByteArray, QSet<QByteArray> > m_parentChildrenMap; // maps a thread leader item to all its descendant items
......@@ -162,6 +163,12 @@ void ThreadGrouperModelPrivate::populateThreadGrouperModel() const
m_comparator->resetCaches();
}
void ThreadGrouperModelPrivate::resort()
{
Q_Q( ThreadGrouperModel );
q->sort( 0, q->sortOrder() );
}
ThreadGrouperModel::ThreadGrouperModel( ThreadGrouperComparator *comparator, QObject *parent )
: QSortFilterProxyModel( parent ), d_ptr( new ThreadGrouperModelPrivate( comparator, this ) )
......@@ -205,6 +212,8 @@ void ThreadGrouperModel::setSourceModel( QAbstractItemModel *sourceModel )
connect( sourceModel, SIGNAL( rowsInserted( QModelIndex, int, int ) ),
this, SLOT( populateThreadGrouperModel() ) );
connect( sourceModel, SIGNAL( rowsInserted( QModelIndex, int, int ) ),
this, SLOT( resort() ) );
connect( sourceModel, SIGNAL( rowsRemoved( QModelIndex, int, int ) ),
this, SLOT( populateThreadGrouperModel() ) );
......
......@@ -149,6 +149,7 @@ class MOBILEUI_EXPORT ThreadGrouperModel : public QSortFilterProxyModel
Q_DECLARE_PRIVATE( ThreadGrouperModel )
ThreadGrouperModelPrivate* const d_ptr;
Q_PRIVATE_SLOT( d_func(), void populateThreadGrouperModel() )
Q_PRIVATE_SLOT( d_func(), void resort() )
};
#endif
......@@ -210,7 +210,8 @@ QString MailThreadGrouperComparator::grouperString( const Akonadi::Item &item )
KMime::Message::Ptr msg;
if ( mSortingOption == SortByDateTimeMostRecent ) {
const Akonadi::Item::Id newestItem = mostRecentIdInThread( messageForItem( item ), item.id() );
const Akonadi::Item rootItem = threadItem( item );
const Akonadi::Item::Id newestItem = mostRecentIdInThread( messageForItem( rootItem ), rootItem.id() );
msg = messageForItem( Akonadi::Item( newestItem ) );
} else {
const Akonadi::Item rootItem = threadItem( item );
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment