diff --git a/CMakeLists.txt b/CMakeLists.txt index d48fbe46d..9137103e4 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -15,7 +15,7 @@ find_package(ECM ${KF5_MIN_VERSION} REQUIRED NO_MODULE) set(CMAKE_MODULE_PATH ${ECM_MODULE_PATH} ${CMAKE_SOURCE_DIR}/cmake) -set(CMAKE_CXX_STANDARD 17) +set(CMAKE_CXX_STANDARD 20) set(CMAKE_CXX_STANDARD_REQUIRED ON) set(KDE_COMPILERSETTINGS_LEVEL 5.84) @@ -110,6 +110,10 @@ set_package_properties(KQuickImageEditor PROPERTIES PURPOSE "Add image editing capability to image attachments" ) +find_package(QCoro REQUIRED) + +qcoro_enable_coroutines() + install(FILES org.kde.neochat.desktop DESTINATION ${KDE_INSTALL_APPDIR}) install(FILES org.kde.neochat.appdata.xml DESTINATION ${KDE_INSTALL_METAINFODIR}) install(FILES org.kde.neochat.svg DESTINATION ${KDE_INSTALL_FULL_ICONDIR}/hicolor/scalable/apps) diff --git a/imports/NeoChat/Dialog/UserDetailDialog.qml b/imports/NeoChat/Dialog/UserDetailDialog.qml index 32953dd85..c09f1b416 100644 --- a/imports/NeoChat/Dialog/UserDetailDialog.qml +++ b/imports/NeoChat/Dialog/UserDetailDialog.qml @@ -142,8 +142,19 @@ Kirigami.OverlaySheet { } } Kirigami.BasicListItem { - visible: user !== room.localUser + visible: user === room.localUser || room.canSendState("redact") + action: Kirigami.Action { + text: i18n("Delete recent messages by this user") + icon.name: "delete" + icon.color: Kirigami.Theme.negativeTextColor + onTriggered: { + room.deleteMessagesByUser(user.id) + } + } + } + Kirigami.BasicListItem { + visible: user !== room.localUser action: Kirigami.Action { text: i18n("Open a private chat") icon.name: "document-send" diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index b88b757e5..3b4d80812 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -60,7 +60,7 @@ if(NOT ANDROID) endif() target_include_directories(neochat PRIVATE ${CMAKE_BINARY_DIR}) -target_link_libraries(neochat PRIVATE Qt::Quick Qt::Qml Qt::Gui Qt::Network Qt::QuickControls2 KF5::I18n KF5::Kirigami2 KF5::Notifications KF5::ConfigCore KF5::ConfigGui KF5::CoreAddons Quotient cmark::cmark ${QTKEYCHAIN_LIBRARIES}) +target_link_libraries(neochat PRIVATE Qt::Quick Qt::Qml Qt::Gui Qt::Network Qt::QuickControls2 KF5::I18n KF5::Kirigami2 KF5::Notifications KF5::ConfigCore KF5::ConfigGui KF5::CoreAddons Quotient cmark::cmark ${QTKEYCHAIN_LIBRARIES} QCoro::QCoro) kconfig_add_kcfg_files(neochat GENERATE_MOC neochatconfig.kcfgc) if(NEOCHAT_FLATPAK) diff --git a/src/neochatroom.cpp b/src/neochatroom.cpp index 2d7f74e27..285657586 100644 --- a/src/neochatroom.cpp +++ b/src/neochatroom.cpp @@ -12,10 +12,14 @@ #include #include +#include +#include + #include "connection.h" #include "csapi/account-data.h" #include "csapi/content-repo.h" #include "csapi/leaving.h" +#include "csapi/redaction.h" #include "csapi/room_state.h" #include "csapi/rooms.h" #include "csapi/typing.h" @@ -720,4 +724,27 @@ QString NeoChatRoom::htmlSafeName() const QString NeoChatRoom::htmlSafeDisplayName() const { return displayName().toHtmlEscaped(); -} \ No newline at end of file +} + +void NeoChatRoom::deleteMessagesByUser(const QString &user) +{ + doDeleteMessagesByUser(user); +} + +QCoro::Task NeoChatRoom::doDeleteMessagesByUser(const QString &user) +{ + QStringList events; + for (const auto &event : messageEvents()) { + if (event->senderId() == user && !event->isRedacted() && !event.viewAs() && !event->isStateEvent()) { + events += event->id(); + } + } + for (const auto &e : events) { + auto job = connection()->callApi(id(), QUrl::toPercentEncoding(e), connection()->generateTxnId()); + co_await qCoro(job, &BaseJob::finished); + if (job->error() != BaseJob::Success) { + qWarning() << "Error: \"" << job->error() << "\" while deleting messages. Aborting"; + break; + } + } +} diff --git a/src/neochatroom.h b/src/neochatroom.h index 16d597d40..4f6689d7f 100644 --- a/src/neochatroom.h +++ b/src/neochatroom.h @@ -15,6 +15,8 @@ #include #include +#include + #include "neochatuser.h" #include "room.h" @@ -137,6 +139,7 @@ private: void onRedaction(const RoomEvent &prevEvent, const RoomEvent &after) override; static QString markdownToHTML(const QString &markdown); + QCoro::Task doDeleteMessagesByUser(const QString &user); private Q_SLOTS: void countChanged(); @@ -175,4 +178,5 @@ public Q_SLOTS: void addLocalAlias(const QString &alias); void removeLocalAlias(const QString &alias); void toggleReaction(const QString &eventId, const QString &reaction); + void deleteMessagesByUser(const QString &user); };