Move all timeline relevant models and classes to the module

This commit is contained in:
James Graham
2025-04-10 18:25:45 +00:00
parent 6ff32d0935
commit 3f457774dc
44 changed files with 206 additions and 115 deletions

View File

@@ -7,16 +7,19 @@ qt_add_executable(timeline-memtest
main.cpp
)
target_link_libraries(timeline-memtest PRIVATE neochatplugin timelineplugin)
target_link_libraries(timeline-memtest PRIVATE neochatplugin Timelineplugin)
target_link_libraries(timeline-memtest PUBLIC
Qt::Core
Qt::Quick
Qt::Qml
Qt::Gui
Qt::QuickControls2
Qt::Widgets
KF6::I18n
KF6::Kirigami
QuotientQt6
neochat
LibNeoChat
Timeline
)
ecm_add_qml_module(timeline-memtest URI org.kde.neochat.timeline-memtest GENERATE_PLUGIN_SOURCE
@@ -30,5 +33,5 @@ ecm_add_qml_module(timeline-memtest URI org.kde.neochat.timeline-memtest GENERAT
QtCore
QtQuick
IMPORTS
org.kde.neochat
org.kde.neochat.timeline
)

View File

@@ -8,14 +8,11 @@ if (NOT ANDROID AND NOT WIN32 AND NOT APPLE AND NOT NEOCHAT_FLATPAK AND NOT NEOC
endif()
add_subdirectory(libneochat)
add_subdirectory(timeline)
add_library(neochat STATIC
controller.cpp
controller.h
models/timelinemessagemodel.cpp
models/timelinemessagemodel.h
models/messagefiltermodel.cpp
models/messagefiltermodel.h
models/roomlistmodel.cpp
models/roomlistmodel.h
models/sortfilterspacelistmodel.cpp
@@ -53,8 +50,6 @@ add_library(neochat STATIC
models/devicesmodel.cpp
models/devicesmodel.h
models/devicesproxymodel.cpp
filetype.cpp
filetype.h
login.cpp
login.h
models/webshortcutmodel.cpp
@@ -63,8 +58,6 @@ add_library(neochat STATIC
blurhash.h
blurhashimageprovider.cpp
blurhashimageprovider.h
models/mediamessagefiltermodel.cpp
models/mediamessagefiltermodel.h
windowcontroller.cpp
windowcontroller.h
models/completionmodel.cpp
@@ -77,43 +70,31 @@ add_library(neochat STATIC
models/statemodel.h
models/statefiltermodel.cpp
models/statefiltermodel.h
models/searchmodel.cpp
models/searchmodel.h
logger.cpp
logger.h
models/stickermodel.cpp
models/stickermodel.h
models/imagepacksmodel.cpp
models/imagepacksmodel.h
models/reactionmodel.cpp
models/reactionmodel.h
models/livelocationsmodel.cpp
models/livelocationsmodel.h
models/locationsmodel.cpp
models/locationsmodel.h
locationhelper.cpp
locationhelper.h
pollhandler.cpp
registration.cpp
jobs/neochatgetcommonroomsjob.cpp
jobs/neochatgetcommonroomsjob.h
mediasizehelper.cpp
mediasizehelper.h
enums/delegatetype.h
colorschemer.cpp
colorschemer.h
models/notificationsmodel.cpp
models/notificationsmodel.h
models/timelinemodel.cpp
models/timelinemodel.h
models/itinerarymodel.cpp
models/itinerarymodel.h
proxycontroller.cpp
proxycontroller.h
models/linemodel.cpp
models/linemodel.h
models/messagecontentmodel.cpp
models/messagecontentmodel.h
enums/neochatroomtype.h
models/sortfilterroomtreemodel.cpp
models/sortfilterroomtreemodel.h
@@ -136,26 +117,12 @@ add_library(neochat STATIC
models/permissionsmodel.h
threepidbindhelper.cpp
threepidbindhelper.h
models/readmarkermodel.cpp
models/readmarkermodel.h
models/threadmodel.cpp
models/threadmodel.h
enums/roomsortparameter.cpp
enums/roomsortparameter.h
models/roomsortparametermodel.cpp
models/roomsortparametermodel.h
models/messagemodel.cpp
models/messagemodel.h
models/messagecontentfiltermodel.cpp
models/messagecontentfiltermodel.h
models/pinnedmessagemodel.cpp
models/pinnedmessagemodel.h
models/commonroomsmodel.cpp
models/commonroomsmodel.h
models/pollanswermodel.cpp
models/pollanswermodel.h
contentprovider.cpp
contentprovider.h
)
set_source_files_properties(qml/TextToSpeechWrapper.qml PROPERTIES
@@ -262,9 +229,6 @@ ecm_add_qml_module(neochat URI org.kde.neochat GENERATE_PLUGIN_SOURCE
qml/AvatarNotification.qml
qml/ReasonDialog.qml
qml/NewPollDialog.qml
SOURCES
messageattached.cpp
messageattached.h
DEPENDENCIES
QtCore
QtQuick
@@ -278,7 +242,6 @@ ecm_add_qml_module(neochat URI org.kde.neochat GENERATE_PLUGIN_SOURCE
)
add_subdirectory(settings)
add_subdirectory(timeline)
add_subdirectory(devtools)
add_subdirectory(login)
add_subdirectory(chatbar)
@@ -293,21 +256,10 @@ else()
qt_target_qml_sources(neochat QML_FILES qml/ShareActionStub.qml)
endif()
configure_file(config-neochat.h.in ${CMAKE_CURRENT_BINARY_DIR}/config-neochat.h)
if(WIN32)
set_target_properties(neochat PROPERTIES OUTPUT_NAME "neochatlib")
endif()
ecm_qt_declare_logging_category(neochat
HEADER "messagemodel_logging.h"
IDENTIFIER "Message"
CATEGORY_NAME "org.kde.neochat.messagemodel"
DESCRIPTION "Neochat: messagemodel"
DEFAULT_SEVERITY Info
EXPORT NEOCHAT
)
ecm_qt_declare_logging_category(neochat
HEADER "publicroomlist_logging.h"
IDENTIFIER "PublicRoomList"
@@ -367,9 +319,10 @@ else()
endif()
target_include_directories(neochat PRIVATE ${CMAKE_BINARY_DIR} ${CMAKE_CURRENT_SOURCE_DIR}/models ${CMAKE_CURRENT_SOURCE_DIR}/enums)
target_link_libraries(neochat PRIVATE settingsplugin timelineplugin devtoolsplugin loginplugin chatbarplugin)
target_link_libraries(neochat PRIVATE settingsplugin Timelineplugin devtoolsplugin loginplugin chatbarplugin)
target_link_libraries(neochat PUBLIC
LibNeoChat
Timeline
Qt::Core
Qt::Quick
Qt::Qml
@@ -506,7 +459,7 @@ if(ANDROID)
)
ecm_add_android_apk(neochat-app ANDROID_DIR ${CMAKE_SOURCE_DIR}/android)
else()
target_link_libraries(neochat PUBLIC Qt::Widgets KF6::KIOWidgets KF6::SyntaxHighlighting)
target_link_libraries(neochat PUBLIC Qt::Widgets KF6::KIOWidgets)
install(FILES neochat.notifyrc DESTINATION ${KDE_INSTALL_KNOTIFYRCDIR})
endif()

View File

@@ -15,10 +15,12 @@
#include <signal.h>
#include <Quotient/csapi/notifications.h>
#include <Quotient/events/roommemberevent.h>
#include <Quotient/qt_connection_util.h>
#include <Quotient/settings.h>
#include "models/actionsmodel.h"
#include "models/messagemodel.h"
#include "neochatconfig.h"
#include "neochatconnection.h"
#include "neochatroom.h"
@@ -68,6 +70,22 @@ Controller::Controller(QObject *parent)
ActionsModel::setAllowQuickEdit(NeoChatConfig::allowQuickEdit());
});
MessageModel::setHiddenFilter([](const RoomEvent *event) -> bool {
if (event->isStateEvent() && !NeoChatConfig::showStateEvent()) {
return true;
}
if (auto roomMemberEvent = eventCast<const RoomMemberEvent>(event)) {
if ((roomMemberEvent->isJoin() || roomMemberEvent->isLeave()) && !NeoChatConfig::showLeaveJoinEvent()) {
return true;
} else if (roomMemberEvent->isRename() && !roomMemberEvent->isJoin() && !roomMemberEvent->isLeave() && !NeoChatConfig::showRename()) {
return true;
} else if (roomMemberEvent->isAvatarUpdate() && !roomMemberEvent->isJoin() && !roomMemberEvent->isLeave() && !NeoChatConfig::showAvatarUpdate()) {
return true;
}
}
return false;
});
ProxyController::instance().setApplicationProxy();
#ifndef Q_OS_ANDROID

View File

@@ -13,6 +13,7 @@ target_sources(LibNeoChat PRIVATE
emojitones.cpp
eventhandler.cpp
filetransferpseudojob.cpp
filetype.cpp
linkpreviewer.cpp
roomlastmessageprovider.cpp
spacehierarchycache.cpp

View File

@@ -56,7 +56,11 @@ public:
*/
Q_INVOKABLE QMimeType mimeTypeForName(const QString &nameOrAlias) const;
enum MatchMode { MatchDefault, MatchExtension, MatchContent };
enum MatchMode {
MatchDefault,
MatchExtension,
MatchContent,
};
Q_ENUM(MatchMode)
/**

View File

@@ -5,9 +5,11 @@
#include "roommanager.h"
#include "chatbarcache.h"
#include "contentprovider.h"
#include "controller.h"
#include "eventhandler.h"
#include "models/actionsmodel.h"
#include "models/messagefiltermodel.h"
#include "neochatconfig.h"
#include "neochatconnection.h"
#include "neochatroom.h"
@@ -72,6 +74,49 @@ RoomManager::RoomManager(QObject *parent)
resolveResource(idOrUri, action);
});
connect(&ActionsModel::instance(), &ActionsModel::knockRoom, this, &RoomManager::knockRoom);
connect(NeoChatConfig::self(), &NeoChatConfig::ShowStateEventChanged, this, [this] {
if (m_messageFilterModel) {
m_messageFilterModel->invalidate();
}
});
connect(NeoChatConfig::self(), &NeoChatConfig::ShowLeaveJoinEventChanged, this, [this] {
if (m_messageFilterModel) {
m_messageFilterModel->invalidate();
}
});
connect(NeoChatConfig::self(), &NeoChatConfig::ShowRenameChanged, this, [this] {
if (m_messageFilterModel) {
m_messageFilterModel->invalidate();
}
});
connect(NeoChatConfig::self(), &NeoChatConfig::ShowAvatarUpdateChanged, this, [this] {
if (m_messageFilterModel) {
m_messageFilterModel->invalidate();
}
});
MessageFilterModel::setShowAllEvents(NeoChatConfig::self()->showAllEvents());
connect(NeoChatConfig::self(), &NeoChatConfig::ShowAllEventsChanged, this, [this] {
MessageFilterModel::setShowAllEvents(NeoChatConfig::self()->showAllEvents());
if (m_messageFilterModel) {
m_messageFilterModel->invalidate();
}
});
MessageFilterModel::setShowDeletedMessages(NeoChatConfig::self()->showDeletedMessages());
connect(NeoChatConfig::self(), &NeoChatConfig::ShowDeletedMessagesChanged, this, [this] {
MessageFilterModel::setShowDeletedMessages(NeoChatConfig::self()->showDeletedMessages());
if (m_messageFilterModel) {
m_messageFilterModel->invalidate();
}
});
ContentProvider::self().setThreadsEnabled(NeoChatConfig::threads());
MessageModel::setThreadsEnabled(NeoChatConfig::threads());
connect(NeoChatConfig::self(), &NeoChatConfig::ThreadsChanged, this, [this] {
ContentProvider::self().setThreadsEnabled(NeoChatConfig::threads());
MessageModel::setThreadsEnabled(NeoChatConfig::threads());
if (m_timelineModel) {
Q_EMIT m_timelineModel->threadsEnabledChanged();
}
});
}
RoomManager::~RoomManager()

View File

@@ -1,8 +1,8 @@
# SPDX-FileCopyrightText: 2024 James Graham <james.h.graham@protonmail.com>
# SPDX-License-Identifier: BSD-2-Clause
qt_add_library(timeline STATIC)
ecm_add_qml_module(timeline GENERATE_PLUGIN_SOURCE
qt_add_library(Timeline STATIC)
ecm_add_qml_module(Timeline GENERATE_PLUGIN_SOURCE
URI org.kde.neochat.timeline
OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/src/org/kde/neochat/timeline
QML_FILES
@@ -55,8 +55,25 @@ ecm_add_qml_module(timeline GENERATE_PLUGIN_SOURCE
ThreadBodyComponent.qml
VideoComponent.qml
SOURCES
contentprovider.cpp
messageattached.cpp
pollhandler.cpp
timelinedelegate.cpp
timelinedelegate.h
enums/delegatetype.h
models/itinerarymodel.cpp
models/mediamessagefiltermodel.cpp
models/messagecontentmodel.cpp
models/messagecontentfiltermodel.cpp
models/messagefiltermodel.cpp
models/messagemodel.cpp
models/pinnedmessagemodel.cpp
models/pollanswermodel.cpp
models/reactionmodel.cpp
models/readmarkermodel.cpp
models/searchmodel.cpp
models/timelinemessagemodel.cpp
models/timelinemodel.cpp
models/threadmodel.cpp
RESOURCES
images/bike.svg
images/bus.svg
@@ -87,8 +104,26 @@ ecm_add_qml_module(timeline GENERATE_PLUGIN_SOURCE
QtQuick
)
target_link_libraries(timeline PRIVATE
Qt::Quick
KF6::Kirigami
LibNeoChat
configure_file(config-neochat.h.in ${CMAKE_CURRENT_BINARY_DIR}/config-neochat.h)
ecm_qt_declare_logging_category(Timeline
HEADER "messagemodel_logging.h"
IDENTIFIER "Message"
CATEGORY_NAME "org.kde.neochat.messagemodel"
DESCRIPTION "Neochat: messagemodel"
DEFAULT_SEVERITY Info
EXPORT NEOCHAT
)
target_include_directories(Timeline PRIVATE ${CMAKE_BINARY_DIR} ${CMAKE_CURRENT_SOURCE_DIR}/enums ${CMAKE_CURRENT_SOURCE_DIR}/models)
target_link_libraries(Timeline PRIVATE
LibNeoChat
Qt::Core
Qt::Quick
Qt::QuickControls2
KF6::Kirigami
)
if(NOT ANDROID)
target_link_libraries(Timeline PUBLIC KF6::SyntaxHighlighting)
endif()

View File

@@ -106,4 +106,13 @@ PollHandler *ContentProvider::handlerForPoll(NeoChatRoom *room, const QString &e
return m_pollHandlers.object(eventId);
}
void ContentProvider::setThreadsEnabled(bool enableThreads)
{
MessageContentModel::setThreadsEnabled(enableThreads);
for (const auto &key : m_eventContentModels.keys()) {
m_eventContentModels.object(key)->threadsEnabledChanged();
}
}
#include "moc_contentprovider.cpp"

View File

@@ -81,6 +81,8 @@ public:
*/
Q_INVOKABLE PollHandler *handlerForPoll(NeoChatRoom *room, const QString &eventId);
void setThreadsEnabled(bool enableThreads);
private:
explicit ContentProvider(QObject *parent = nullptr);

View File

@@ -5,7 +5,6 @@
#include "contentprovider.h"
#include "enums/messagecomponenttype.h"
#include "eventhandler.h"
#include "neochatconfig.h"
#include <QImageReader>
@@ -37,6 +36,8 @@
using namespace Quotient;
bool MessageContentModel::m_threadsEnabled = false;
MessageContentModel::MessageContentModel(NeoChatRoom *room, const QString &eventId, bool isReply, bool isPending, MessageContentModel *parent)
: QAbstractListModel(parent)
, m_room(room)
@@ -149,7 +150,7 @@ void MessageContentModel::initializeModel()
}
});
connect(NeoChatConfig::self(), &NeoChatConfig::ThreadsChanged, this, [this]() {
connect(this, &MessageContentModel::threadsEnabledChanged, this, [this]() {
updateReplyModel();
resetModel();
});
@@ -497,11 +498,10 @@ QList<MessageComponent> MessageContentModel::messageContentComponents(bool isEdi
}
#if Quotient_VERSION_MINOR > 9 || (Quotient_VERSION_MINOR == 9 && Quotient_VERSION_PATCH > 1)
if (NeoChatConfig::self()->threads() && roomMessageEvent && (roomMessageEvent->isThreaded() || m_room->threads().contains(roomMessageEvent->id()))
if (m_threadsEnabled && roomMessageEvent && (roomMessageEvent->isThreaded() || m_room->threads().contains(roomMessageEvent->id()))
&& roomMessageEvent->id() == roomMessageEvent->threadRootEventId()) {
#else
if (NeoChatConfig::self()->threads() && roomMessageEvent && roomMessageEvent->isThreaded()
&& roomMessageEvent->id() == roomMessageEvent->threadRootEventId()) {
if (m_threadsEnabled && roomMessageEvent && roomMessageEvent->isThreaded() && roomMessageEvent->id() == roomMessageEvent->threadRootEventId()) {
#endif
newComponents += MessageComponent{MessageComponentType::Separator, {}, {}};
newComponents += MessageComponent{MessageComponentType::ThreadBody, u"Thread Body"_s, {}};
@@ -530,7 +530,7 @@ void MessageContentModel::updateReplyModel()
if (roomMessageEvent == nullptr) {
return;
}
if (!roomMessageEvent->isReply(!NeoChatConfig::self()->threads()) || (roomMessageEvent->isThreaded() && NeoChatConfig::self()->threads())) {
if (!roomMessageEvent->isReply(m_threadsEnabled) || (roomMessageEvent->isThreaded() && m_threadsEnabled)) {
if (m_replyModel) {
delete m_replyModel;
}
@@ -541,7 +541,7 @@ void MessageContentModel::updateReplyModel()
return;
}
m_replyModel = new MessageContentModel(m_room, roomMessageEvent->replyEventId(!NeoChatConfig::self()->threads()), true, false, this);
m_replyModel = new MessageContentModel(m_room, roomMessageEvent->replyEventId(!m_threadsEnabled), true, false, this);
connect(m_replyModel, &MessageContentModel::eventUpdated, this, [this]() {
Q_EMIT dataChanged(index(0), index(0), {ReplyAuthorRole});
@@ -774,4 +774,9 @@ ThreadModel *MessageContentModel::modelForThread(const QString &threadRootId)
return ContentProvider::self().modelForThread(m_room, threadRootId);
}
void MessageContentModel::setThreadsEnabled(bool enableThreads)
{
m_threadsEnabled = enableThreads;
}
#include "moc_messagecontentmodel.cpp"

View File

@@ -112,10 +112,14 @@ public:
*/
Q_INVOKABLE ThreadModel *modelForThread(const QString &threadRootId);
static void setThreadsEnabled(bool enableThreads);
Q_SIGNALS:
void showAuthorChanged();
void eventUpdated();
void threadsEnabledChanged();
private:
QPointer<NeoChatRoom> m_room;
QString m_eventId;
@@ -150,4 +154,6 @@ private:
bool m_emptyItinerary = false;
void updateReactionModel();
static bool m_threadsEnabled;
};

View File

@@ -7,37 +7,23 @@
#include <QVariant>
#include "enums/delegatetype.h"
#include "neochatconfig.h"
#include "timelinemessagemodel.h"
using namespace Quotient;
bool MessageFilterModel::m_showAllEvents = false;
bool MessageFilterModel::m_showDeletedMessages = false;
MessageFilterModel::MessageFilterModel(QObject *parent, QAbstractItemModel *sourceModel)
: QSortFilterProxyModel(parent)
{
Q_ASSERT(sourceModel);
setSourceModel(sourceModel);
connect(NeoChatConfig::self(), &NeoChatConfig::ShowStateEventChanged, this, [this] {
invalidateFilter();
});
connect(NeoChatConfig::self(), &NeoChatConfig::ShowLeaveJoinEventChanged, this, [this] {
invalidateFilter();
});
connect(NeoChatConfig::self(), &NeoChatConfig::ShowRenameChanged, this, [this] {
invalidateFilter();
});
connect(NeoChatConfig::self(), &NeoChatConfig::ShowAvatarUpdateChanged, this, [this] {
invalidateFilter();
});
connect(NeoChatConfig::self(), &NeoChatConfig::ShowDeletedMessagesChanged, this, [this] {
invalidateFilter();
});
}
bool MessageFilterModel::filterAcceptsRow(int sourceRow, const QModelIndex &sourceParent) const
{
if (NeoChatConfig::self()->showAllEvents()) {
if (m_showAllEvents) {
return true;
}
return eventIsVisible(sourceRow, sourceParent);
@@ -48,7 +34,7 @@ bool MessageFilterModel::eventIsVisible(int sourceRow, const QModelIndex &source
const QModelIndex index = sourceModel()->index(sourceRow, 0, sourceParent);
// Don't show redacted (i.e. deleted) messages.
if (index.data(TimelineMessageModel::IsRedactedRole).toBool() && !NeoChatConfig::self()->showDeletedMessages()) {
if (index.data(TimelineMessageModel::IsRedactedRole).toBool() && !m_showDeletedMessages) {
return false;
}
@@ -79,7 +65,7 @@ bool MessageFilterModel::eventIsVisible(int sourceRow, const QModelIndex &source
QVariant MessageFilterModel::data(const QModelIndex &index, int role) const
{
if (role == TimelineMessageModel::DelegateTypeRole && NeoChatConfig::self()->showAllEvents()) {
if (role == TimelineMessageModel::DelegateTypeRole && m_showAllEvents) {
if (!eventIsVisible(index.row(), index.parent())) {
return DelegateType::Other;
}
@@ -220,4 +206,14 @@ QString MessageFilterModel::excessAuthors(int row) const
}
}
void MessageFilterModel::setShowAllEvents(bool enabled)
{
MessageFilterModel::m_showAllEvents = enabled;
}
void MessageFilterModel::setShowDeletedMessages(bool enabled)
{
MessageFilterModel::m_showDeletedMessages = enabled;
}
#include "moc_messagefiltermodel.cpp"

View File

@@ -58,7 +58,13 @@ public:
*/
[[nodiscard]] QHash<int, QByteArray> roleNames() const override;
static void setShowAllEvents(bool enabled);
static void setShowDeletedMessages(bool enabled);
private:
static bool m_showAllEvents;
static bool m_showDeletedMessages;
bool eventIsVisible(int sourceRow, const QModelIndex &sourceParent) const;
bool showAuthor(QModelIndex index) const;

View File

@@ -3,11 +3,9 @@
#include "messagemodel.h"
#include "neochatconfig.h"
#include "threadmodel.h"
#include <QEvent>
#include <Quotient/events/encryptedevent.h>
#include <Quotient/events/roommemberevent.h>
#include <Quotient/events/roommessageevent.h>
#include <Quotient/events/stickerevent.h>
#if Quotient_VERSION_MINOR > 9 || (Quotient_VERSION_MINOR == 9 && Quotient_VERSION_PATCH > 1)
@@ -26,6 +24,11 @@
using namespace Quotient;
std::function<bool(const Quotient::RoomEvent *)> MessageModel::m_hiddenFilter = [](const Quotient::RoomEvent *) -> bool {
return false;
};
bool MessageModel::m_threadsEnabled = false;
MessageModel::MessageModel(QObject *parent)
: QAbstractListModel(parent)
{
@@ -38,7 +41,7 @@ MessageModel::MessageModel(QObject *parent)
resetting = false;
});
connect(NeoChatConfig::self(), &NeoChatConfig::ThreadsChanged, this, [this]() {
connect(this, &MessageModel::threadsEnabledChanged, this, [this]() {
beginResetModel();
endResetModel();
});
@@ -129,7 +132,7 @@ QVariant MessageModel::data(const QModelIndex &idx, int role) const
}
auto roomMessageEvent = eventCast<const RoomMessageEvent>(&event.value().get());
if (NeoChatConfig::self()->threads() && roomMessageEvent && roomMessageEvent->isThreaded()) {
if (m_threadsEnabled && roomMessageEvent && roomMessageEvent->isThreaded()) {
return QVariant::fromValue<MessageContentModel *>(ContentProvider::self().contentModelForEvent(m_room, roomMessageEvent->threadRootEventId()));
}
return QVariant::fromValue<MessageContentModel *>(ContentProvider::self().contentModelForEvent(m_room, &event->get()));
@@ -176,22 +179,7 @@ QVariant MessageModel::data(const QModelIndex &idx, int role) const
return pendingIt->deliveryStatus();
}
if (EventHandler::isHidden(m_room, &event.value().get(), [](const RoomEvent *event) -> bool {
if (event->isStateEvent() && !NeoChatConfig::showStateEvent()) {
return true;
}
if (auto roomMemberEvent = eventCast<const RoomMemberEvent>(event)) {
if ((roomMemberEvent->isJoin() || roomMemberEvent->isLeave()) && !NeoChatConfig::showLeaveJoinEvent()) {
return true;
} else if (roomMemberEvent->isRename() && !roomMemberEvent->isJoin() && !roomMemberEvent->isLeave() && !NeoChatConfig::showRename()) {
return true;
} else if (roomMemberEvent->isAvatarUpdate() && !roomMemberEvent->isJoin() && !roomMemberEvent->isLeave()
&& !NeoChatConfig::showAvatarUpdate()) {
return true;
}
}
return false;
})) {
if (EventHandler::isHidden(m_room, &event.value().get(), m_hiddenFilter)) {
return EventStatus::Hidden;
}
@@ -204,8 +192,7 @@ QVariant MessageModel::data(const QModelIndex &idx, int role) const
}
}
#else
if (roomMessageEvent && roomMessageEvent->isThreaded() && roomMessageEvent->threadRootEventId() != event.value().get().id()
&& NeoChatConfig::threads()) {
if (roomMessageEvent && roomMessageEvent->isThreaded() && roomMessageEvent->threadRootEventId() != event.value().get().id() && m_threadsEnabled) {
return EventStatus::Hidden;
}
#endif
@@ -239,7 +226,7 @@ QVariant MessageModel::data(const QModelIndex &idx, int role) const
}
if (role == IsThreadedRole) {
if (!NeoChatConfig::self()->threads()) {
if (!m_threadsEnabled) {
return false;
}
if (auto roomMessageEvent = eventCast<const RoomMessageEvent>(&event.value().get())) {
@@ -501,4 +488,14 @@ bool MessageModel::event(QEvent *event)
return QObject::event(event);
}
void MessageModel::setHiddenFilter(std::function<bool(const Quotient::RoomEvent *)> hiddenFilter)
{
MessageModel::m_hiddenFilter = hiddenFilter;
}
void MessageModel::setThreadsEnabled(bool enableThreads)
{
MessageModel::m_threadsEnabled = enableThreads;
}
#include "moc_messagemodel.cpp"

View File

@@ -112,6 +112,10 @@ public:
*/
Q_INVOKABLE [[nodiscard]] int eventIdToRow(const QString &eventID) const;
static void setHiddenFilter(std::function<bool(const Quotient::RoomEvent *)> hiddenFilter);
static void setThreadsEnabled(bool enableThreads);
Q_SIGNALS:
/**
* @brief Emitted when the room is changed.
@@ -126,6 +130,8 @@ Q_SIGNALS:
*/
void newEventAdded(const Quotient::RoomEvent *event);
void threadsEnabledChanged();
protected:
QPointer<NeoChatRoom> m_room;
QPersistentModelIndex m_lastReadEventIndex;
@@ -150,4 +156,7 @@ private:
QMap<QString, QSharedPointer<ReadMarkerModel>> m_readMarkerModels;
void createEventObjects(const Quotient::RoomEvent *event);
static std::function<bool(const Quotient::RoomEvent *)> m_hiddenFilter;
static bool m_threadsEnabled;
};

View File

@@ -5,7 +5,7 @@
#include <Quotient/qt_connection_util.h>
#include "delegatetype.h"
#include "enums/delegatetype.h"
TimelineModel::TimelineModel(QObject *parent)
: QConcatenateTablesProxyModel(parent)
@@ -16,6 +16,8 @@ TimelineModel::TimelineModel(QObject *parent)
addSourceModel(m_timelineMessageModel);
m_timelineEndModel = new TimelineEndModel(this);
addSourceModel(m_timelineEndModel);
connect(this, &TimelineModel::threadsEnabledChanged, m_timelineMessageModel, &TimelineMessageModel::threadsEnabledChanged);
}
NeoChatRoom *TimelineModel::room() const

View File

@@ -156,6 +156,7 @@ public:
Q_SIGNALS:
void roomChanged();
void threadsEnabledChanged();
private:
TimelineMessageModel *m_timelineMessageModel = nullptr;

View File

@@ -7,7 +7,6 @@
#include "events/pollevent.h"
#include "neochatroom.h"
#include "pollanswermodel.h"
#include <Quotient/csapi/relations.h>
#include <Quotient/events/roompowerlevelsevent.h>