mirror of
https://git.jami.net/savoirfairelinux/jami-client-qt.git
synced 2025-08-05 23:35:50 +02:00
messagelistmodel: replace C++ filter proxy model with QML-SFPM
Change-Id: I7471b4cf5539bd253d4d1b9e9b2bfd10030a9525
This commit is contained in:
parent
f644ab8a76
commit
cda1f335e7
3 changed files with 22 additions and 39 deletions
|
@ -22,6 +22,8 @@ import QtQuick.Controls
|
||||||
import QtQuick.Layouts
|
import QtQuick.Layouts
|
||||||
import Qt.labs.qmlmodels
|
import Qt.labs.qmlmodels
|
||||||
|
|
||||||
|
import SortFilterProxyModel 0.2
|
||||||
|
|
||||||
import net.jami.Models 1.1
|
import net.jami.Models 1.1
|
||||||
import net.jami.Adapters 1.1
|
import net.jami.Adapters 1.1
|
||||||
import net.jami.Constants 1.1
|
import net.jami.Constants 1.1
|
||||||
|
@ -194,7 +196,21 @@ JamiListView {
|
||||||
boundsBehavior: Flickable.StopAtBounds
|
boundsBehavior: Flickable.StopAtBounds
|
||||||
currentIndex: -1
|
currentIndex: -1
|
||||||
|
|
||||||
model: MessagesAdapter.messageListModel
|
model: SortFilterProxyModel {
|
||||||
|
// There doesn't seem to a subscription to property change
|
||||||
|
// events in the expression for sourceModel. This was originally
|
||||||
|
// masked behind an unchanging QSortFilterProxyModel object that
|
||||||
|
// just reset it's sourceModel in MessagesAdapter.
|
||||||
|
property var messageListModel: MessagesAdapter.messageListModel
|
||||||
|
onMessageListModelChanged: sourceModel = messageListModel
|
||||||
|
filters: ExpressionFilter {
|
||||||
|
readonly property int mergeType: Interaction.Type.MERGE
|
||||||
|
expression: Body !== "" && Type !== mergeType
|
||||||
|
}
|
||||||
|
sorters: ExpressionSorter {
|
||||||
|
expression: modelLeft.index > modelRight.index
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
delegate: DelegateChooser {
|
delegate: DelegateChooser {
|
||||||
id: delegateChooser
|
id: delegateChooser
|
||||||
|
|
|
@ -49,18 +49,13 @@ MessagesAdapter::MessagesAdapter(AppSettingsManager* settingsManager,
|
||||||
: QmlAdapterBase(instance, parent)
|
: QmlAdapterBase(instance, parent)
|
||||||
, settingsManager_(settingsManager)
|
, settingsManager_(settingsManager)
|
||||||
, previewEngine_(previewEngine)
|
, previewEngine_(previewEngine)
|
||||||
, filteredMsgListModel_(new FilteredMsgListModel(this))
|
|
||||||
{
|
{
|
||||||
connect(lrcInstance_, &LRCInstance::selectedConvUidChanged, [this]() {
|
connect(lrcInstance_, &LRCInstance::selectedConvUidChanged, [this]() {
|
||||||
set_replyToId("");
|
set_replyToId("");
|
||||||
const QString& convId = lrcInstance_->get_selectedConvUid();
|
const QString& convId = lrcInstance_->get_selectedConvUid();
|
||||||
const auto& conversation = lrcInstance_->getConversationFromConvUid(convId);
|
const auto& conversation = lrcInstance_->getConversationFromConvUid(convId);
|
||||||
filteredMsgListModel_->setSourceModel(conversation.interactions.get());
|
set_messageListModel(QVariant::fromValue(conversation.interactions.get()));
|
||||||
set_messageListModel(QVariant::fromValue(filteredMsgListModel_));
|
set_currentConvComposingList(conversationTypersUrlToName(conversation.typers));
|
||||||
if (!conversation.typers.empty())
|
|
||||||
set_currentConvComposingList(conversationTypersUrlToName(conversation.typers));
|
|
||||||
else
|
|
||||||
set_currentConvComposingList({});
|
|
||||||
});
|
});
|
||||||
|
|
||||||
connect(previewEngine_, &PreviewEngine::infoReady, this, &MessagesAdapter::onPreviewInfoReady);
|
connect(previewEngine_, &PreviewEngine::infoReady, this, &MessagesAdapter::onPreviewInfoReady);
|
||||||
|
@ -104,7 +99,7 @@ MessagesAdapter::loadMoreMessages()
|
||||||
void
|
void
|
||||||
MessagesAdapter::loadConversationUntil(const QString& to)
|
MessagesAdapter::loadConversationUntil(const QString& to)
|
||||||
{
|
{
|
||||||
if (auto* model = static_cast<MessageListModel*>(filteredMsgListModel_->sourceModel())) {
|
if (auto* model = messageListModel_.value<MessageListModel*>()) {
|
||||||
auto idx = model->indexOfMessage(to);
|
auto idx = model->indexOfMessage(to);
|
||||||
if (idx == -1) {
|
if (idx == -1) {
|
||||||
auto accountId = lrcInstance_->get_currentAccountId();
|
auto accountId = lrcInstance_->get_currentAccountId();
|
||||||
|
@ -324,7 +319,7 @@ MessagesAdapter::getTransferStats(const QString& msgId, int status)
|
||||||
QVariant
|
QVariant
|
||||||
MessagesAdapter::dataForInteraction(const QString& interactionId, int role) const
|
MessagesAdapter::dataForInteraction(const QString& interactionId, int role) const
|
||||||
{
|
{
|
||||||
if (auto* model = static_cast<MessageListModel*>(filteredMsgListModel_->sourceModel())) {
|
if (auto* model = messageListModel_.value<MessageListModel*>()) {
|
||||||
auto idx = model->indexOfMessage(interactionId);
|
auto idx = model->indexOfMessage(interactionId);
|
||||||
if (idx != -1)
|
if (idx != -1)
|
||||||
return model->data(idx, role);
|
return model->data(idx, role);
|
||||||
|
@ -335,7 +330,7 @@ MessagesAdapter::dataForInteraction(const QString& interactionId, int role) cons
|
||||||
int
|
int
|
||||||
MessagesAdapter::getIndexOfMessage(const QString& interactionId) const
|
MessagesAdapter::getIndexOfMessage(const QString& interactionId) const
|
||||||
{
|
{
|
||||||
if (auto* model = static_cast<MessageListModel*>(filteredMsgListModel_->sourceModel())) {
|
if (auto* model = messageListModel_.value<MessageListModel*>()) {
|
||||||
return model->indexOfMessage(interactionId);
|
return model->indexOfMessage(interactionId);
|
||||||
}
|
}
|
||||||
return {};
|
return {};
|
||||||
|
|
|
@ -25,33 +25,6 @@
|
||||||
#include <QObject>
|
#include <QObject>
|
||||||
#include <QString>
|
#include <QString>
|
||||||
|
|
||||||
#include <QSortFilterProxyModel>
|
|
||||||
|
|
||||||
class FilteredMsgListModel final : public QSortFilterProxyModel
|
|
||||||
{
|
|
||||||
Q_OBJECT
|
|
||||||
|
|
||||||
public:
|
|
||||||
explicit FilteredMsgListModel(QObject* parent = nullptr)
|
|
||||||
: QSortFilterProxyModel(parent)
|
|
||||||
{
|
|
||||||
sort(0, Qt::AscendingOrder);
|
|
||||||
}
|
|
||||||
|
|
||||||
bool filterAcceptsRow(int sourceRow, const QModelIndex& sourceParent) const override
|
|
||||||
{
|
|
||||||
auto index = sourceModel()->index(sourceRow, 0, sourceParent);
|
|
||||||
auto type = sourceModel()->data(index, MessageList::Role::Type).toInt();
|
|
||||||
auto hasBody = !sourceModel()->data(index, MessageList::Role::Body).toString().isEmpty();
|
|
||||||
return static_cast<interaction::Type>(type) != interaction::Type::MERGE && hasBody;
|
|
||||||
};
|
|
||||||
|
|
||||||
bool lessThan(const QModelIndex& left, const QModelIndex& right) const override
|
|
||||||
{
|
|
||||||
return left.row() > right.row();
|
|
||||||
};
|
|
||||||
};
|
|
||||||
|
|
||||||
class AppSettingsManager;
|
class AppSettingsManager;
|
||||||
|
|
||||||
class MessagesAdapter final : public QmlAdapterBase
|
class MessagesAdapter final : public QmlAdapterBase
|
||||||
|
@ -138,7 +111,6 @@ private:
|
||||||
|
|
||||||
AppSettingsManager* settingsManager_;
|
AppSettingsManager* settingsManager_;
|
||||||
PreviewEngine* previewEngine_;
|
PreviewEngine* previewEngine_;
|
||||||
FilteredMsgListModel* filteredMsgListModel_;
|
|
||||||
|
|
||||||
static constexpr const int loadChunkSize_ {20};
|
static constexpr const int loadChunkSize_ {20};
|
||||||
};
|
};
|
||||||
|
|
Loading…
Add table
Reference in a new issue