Page MenuHomePhorge

D175.1732306688.diff
No OneTemporary

Size
9 KB
Referenced Files
None
Subscribers
None

D175.1732306688.diff

diff --git a/src/contents/ui/room-settings/RoomStickerPackItemDelegate.qml b/src/contents/ui/room-settings/RoomStickerPackItemDelegate.qml
--- a/src/contents/ui/room-settings/RoomStickerPackItemDelegate.qml
+++ b/src/contents/ui/room-settings/RoomStickerPackItemDelegate.qml
@@ -8,6 +8,7 @@
import QtQuick.Layouts
import QtQuick.Controls
import org.kde.kirigami as Kirigami
+import org.kde.kirigamiaddons.delegates 1.0 as KAD
import moe.kazv.mxc.kazv as MK
import '..' as Kazv
import '.' as RoomSettings
@@ -18,8 +19,10 @@
property var stickerPack
property var stickerRoomsEvent
- contentItem: Label {
- text: stickerPack.packName || stickerPack.stateKey
+ text: stickerPack.packName || stickerPack.stateKey
+ contentItem: KAD.SubtitleContentItem {
+ itemDelegate: upper
+ subtitle: stickerPack.packName ? stickerPack.stateKey : ''
}
actions: [
diff --git a/src/contents/ui/room-settings/RoomStickerPacksPage.qml b/src/contents/ui/room-settings/RoomStickerPacksPage.qml
--- a/src/contents/ui/room-settings/RoomStickerPacksPage.qml
+++ b/src/contents/ui/room-settings/RoomStickerPacksPage.qml
@@ -11,6 +11,7 @@
import moe.kazv.mxc.kazv as MK
import '..' as Kazv
import '.' as RoomSettings
+import '../matrix-helpers.js' as Helpers
Kazv.ClosableScrollablePage {
id: roomStickerPacksPage
@@ -33,4 +34,57 @@
stickerPack: stickerPackList.at(index)
}
}
+
+ actions: [
+ Kirigami.Action {
+ objectName: 'addStickerPackAction'
+ text: l10n.get('room-sticker-packs-page-add-action')
+ icon.name: 'list-add'
+ onTriggered: addStickerPackPopup.open()
+ }
+ ]
+
+ property var addStickerPack: Kazv.AsyncHandler {
+ id: addStickerPack
+ trigger: () => {
+ const type = Helpers.roomImagePackEventType;
+ const stateKey = stickerPackStateKey.text;
+ const state = room.state(type, stateKey);
+ const content = state.content;
+ content.pack = content.pack || {};
+ content.pack.display_name = stickerPackName.text;
+ return roomStickerPacksPage.room.sendStateEvent({
+ type,
+ state_key: stateKey,
+ content,
+ });
+ }
+
+ onResolved: (success, data) => {
+ if (success) {
+ showPassiveNotification(l10n.get('room-sticker-packs-page-add-success'));
+ } else {
+ showPassiveNotification(l10n.get('room-sticker-packs-page-add-failed', { errorMsg: data.error, errorCode: data.errorCode }));
+ }
+ }
+ }
+
+ property var addStickerPackPopup: Kirigami.PromptDialog {
+ id: addStickerPackPopup
+ title: l10n.get('room-sticker-packs-page-add-popup-title')
+ standardButtons: Kirigami.Dialog.Ok | Kirigami.Dialog.Cancel
+ onAccepted: addStickerPack.call()
+ Kirigami.FormLayout {
+ TextField {
+ id: stickerPackName
+ objectName: 'stickerPackName'
+ Kirigami.FormData.label: l10n.get('room-sticker-packs-page-add-popup-name-prompt')
+ }
+ TextField {
+ id: stickerPackStateKey
+ objectName: 'stickerPackStateKey'
+ Kirigami.FormData.label: l10n.get('room-sticker-packs-page-add-popup-state-key-prompt')
+ }
+ }
+ }
}
diff --git a/src/js/matrix-helpers.js b/src/js/matrix-helpers.js
--- a/src/js/matrix-helpers.js
+++ b/src/js/matrix-helpers.js
@@ -126,3 +126,4 @@
const toolTipTimeout = 5000;
const imagePackRoomsEventType = 'im.ponies.emote_rooms';
+const roomImagePackEventType = 'im.ponies.room_emotes';
diff --git a/src/l10n/cmn-Hans/100-ui.ftl b/src/l10n/cmn-Hans/100-ui.ftl
--- a/src/l10n/cmn-Hans/100-ui.ftl
+++ b/src/l10n/cmn-Hans/100-ui.ftl
@@ -115,6 +115,12 @@
room-sticker-packs-page-title = { $room } 中的贴纸包
room-sticker-packs-use-action = 使用贴纸包
room-sticker-packs-use-failed = 设置使用的贴纸包失败。错误代码:{ $errorCode }。错误讯息:{ $errorMsg }。
+room-sticker-packs-page-add-action = 添加贴纸包
+room-sticker-packs-page-add-popup-title = 添加贴纸包
+room-sticker-packs-page-add-success = 已添加贴纸包。
+room-sticker-packs-page-add-failed = 无法添加贴纸包。错误代码:{ $errorCode }。错误讯息:{ $errorMsg }。
+room-sticker-packs-page-add-popup-name-prompt = 贴纸包名称:
+room-sticker-packs-page-add-popup-state-key-prompt = 状态键:
room-member-list-page-title = { $room } 的成员
diff --git a/src/l10n/en/100-ui.ftl b/src/l10n/en/100-ui.ftl
--- a/src/l10n/en/100-ui.ftl
+++ b/src/l10n/en/100-ui.ftl
@@ -119,6 +119,12 @@
room-sticker-packs-page-title = Sticker packs in { $room }
room-sticker-packs-use-action = Use sticker pack
room-sticker-packs-use-failed = Failed to set sticker packs in use. Error code: { $errorCode }. Error message: { $errorMsg }.
+room-sticker-packs-page-add-action = Add sticker pack
+room-sticker-packs-page-add-popup-title = Add sticker pack
+room-sticker-packs-page-add-success = Sticker pack added.
+room-sticker-packs-page-add-failed = Cannot add sticker pack. Error code: { $errorCode }. Error message: { $errorMsg }.
+room-sticker-packs-page-add-popup-name-prompt = Sticker pack name:
+room-sticker-packs-page-add-popup-state-key-prompt = State key:
room-member-list-page-title = Members of { $room }
diff --git a/src/matrix-room.hpp b/src/matrix-room.hpp
--- a/src/matrix-room.hpp
+++ b/src/matrix-room.hpp
@@ -71,6 +71,8 @@
Q_INVOKABLE MatrixRoomMember *member(QString userId) const;
+ Q_INVOKABLE MatrixEvent *state(const QString &type, const QString &stateKey) const;
+
Q_INVOKABLE MatrixRoomTimeline *timeline() const;
Q_INVOKABLE MatrixRoomPinnedEventsTimeline *pinnedEventsTimeline() const;
diff --git a/src/matrix-room.cpp b/src/matrix-room.cpp
--- a/src/matrix-room.cpp
+++ b/src/matrix-room.cpp
@@ -409,6 +409,11 @@
return new MatrixRoomMember(m_room.memberEventFor(userId.toStdString()));
}
+MatrixEvent *MatrixRoom::state(const QString &type, const QString &stateKey) const
+{
+ return new MatrixEvent(m_room.state({type.toStdString(), stateKey.toStdString()}));
+}
+
MatrixEvent *MatrixRoom::messageById(QString eventId) const
{
return new MatrixEvent(
diff --git a/src/tests/quick-tests/tst_RoomStickerPacksPage.qml b/src/tests/quick-tests/tst_RoomStickerPacksPage.qml
new file mode 100644
--- /dev/null
+++ b/src/tests/quick-tests/tst_RoomStickerPacksPage.qml
@@ -0,0 +1,127 @@
+/*
+ * This file is part of kazv.
+ * SPDX-FileCopyrightText: 2024 tusooa <tusooa@kazv.moe>
+ * SPDX-License-Identifier: AGPL-3.0-or-later
+ */
+
+import QtQuick
+import QtQuick.Layouts
+import QtTest
+import moe.kazv.mxc.kazv as MK
+import org.kde.kirigami as Kirigami
+import '../../contents/ui/room-settings' as KazvRS
+import '../../js/matrix-helpers.js' as MatrixHelpers
+import 'test-helpers.js' as Helpers
+import 'test-helpers' as TestHelpers
+
+Item {
+ id: item
+ width: 800
+ height: 600
+
+ property var l10n: Helpers.fluentMock
+ property var mockHelper: TestHelpers.MockHelper {}
+ property var showPassiveNotification: mockHelper.noop()
+ property var matrixSdk: TestHelpers.MatrixSdkMock {
+ property var sendAccountData: mockHelper.promise()
+ }
+
+ KazvRS.RoomStickerPacksPage {
+ id: page
+ anchors.fill: parent
+ room: QtObject {
+ function state(type, stateKey) {
+ return {
+ type,
+ stateKey,
+ content: stateKey === 'foo' ? {
+ images: {
+ 'mew': {},
+ },
+ } : stateKey === 'bar' ? {
+ pack: {
+ 'some': 'others',
+ },
+ } : {},
+ };
+ }
+
+ property var sendStateEvent: mockHelper.promise()
+ }
+ }
+
+ TestCase {
+ id: roomStickerPacksPageTest
+ name: 'RoomStickerPacksPageTest'
+ when: windowShown
+
+ function init() {
+ item.mockHelper.clearAll();
+ }
+
+ function test_addPack_data() {
+ return [
+ {
+ succ: true,
+ stateKey: '',
+ packContent: {
+ pack: {
+ display_name: 'some name',
+ },
+ },
+ },
+ {
+ succ: false,
+ stateKey: '',
+ packContent: {
+ pack: {
+ display_name: 'some name',
+ },
+ },
+ },
+ {
+ succ: true,
+ stateKey: 'foo',
+ packContent: {
+ images: {
+ 'mew': {},
+ },
+ pack: {
+ display_name: 'some name',
+ },
+ },
+ },
+ {
+ succ: true,
+ stateKey: 'bar',
+ packContent: {
+ pack: {
+ 'some': 'others',
+ display_name: 'some name',
+ },
+ },
+ },
+ ];
+ }
+
+ function test_addPack(data) {
+ findChild(page, 'addStickerPackAction').trigger();
+ tryVerify(() => findChild(page, 'stickerPackName').visible);
+ findChild(page, 'stickerPackName').text = 'some name';
+ findChild(page, 'stickerPackStateKey').text = data.stateKey;
+ page.addStickerPackPopup.accept();
+ tryVerify(() => page.room.sendStateEvent.calledTimes() === 1);
+ verify(Helpers.deepEqual(
+ page.room.sendStateEvent.lastArgs(),
+ [{
+ type: MatrixHelpers.roomImagePackEventType,
+ state_key: data.stateKey,
+ content: data.packContent,
+ }],
+ ));
+
+ page.room.sendStateEvent.lastRetVal().resolve(data.succ, {});
+ compare(item.showPassiveNotification.calledTimes(), 1);
+ }
+ }
+}

File Metadata

Mime Type
text/plain
Expires
Fri, Nov 22, 12:18 PM (19 h, 7 m)
Storage Engine
blob
Storage Format
Raw Data
Storage Handle
38969
Default Alt Text
D175.1732306688.diff (9 KB)

Event Timeline