diff --git a/CMakeLists.txt b/CMakeLists.txt index af50aff8..54dda226 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -766,6 +766,7 @@ set(QML_SOURCES resources/qml/dialogs/EventExpirationDialog.qml resources/qml/dialogs/ImageOverlay.qml resources/qml/dialogs/ImagePackEditorDialog.qml + resources/qml/dialogs/ImagePackDeleteDialog.qml resources/qml/dialogs/ImagePackSettingsDialog.qml resources/qml/dialogs/InputDialog.qml resources/qml/dialogs/InviteDialog.qml diff --git a/resources/qml/dialogs/ImagePackDeleteDialog.qml b/resources/qml/dialogs/ImagePackDeleteDialog.qml new file mode 100644 index 00000000..91407a9e --- /dev/null +++ b/resources/qml/dialogs/ImagePackDeleteDialog.qml @@ -0,0 +1,23 @@ +// SPDX-FileCopyrightText: Nheko Contributors +// +// SPDX-License-Identifier: GPL-3.0-or-later + +import Qt.labs.platform 1.1 as P +import QtQuick +import im.nheko + +P.MessageDialog { + id: deleteStickerPackRoot + + property SingleImagePackModel imagePack + + text: qsTr("Are you sure you wish to delete the sticker pack '%1'?").arg(imagePack.packname) + modality: Qt.ApplicationModal + flags: Qt.Tool | Qt.WindowStaysOnTopHint | Qt.WindowCloseButtonHint | Qt.WindowTitleHint + buttons: P.MessageDialog.Yes | P.MessageDialog.No + + onAccepted: { + console.info("deleting image pack " + imagePack.packname); + imagePack.remove() + } +} diff --git a/resources/qml/dialogs/ImagePackSettingsDialog.qml b/resources/qml/dialogs/ImagePackSettingsDialog.qml index 9f807e65..69068405 100644 --- a/resources/qml/dialogs/ImagePackSettingsDialog.qml +++ b/resources/qml/dialogs/ImagePackSettingsDialog.qml @@ -32,7 +32,11 @@ ApplicationWindow { ImagePackEditorDialog { } + } + Component { + id: packDeleteDialog + ImagePackDeleteDialog {} } AdaptiveLayout { @@ -189,16 +193,30 @@ ApplicationWindow { } - Button { + RowLayout { Layout.alignment: Qt.AlignHCenter - text: qsTr("Edit") - enabled: currentPack.canEdit - onClicked: { - var dialog = packEditor.createObject(timelineRoot, { - "imagePack": currentPack - }); - dialog.show(); - timelineRoot.destroyOnClose(dialog); + + Button { + text: qsTr("Edit") + enabled: currentPack.canEdit + onClicked: { + var dialog = packEditor.createObject(timelineRoot, { + "imagePack": currentPack + }); + dialog.show(); + timelineRoot.destroyOnClose(dialog); + } + } + Button { + text: qsTr("Remove") + enabled: currentPack.canEdit + onClicked: { + var dialog = packDeleteDialog.createObject(timelineRoot, { + "imagePack": currentPack + }); + dialog.open(); + timelineRoot.destroyOnClose(dialog); + } } } diff --git a/src/SingleImagePackModel.cpp b/src/SingleImagePackModel.cpp index 1adfdaa2..95a863d3 100644 --- a/src/SingleImagePackModel.cpp +++ b/src/SingleImagePackModel.cpp @@ -8,6 +8,7 @@ #include #include +#include #include #include @@ -285,18 +286,7 @@ SingleImagePackModel::save() }); } else { if (old_statekey_ != statekey_) { - http::client()->send_state_event( - roomid_, - to_string(mtx::events::EventType::ImagePackInRoom), - old_statekey_, - nlohmann::json::object(), - [](const mtx::responses::EventId &, mtx::http::RequestErr e) { - if (e) - ChatPage::instance()->showNotification( - tr("Failed to delete old image pack: %1") - .arg(QString::fromStdString(e->matrix_error.error))); - }); - old_statekey_ = statekey_; + this->remove(); } http::client()->send_state_event( @@ -314,6 +304,37 @@ SingleImagePackModel::save() } } +void +SingleImagePackModel::remove() +{ + // handle account pack deletion. + // Sadly we cannot actually delete the pack, + // so we just send an empty pack to clear out its information. + if (roomid_.empty()) { + http::client()->put_account_data( + mtx::events::msc2545::ImagePack(), [](mtx::http::RequestErr e) { + if (e) + ChatPage::instance()->showNotification( + tr("Failed to update image pack: %1") + .arg(QString::fromStdString(e->matrix_error.error))); + }); + return; + } + + http::client()->send_state_event( + roomid_, + to_string(mtx::events::EventType::ImagePackInRoom), + old_statekey_, + nlohmann::json::object(), + [](const mtx::responses::EventId &, mtx::http::RequestErr e) { + if (e) + ChatPage::instance()->showNotification( + tr("Failed to delete old image pack: %1") + .arg(QString::fromStdString(e->matrix_error.error))); + }); + old_statekey_ = statekey_; +} + void SingleImagePackModel::addStickers(QList files) { diff --git a/src/SingleImagePackModel.h b/src/SingleImagePackModel.h index e1ab98fb..d5cc818e 100644 --- a/src/SingleImagePackModel.h +++ b/src/SingleImagePackModel.h @@ -70,6 +70,7 @@ public: void setIsEmotePack(bool val); Q_INVOKABLE void save(); + Q_INVOKABLE void remove(); Q_INVOKABLE void addStickers(QList files); Q_INVOKABLE void remove(int index); Q_INVOKABLE void setAvatar(QUrl file);