mirror of
https://git.jami.net/savoirfairelinux/jami-client-qt.git
synced 2025-08-03 14:25:38 +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 Qt.labs.qmlmodels
|
||||
|
||||
import SortFilterProxyModel 0.2
|
||||
|
||||
import net.jami.Models 1.1
|
||||
import net.jami.Adapters 1.1
|
||||
import net.jami.Constants 1.1
|
||||
|
@ -194,7 +196,21 @@ JamiListView {
|
|||
boundsBehavior: Flickable.StopAtBounds
|
||||
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 {
|
||||
id: delegateChooser
|
||||
|
|
|
@ -49,18 +49,13 @@ MessagesAdapter::MessagesAdapter(AppSettingsManager* settingsManager,
|
|||
: QmlAdapterBase(instance, parent)
|
||||
, settingsManager_(settingsManager)
|
||||
, previewEngine_(previewEngine)
|
||||
, filteredMsgListModel_(new FilteredMsgListModel(this))
|
||||
{
|
||||
connect(lrcInstance_, &LRCInstance::selectedConvUidChanged, [this]() {
|
||||
set_replyToId("");
|
||||
const QString& convId = lrcInstance_->get_selectedConvUid();
|
||||
const auto& conversation = lrcInstance_->getConversationFromConvUid(convId);
|
||||
filteredMsgListModel_->setSourceModel(conversation.interactions.get());
|
||||
set_messageListModel(QVariant::fromValue(filteredMsgListModel_));
|
||||
if (!conversation.typers.empty())
|
||||
set_currentConvComposingList(conversationTypersUrlToName(conversation.typers));
|
||||
else
|
||||
set_currentConvComposingList({});
|
||||
set_messageListModel(QVariant::fromValue(conversation.interactions.get()));
|
||||
set_currentConvComposingList(conversationTypersUrlToName(conversation.typers));
|
||||
});
|
||||
|
||||
connect(previewEngine_, &PreviewEngine::infoReady, this, &MessagesAdapter::onPreviewInfoReady);
|
||||
|
@ -104,7 +99,7 @@ MessagesAdapter::loadMoreMessages()
|
|||
void
|
||||
MessagesAdapter::loadConversationUntil(const QString& to)
|
||||
{
|
||||
if (auto* model = static_cast<MessageListModel*>(filteredMsgListModel_->sourceModel())) {
|
||||
if (auto* model = messageListModel_.value<MessageListModel*>()) {
|
||||
auto idx = model->indexOfMessage(to);
|
||||
if (idx == -1) {
|
||||
auto accountId = lrcInstance_->get_currentAccountId();
|
||||
|
@ -324,7 +319,7 @@ MessagesAdapter::getTransferStats(const QString& msgId, int status)
|
|||
QVariant
|
||||
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);
|
||||
if (idx != -1)
|
||||
return model->data(idx, role);
|
||||
|
@ -335,7 +330,7 @@ MessagesAdapter::dataForInteraction(const QString& interactionId, int role) cons
|
|||
int
|
||||
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 {};
|
||||
|
|
|
@ -25,33 +25,6 @@
|
|||
#include <QObject>
|
||||
#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 MessagesAdapter final : public QmlAdapterBase
|
||||
|
@ -138,7 +111,6 @@ private:
|
|||
|
||||
AppSettingsManager* settingsManager_;
|
||||
PreviewEngine* previewEngine_;
|
||||
FilteredMsgListModel* filteredMsgListModel_;
|
||||
|
||||
static constexpr const int loadChunkSize_ {20};
|
||||
};
|
||||
|
|
Loading…
Add table
Reference in a new issue