Page Menu
Home
Phorge
Search
Configure Global Search
Log In
Files
F114777
D171.1732576360.diff
No One
Temporary
Actions
View File
Edit File
Delete File
View Transforms
Subscribe
Award Token
Flag For Later
Size
9 KB
Referenced Files
None
Subscribers
None
D171.1732576360.diff
View Options
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
@@ -11,11 +11,67 @@
import moe.kazv.mxc.kazv as MK
import '..' as Kazv
import '.' as RoomSettings
+import '../matrix-helpers.js' as Helpers
Kirigami.SwipeListItem {
+ id: upper
property var stickerPack
+ property var stickerRoomsEvent
contentItem: Label {
text: stickerPack.packName || stickerPack.stateKey
}
+
+ actions: [
+ Kirigami.Action {
+ objectName: 'usePackAction'
+ text: l10n.get('room-sticker-packs-use-action')
+ checkable: true
+ checked: upper.getIsUsingPack()
+ icon.name: checked ? 'starred-symbolic' : 'non-starred-symbolic'
+ onTriggered: checked ? upper.usePack() : upper.disusePack()
+ }
+ ]
+
+ function getIsUsingPack() {
+ return Object.entries(stickerRoomsEvent.content.rooms || {})
+ .some(([roomId, packs]) =>
+ roomId === stickerPack.roomId &&
+ Object.entries(packs).some(([stateKey, _]) =>
+ stateKey === stickerPack.stateKey
+ )
+ );
+ }
+
+ function usePack() {
+ const content = stickerRoomsEvent.content;
+ content.rooms = content.rooms || {};
+ content.rooms[stickerPack.roomId] = content.rooms[stickerPack.roomId] || {};
+ content.rooms[stickerPack.roomId][stickerPack.stateKey] = {};
+ send(content);
+ }
+
+ function disusePack() {
+ const content = stickerRoomsEvent.content;
+ if (!stickerPack.stateKey in content.rooms?.[stickerPack.roomId]) {
+ return;
+ }
+ delete content.rooms[stickerPack.roomId][stickerPack.stateKey];
+ send(content);
+ }
+
+ property var sendAccountData: Kazv.AsyncHandler {
+ trigger: () => matrixSdk.sendAccountData(Helpers.imagePackRoomsEventType, content);
+ property var content
+ onResolved: (success, data) => {
+ if (!success) {
+ showPassiveNotification(l10n.get('room-sticker-packs-use-failed', { errorCode: data.errorCode, errorMsg: data.error }));
+ }
+ }
+ }
+
+ function send(content) {
+ sendAccountData.content = content;
+ sendAccountData.call();
+ }
}
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
@@ -29,6 +29,7 @@
model: roomStickerPacksPage.stickerPackList
delegate: RoomSettings.RoomStickerPackItemDelegate {
required property int index
+ stickerRoomsEvent: matrixSdk.stickerRoomsEvent()
stickerPack: stickerPackList.at(index)
}
}
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
@@ -125,3 +125,4 @@
}
const toolTipTimeout = 5000;
+const imagePackRoomsEventType = 'im.ponies.emote_rooms';
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
@@ -113,6 +113,8 @@
room-settings-set-topic-failed-prompt = 不能设置话题。错误代码:{ $errorCode }。错误讯息:{ $errorMsg }。
room-sticker-packs-action = 贴纸包...
room-sticker-packs-page-title = { $room } 中的贴纸包
+room-sticker-packs-use-action = 使用贴纸包
+room-sticker-packs-use-failed = 设置使用的贴纸包失败。错误代码:{ $errorCode }。错误讯息:{ $errorMsg }。
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
@@ -117,6 +117,8 @@
room-settings-set-topic-failed-prompt = Cannot set topic. Error code: { $errorCode }. Error message: { $errorMsg }.
room-sticker-packs-action = Sticker packs...
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-member-list-page-title = Members of { $room }
diff --git a/src/matrix-sdk.hpp b/src/matrix-sdk.hpp
--- a/src/matrix-sdk.hpp
+++ b/src/matrix-sdk.hpp
@@ -253,6 +253,13 @@
*/
MatrixStickerPackList *stickerPackList() const;
+ /**
+ * Get the sticker rooms account data event for the current account.
+ *
+ * @return A MatrixEvent representing the sticker rooms account data event.
+ */
+ MatrixEvent *stickerRoomsEvent() const;
+
/**
* Update the sticker pack from source.
*
@@ -264,6 +271,8 @@
MatrixUserGivenAttrsMap *userGivenNicknameMap() const;
+ MatrixPromise *sendAccountData(const QString &type, const QJsonObject &content);
+
private:
MatrixPromise *sendAccountDataImpl(Kazv::Event event);
diff --git a/src/matrix-sdk.cpp b/src/matrix-sdk.cpp
--- a/src/matrix-sdk.cpp
+++ b/src/matrix-sdk.cpp
@@ -41,6 +41,7 @@
#include "qt-job-handler.hpp"
#include "device-mgmt/matrix-device-list.hpp"
#include "matrix-sticker-pack-list.hpp"
+#include "matrix-sticker-pack-list-p.hpp"
#include "matrix-user-given-attrs-map.hpp"
#include "kazv-log.hpp"
#include "matrix-utils.hpp"
@@ -697,6 +698,11 @@
return new MatrixStickerPackList(m_d->clientOnSecondaryRoot);
}
+MatrixEvent *MatrixSdk::stickerRoomsEvent() const
+{
+ return new MatrixEvent(m_d->clientOnSecondaryRoot.accountData()[imagePackRoomsEventType][lager::lenses::or_default]);
+}
+
MatrixPromise *MatrixSdk::updateStickerPack(MatrixStickerPackSource source)
{
if (source.source == MatrixStickerPackSource::AccountData) {
@@ -721,6 +727,15 @@
);
}
+MatrixPromise *MatrixSdk::sendAccountData(const QString &type, const QJsonObject &content)
+{
+ Event e = json{
+ {"type", type.toStdString()},
+ {"content", content},
+ };
+ return sendAccountDataImpl(std::move(e));
+}
+
MatrixPromise *MatrixSdk::sendAccountDataImpl(Event event)
{
return new MatrixPromise(m_d->clientOnSecondaryRoot.setAccountData(event));
diff --git a/src/matrix-sticker-pack-list-p.hpp b/src/matrix-sticker-pack-list-p.hpp
new file mode 100644
--- /dev/null
+++ b/src/matrix-sticker-pack-list-p.hpp
@@ -0,0 +1,13 @@
+/*
+ * This file is part of kazv.
+ * SPDX-FileCopyrightText: 2020-2024 tusooa <tusooa@kazv.moe>
+ * SPDX-License-Identifier: AGPL-3.0-or-later
+ */
+
+#pragma once
+#include <kazv-defs.hpp>
+#include <string>
+
+inline const std::string accountDataEventType = "im.ponies.user_emotes";
+inline const std::string roomStateEventType = "im.ponies.room_emotes";
+inline const std::string imagePackRoomsEventType = "im.ponies.emote_rooms";
diff --git a/src/matrix-sticker-pack-list.cpp b/src/matrix-sticker-pack-list.cpp
--- a/src/matrix-sticker-pack-list.cpp
+++ b/src/matrix-sticker-pack-list.cpp
@@ -11,13 +11,10 @@
#include "matrix-sticker-pack.hpp"
#include "matrix-sticker-pack-list.hpp"
+#include "matrix-sticker-pack-list-p.hpp"
using namespace Kazv;
-static const std::string accountDataEventType = "im.ponies.user_emotes";
-static const std::string roomStateEventType = "im.ponies.room_emotes";
-static const std::string imagePackRoomsEventType = "im.ponies.emote_rooms";
-
using ImagePackRoomMap = immer::map<std::string/* room id */, immer::map<std::string/* */, json>>;
lager::reader<immer::flex_vector<MatrixStickerPackSource>> getEventsFromClient(Client client)
diff --git a/src/tests/quick-tests/tst_RoomStickerPackItemDelegate.qml b/src/tests/quick-tests/tst_RoomStickerPackItemDelegate.qml
new file mode 100644
--- /dev/null
+++ b/src/tests/quick-tests/tst_RoomStickerPackItemDelegate.qml
@@ -0,0 +1,94 @@
+/*
+ * 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 'test-helpers.js' as Helpers
+import 'test-helpers' as TestHelpers
+
+Item {
+ id: item
+ width: 800
+ height: 600
+
+ property var mockHelper: TestHelpers.MockHelper {}
+ property var matrixSdk: TestHelpers.MatrixSdkMock {
+ property var sendAccountData: mockHelper.promise()
+ }
+
+ KazvRS.RoomStickerPackItemDelegate {
+ id: packItem
+ }
+
+ TestCase {
+ id: roomStickerPackItemDelegateTest
+ name: 'RoomStickerPackItemDelegateTest'
+ when: windowShown
+
+ function init() {
+ item.mockHelper.clearAll();
+
+ packItem.stickerPack = {
+ packName: 'some pack',
+ stateKey: 'some-pack',
+ roomId: '!foo:example.com',
+ isRoomState: true,
+ };
+
+ packItem.stickerRoomsEvent = {
+ content: {
+ },
+ };
+ }
+
+ function test_usePack() {
+ const usePackAction = findChild(packItem, 'usePackAction');
+ verify(!usePackAction.checked);
+ usePackAction.trigger();
+ tryVerify(() => matrixSdk.sendAccountData.calledTimes() === 1);
+ verify(Helpers.deepEqual(
+ matrixSdk.sendAccountData.lastArgs()[1],
+ {
+ rooms: {
+ '!foo:example.com': {
+ 'some-pack': {},
+ },
+ },
+ },
+ ));
+ }
+
+ function test_disusePack() {
+ packItem.stickerRoomsEvent = {
+ content: {
+ rooms: {
+ '!foo:example.com': {
+ 'some-pack': {},
+ },
+ },
+ },
+ };
+
+ const usePackAction = findChild(packItem, 'usePackAction');
+ verify(usePackAction.checked);
+ usePackAction.trigger();
+ tryVerify(() => matrixSdk.sendAccountData.calledTimes() === 1);
+ verify(Helpers.deepEqual(
+ matrixSdk.sendAccountData.lastArgs()[1],
+ {
+ rooms: {
+ '!foo:example.com': {
+ },
+ },
+ },
+ ));
+ }
+ }
+}
File Metadata
Details
Attached
Mime Type
text/plain
Expires
Mon, Nov 25, 3:12 PM (13 h, 26 m)
Storage Engine
blob
Storage Format
Raw Data
Storage Handle
38854
Default Alt Text
D171.1732576360.diff (9 KB)
Attached To
Mode
D171: Add option to use or disuse a sticker pack
Attached
Detach File
Event Timeline
Log In to Comment