diff --git a/memorytests/CMakeLists.txt b/memorytests/CMakeLists.txt index 69dc03339..dc75f4fca 100644 --- a/memorytests/CMakeLists.txt +++ b/memorytests/CMakeLists.txt @@ -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 ) diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index 0bc055090..dcd407327 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -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() diff --git a/src/controller.cpp b/src/controller.cpp index 78f4f4069..0f50a04a5 100644 --- a/src/controller.cpp +++ b/src/controller.cpp @@ -15,10 +15,12 @@ #include #include +#include #include #include #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(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 diff --git a/src/libneochat/CMakeLists.txt b/src/libneochat/CMakeLists.txt index 7e0195982..759eb454b 100644 --- a/src/libneochat/CMakeLists.txt +++ b/src/libneochat/CMakeLists.txt @@ -13,6 +13,7 @@ target_sources(LibNeoChat PRIVATE emojitones.cpp eventhandler.cpp filetransferpseudojob.cpp + filetype.cpp linkpreviewer.cpp roomlastmessageprovider.cpp spacehierarchycache.cpp diff --git a/src/filetype.cpp b/src/libneochat/filetype.cpp similarity index 100% rename from src/filetype.cpp rename to src/libneochat/filetype.cpp diff --git a/src/filetype.h b/src/libneochat/filetype.h similarity index 97% rename from src/filetype.h rename to src/libneochat/filetype.h index 385f911a6..35db73b81 100644 --- a/src/filetype.h +++ b/src/libneochat/filetype.h @@ -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) /** diff --git a/src/roommanager.cpp b/src/roommanager.cpp index f150d65a9..d4e35fa82 100644 --- a/src/roommanager.cpp +++ b/src/roommanager.cpp @@ -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() diff --git a/src/timeline/CMakeLists.txt b/src/timeline/CMakeLists.txt index 8e6538a72..d2ff99d12 100644 --- a/src/timeline/CMakeLists.txt +++ b/src/timeline/CMakeLists.txt @@ -1,8 +1,8 @@ # SPDX-FileCopyrightText: 2024 James Graham # 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() diff --git a/src/config-neochat.h.in b/src/timeline/config-neochat.h.in similarity index 100% rename from src/config-neochat.h.in rename to src/timeline/config-neochat.h.in diff --git a/src/contentprovider.cpp b/src/timeline/contentprovider.cpp similarity index 93% rename from src/contentprovider.cpp rename to src/timeline/contentprovider.cpp index 62117a314..51f0ff292 100644 --- a/src/contentprovider.cpp +++ b/src/timeline/contentprovider.cpp @@ -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" diff --git a/src/contentprovider.h b/src/timeline/contentprovider.h similarity index 98% rename from src/contentprovider.h rename to src/timeline/contentprovider.h index 995952002..bbf02224e 100644 --- a/src/contentprovider.h +++ b/src/timeline/contentprovider.h @@ -81,6 +81,8 @@ public: */ Q_INVOKABLE PollHandler *handlerForPoll(NeoChatRoom *room, const QString &eventId); + void setThreadsEnabled(bool enableThreads); + private: explicit ContentProvider(QObject *parent = nullptr); diff --git a/src/enums/delegatetype.h b/src/timeline/enums/delegatetype.h similarity index 100% rename from src/enums/delegatetype.h rename to src/timeline/enums/delegatetype.h diff --git a/src/messageattached.cpp b/src/timeline/messageattached.cpp similarity index 100% rename from src/messageattached.cpp rename to src/timeline/messageattached.cpp diff --git a/src/messageattached.h b/src/timeline/messageattached.h similarity index 100% rename from src/messageattached.h rename to src/timeline/messageattached.h diff --git a/src/models/itinerarymodel.cpp b/src/timeline/models/itinerarymodel.cpp similarity index 100% rename from src/models/itinerarymodel.cpp rename to src/timeline/models/itinerarymodel.cpp diff --git a/src/models/itinerarymodel.h b/src/timeline/models/itinerarymodel.h similarity index 100% rename from src/models/itinerarymodel.h rename to src/timeline/models/itinerarymodel.h diff --git a/src/models/mediamessagefiltermodel.cpp b/src/timeline/models/mediamessagefiltermodel.cpp similarity index 100% rename from src/models/mediamessagefiltermodel.cpp rename to src/timeline/models/mediamessagefiltermodel.cpp diff --git a/src/models/mediamessagefiltermodel.h b/src/timeline/models/mediamessagefiltermodel.h similarity index 100% rename from src/models/mediamessagefiltermodel.h rename to src/timeline/models/mediamessagefiltermodel.h diff --git a/src/models/messagecontentfiltermodel.cpp b/src/timeline/models/messagecontentfiltermodel.cpp similarity index 100% rename from src/models/messagecontentfiltermodel.cpp rename to src/timeline/models/messagecontentfiltermodel.cpp diff --git a/src/models/messagecontentfiltermodel.h b/src/timeline/models/messagecontentfiltermodel.h similarity index 100% rename from src/models/messagecontentfiltermodel.h rename to src/timeline/models/messagecontentfiltermodel.h diff --git a/src/models/messagecontentmodel.cpp b/src/timeline/models/messagecontentmodel.cpp similarity index 97% rename from src/models/messagecontentmodel.cpp rename to src/timeline/models/messagecontentmodel.cpp index 591ea6ae7..da9745f6a 100644 --- a/src/models/messagecontentmodel.cpp +++ b/src/timeline/models/messagecontentmodel.cpp @@ -5,7 +5,6 @@ #include "contentprovider.h" #include "enums/messagecomponenttype.h" #include "eventhandler.h" -#include "neochatconfig.h" #include @@ -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 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" diff --git a/src/models/messagecontentmodel.h b/src/timeline/models/messagecontentmodel.h similarity index 97% rename from src/models/messagecontentmodel.h rename to src/timeline/models/messagecontentmodel.h index 07ceb26e2..78b6d02fb 100644 --- a/src/models/messagecontentmodel.h +++ b/src/timeline/models/messagecontentmodel.h @@ -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 m_room; QString m_eventId; @@ -150,4 +154,6 @@ private: bool m_emptyItinerary = false; void updateReactionModel(); + + static bool m_threadsEnabled; }; diff --git a/src/models/messagefiltermodel.cpp b/src/timeline/models/messagefiltermodel.cpp similarity index 90% rename from src/models/messagefiltermodel.cpp rename to src/timeline/models/messagefiltermodel.cpp index 36099b4db..7259bbf83 100644 --- a/src/models/messagefiltermodel.cpp +++ b/src/timeline/models/messagefiltermodel.cpp @@ -7,37 +7,23 @@ #include #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" diff --git a/src/models/messagefiltermodel.h b/src/timeline/models/messagefiltermodel.h similarity index 94% rename from src/models/messagefiltermodel.h rename to src/timeline/models/messagefiltermodel.h index de8fcdb5d..6645f19d9 100644 --- a/src/models/messagefiltermodel.h +++ b/src/timeline/models/messagefiltermodel.h @@ -58,7 +58,13 @@ public: */ [[nodiscard]] QHash 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; diff --git a/src/models/messagemodel.cpp b/src/timeline/models/messagemodel.cpp similarity index 92% rename from src/models/messagemodel.cpp rename to src/timeline/models/messagemodel.cpp index 1be3f4a3f..68ecacf1d 100644 --- a/src/models/messagemodel.cpp +++ b/src/timeline/models/messagemodel.cpp @@ -3,11 +3,9 @@ #include "messagemodel.h" -#include "neochatconfig.h" -#include "threadmodel.h" +#include #include -#include #include #include #if Quotient_VERSION_MINOR > 9 || (Quotient_VERSION_MINOR == 9 && Quotient_VERSION_PATCH > 1) @@ -26,6 +24,11 @@ using namespace Quotient; +std::function 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(&event.value().get()); - if (NeoChatConfig::self()->threads() && roomMessageEvent && roomMessageEvent->isThreaded()) { + if (m_threadsEnabled && roomMessageEvent && roomMessageEvent->isThreaded()) { return QVariant::fromValue(ContentProvider::self().contentModelForEvent(m_room, roomMessageEvent->threadRootEventId())); } return QVariant::fromValue(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(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(&event.value().get())) { @@ -501,4 +488,14 @@ bool MessageModel::event(QEvent *event) return QObject::event(event); } +void MessageModel::setHiddenFilter(std::function hiddenFilter) +{ + MessageModel::m_hiddenFilter = hiddenFilter; +} + +void MessageModel::setThreadsEnabled(bool enableThreads) +{ + MessageModel::m_threadsEnabled = enableThreads; +} + #include "moc_messagemodel.cpp" diff --git a/src/models/messagemodel.h b/src/timeline/models/messagemodel.h similarity index 94% rename from src/models/messagemodel.h rename to src/timeline/models/messagemodel.h index 835bba8bb..f8fff7f89 100644 --- a/src/models/messagemodel.h +++ b/src/timeline/models/messagemodel.h @@ -112,6 +112,10 @@ public: */ Q_INVOKABLE [[nodiscard]] int eventIdToRow(const QString &eventID) const; + static void setHiddenFilter(std::function 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 m_room; QPersistentModelIndex m_lastReadEventIndex; @@ -150,4 +156,7 @@ private: QMap> m_readMarkerModels; void createEventObjects(const Quotient::RoomEvent *event); + + static std::function m_hiddenFilter; + static bool m_threadsEnabled; }; diff --git a/src/models/pinnedmessagemodel.cpp b/src/timeline/models/pinnedmessagemodel.cpp similarity index 100% rename from src/models/pinnedmessagemodel.cpp rename to src/timeline/models/pinnedmessagemodel.cpp diff --git a/src/models/pinnedmessagemodel.h b/src/timeline/models/pinnedmessagemodel.h similarity index 100% rename from src/models/pinnedmessagemodel.h rename to src/timeline/models/pinnedmessagemodel.h diff --git a/src/models/pollanswermodel.cpp b/src/timeline/models/pollanswermodel.cpp similarity index 100% rename from src/models/pollanswermodel.cpp rename to src/timeline/models/pollanswermodel.cpp diff --git a/src/models/pollanswermodel.h b/src/timeline/models/pollanswermodel.h similarity index 100% rename from src/models/pollanswermodel.h rename to src/timeline/models/pollanswermodel.h diff --git a/src/models/reactionmodel.cpp b/src/timeline/models/reactionmodel.cpp similarity index 100% rename from src/models/reactionmodel.cpp rename to src/timeline/models/reactionmodel.cpp diff --git a/src/models/reactionmodel.h b/src/timeline/models/reactionmodel.h similarity index 100% rename from src/models/reactionmodel.h rename to src/timeline/models/reactionmodel.h diff --git a/src/models/readmarkermodel.cpp b/src/timeline/models/readmarkermodel.cpp similarity index 100% rename from src/models/readmarkermodel.cpp rename to src/timeline/models/readmarkermodel.cpp diff --git a/src/models/readmarkermodel.h b/src/timeline/models/readmarkermodel.h similarity index 100% rename from src/models/readmarkermodel.h rename to src/timeline/models/readmarkermodel.h diff --git a/src/models/searchmodel.cpp b/src/timeline/models/searchmodel.cpp similarity index 100% rename from src/models/searchmodel.cpp rename to src/timeline/models/searchmodel.cpp diff --git a/src/models/searchmodel.h b/src/timeline/models/searchmodel.h similarity index 100% rename from src/models/searchmodel.h rename to src/timeline/models/searchmodel.h diff --git a/src/models/threadmodel.cpp b/src/timeline/models/threadmodel.cpp similarity index 100% rename from src/models/threadmodel.cpp rename to src/timeline/models/threadmodel.cpp diff --git a/src/models/threadmodel.h b/src/timeline/models/threadmodel.h similarity index 100% rename from src/models/threadmodel.h rename to src/timeline/models/threadmodel.h diff --git a/src/models/timelinemessagemodel.cpp b/src/timeline/models/timelinemessagemodel.cpp similarity index 100% rename from src/models/timelinemessagemodel.cpp rename to src/timeline/models/timelinemessagemodel.cpp diff --git a/src/models/timelinemessagemodel.h b/src/timeline/models/timelinemessagemodel.h similarity index 100% rename from src/models/timelinemessagemodel.h rename to src/timeline/models/timelinemessagemodel.h diff --git a/src/models/timelinemodel.cpp b/src/timeline/models/timelinemodel.cpp similarity index 96% rename from src/models/timelinemodel.cpp rename to src/timeline/models/timelinemodel.cpp index 1f43545d3..90d2ff0e5 100644 --- a/src/models/timelinemodel.cpp +++ b/src/timeline/models/timelinemodel.cpp @@ -5,7 +5,7 @@ #include -#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 diff --git a/src/models/timelinemodel.h b/src/timeline/models/timelinemodel.h similarity index 99% rename from src/models/timelinemodel.h rename to src/timeline/models/timelinemodel.h index 858902b72..aca649f8f 100644 --- a/src/models/timelinemodel.h +++ b/src/timeline/models/timelinemodel.h @@ -156,6 +156,7 @@ public: Q_SIGNALS: void roomChanged(); + void threadsEnabledChanged(); private: TimelineMessageModel *m_timelineMessageModel = nullptr; diff --git a/src/pollhandler.cpp b/src/timeline/pollhandler.cpp similarity index 99% rename from src/pollhandler.cpp rename to src/timeline/pollhandler.cpp index 0374d8551..7ef737a9c 100644 --- a/src/pollhandler.cpp +++ b/src/timeline/pollhandler.cpp @@ -7,7 +7,6 @@ #include "events/pollevent.h" #include "neochatroom.h" -#include "pollanswermodel.h" #include #include diff --git a/src/pollhandler.h b/src/timeline/pollhandler.h similarity index 100% rename from src/pollhandler.h rename to src/timeline/pollhandler.h