File indexing completed on 2024-05-12 16:25:05

0001 // SPDX-FileCopyrightText: 2021 Nicolas Fella <nicolas.fella@gmx.de>
0002 // SPDX-License-Identifier: GPL-2.0-only OR GPL-3.0-only OR LicenseRef-KDE-Accepted-LGPL
0003 
0004 #include "messagefiltermodel.h"
0005 
0006 #include "messageeventmodel.h"
0007 #include "neochatconfig.h"
0008 
0009 using namespace Quotient;
0010 
0011 MessageFilterModel::MessageFilterModel(QObject *parent)
0012     : QSortFilterProxyModel(parent)
0013 {
0014     connect(NeoChatConfig::self(), &NeoChatConfig::ShowStateEventChanged, this, [this] {
0015         invalidateFilter();
0016     });
0017     connect(NeoChatConfig::self(), &NeoChatConfig::ShowLeaveJoinEventChanged, this, [this] {
0018         invalidateFilter();
0019     });
0020     connect(NeoChatConfig::self(), &NeoChatConfig::ShowRenameChanged, this, [this] {
0021         invalidateFilter();
0022     });
0023     connect(NeoChatConfig::self(), &NeoChatConfig::ShowAvatarUpdateChanged, this, [this] {
0024         invalidateFilter();
0025     });
0026     connect(NeoChatConfig::self(), &NeoChatConfig::ShowDeletedMessagesChanged, this, [this] {
0027         invalidateFilter();
0028     });
0029 }
0030 
0031 bool MessageFilterModel::filterAcceptsRow(int sourceRow, const QModelIndex &sourceParent) const
0032 {
0033     const QModelIndex index = sourceModel()->index(sourceRow, 0, sourceParent);
0034 
0035     if (index.data(MessageEventModel::IsRedactedRole).toBool() && !NeoChatConfig::self()->showDeletedMessages()) {
0036         return false;
0037     }
0038 
0039     const int specialMarks = index.data(MessageEventModel::SpecialMarksRole).toInt();
0040     if (specialMarks == EventStatus::Hidden || specialMarks == EventStatus::Replaced) {
0041         return false;
0042     }
0043 
0044     const auto eventType = index.data(MessageEventModel::DelegateTypeRole).toInt();
0045 
0046     if (eventType == MessageEventModel::Other) {
0047         return false;
0048     }
0049 
0050     return true;
0051 }
0052 
0053 #include "moc_messagefiltermodel.cpp"