Add feature to delete all loaded messages by user
This commit is contained in:
@@ -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)
|
||||
|
||||
@@ -12,10 +12,14 @@
|
||||
#include <QTextDocument>
|
||||
#include <functional>
|
||||
|
||||
#include <qcoro/qcorosignal.h>
|
||||
#include <qcoro/task.h>
|
||||
|
||||
#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();
|
||||
}
|
||||
}
|
||||
|
||||
void NeoChatRoom::deleteMessagesByUser(const QString &user)
|
||||
{
|
||||
doDeleteMessagesByUser(user);
|
||||
}
|
||||
|
||||
QCoro::Task<void> NeoChatRoom::doDeleteMessagesByUser(const QString &user)
|
||||
{
|
||||
QStringList events;
|
||||
for (const auto &event : messageEvents()) {
|
||||
if (event->senderId() == user && !event->isRedacted() && !event.viewAs<RedactionEvent>() && !event->isStateEvent()) {
|
||||
events += event->id();
|
||||
}
|
||||
}
|
||||
for (const auto &e : events) {
|
||||
auto job = connection()->callApi<RedactEventJob>(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;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -15,6 +15,8 @@
|
||||
#include <QPointer>
|
||||
#include <QTimer>
|
||||
|
||||
#include <qcoro/task.h>
|
||||
|
||||
#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<void> 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);
|
||||
};
|
||||
|
||||
Reference in New Issue
Block a user