Page Menu
Home
Phorge
Search
Configure Global Search
Log In
Files
F113805
D24.1732489099.diff
No One
Temporary
Actions
View File
Edit File
Delete File
View Transforms
Subscribe
Award Token
Flag For Later
Size
10 KB
Referenced Files
None
Subscribers
None
D24.1732489099.diff
View Options
diff --git a/src/contents/ui/MessageNotification.qml b/src/contents/ui/MessageNotification.qml
--- a/src/contents/ui/MessageNotification.qml
+++ b/src/contents/ui/MessageNotification.qml
@@ -12,4 +12,9 @@
eventId: 'message'
text: 'test text'
title: 'test title'
+ property var roomId
+ defaultAction: l10n.get('notification-open')
+ onDefaultActivated: {
+ switchToRoomRequested(roomId);
+ }
}
diff --git a/src/contents/ui/Notifier.qml b/src/contents/ui/Notifier.qml
--- a/src/contents/ui/Notifier.qml
+++ b/src/contents/ui/Notifier.qml
@@ -27,7 +27,11 @@
const senderName = sender.name || sender.userId || '';
if (matrixSdk.shouldNotify(event)) {
console.debug('Push rules say we should notify this');
- const notification = notificationComp.createObject(notifier);
+ const notification = notificationComp.createObject(
+ notifier,
+ {
+ roomId,
+ });
notification.eventId = matrixSdk.shouldPlaySound(event) ? 'message' : 'messageWithoutSound';
notification.title = Helpers.roomNameOrHeroes(room, l10n);
const message = event.content.body;
diff --git a/src/contents/ui/PageManager.qml b/src/contents/ui/PageManager.qml
new file mode 100644
--- /dev/null
+++ b/src/contents/ui/PageManager.qml
@@ -0,0 +1,58 @@
+/*
+ * This file is part of kazv.
+ * SPDX-FileCopyrightText: 2024 tusooa <tusooa@kazv.moe>
+ * SPDX-License-Identifier: AGPL-3.0-or-later
+ */
+
+import QtQuick 2.15
+import org.kde.kirigami 2.20 as Kirigami
+import QtQuick.Controls 2.15
+import moe.kazv.mxc.kazv 0.0 as MK
+
+import '.' as Kazv
+
+QtObject {
+ property var pageStack
+ property var sdkVars
+ property var main
+
+ function switchToRoom(roomId) {
+ const nextPage = pageStack.get(pageStack.currentIndex + 1)
+ if (nextPage &&
+ nextPage instanceof Kazv.RoomPage &&
+ nextPage.roomId === roomId) {
+ pageStack.goForward();
+ } else {
+ sdkVars.currentRoomId = '';
+ sdkVars.currentRoomId = roomId;
+ }
+ }
+
+ function activateRoomPage() {
+ // Go back to the first page. This ensures that the room page
+ // will always be the second page.
+ while (pageStack.currentIndex > 0) {
+ pageStack.goBack();
+ }
+ pageStack.push(Qt.resolvedUrl("RoomPage.qml"), {
+ roomId: sdkVars.currentRoomId,
+ });
+ }
+
+ property var sdkVarsConn: Connections {
+ target: sdkVars
+
+ function onCurrentRoomIdChanged() {
+ if (sdkVars.currentRoomId.length) {
+ activateRoomPage();
+ }
+ }
+ }
+
+ property var mainConn: Connections {
+ target: main
+ function onSwitchToRoomRequested(roomId) {
+ switchToRoom(roomId);
+ }
+ }
+}
diff --git a/src/contents/ui/RoomListViewItemDelegate.qml b/src/contents/ui/RoomListViewItemDelegate.qml
--- a/src/contents/ui/RoomListViewItemDelegate.qml
+++ b/src/contents/ui/RoomListViewItemDelegate.qml
@@ -30,17 +30,7 @@
// against our newly-posted receipts
property var hasUnreadMessages: getHasUnreadMessages(roomTimeline, roomTimeline.count, lastUnreadMessageReaders ? lastUnreadMessageReaders.count : 0)
- onClicked: {
- const nextPage = pageStack.get(pageStack.currentIndex + 1)
- if (nextPage &&
- nextPage instanceof Kazv.RoomPage &&
- nextPage.roomId === item.roomId) {
- pageStack.goForward()
- } else {
- sdkVars.currentRoomId = ''
- sdkVars.currentRoomId = item.roomId
- }
- }
+ onClicked: switchToRoomRequested(item.roomId)
checkable: true
checked: sdkVars.currentRoomId == item.roomId
autoExclusive: true
diff --git a/src/contents/ui/main.qml b/src/contents/ui/main.qml
--- a/src/contents/ui/main.qml
+++ b/src/contents/ui/main.qml
@@ -161,10 +161,11 @@
}
}
- function activateRoomPage() {
- pageStack.push(Qt.resolvedUrl("RoomPage.qml"), {
- roomId: root.sdkVars.currentRoomId,
- });
+ signal switchToRoomRequested(string roomId)
+ property var pageManager: Kazv.PageManager {
+ pageStack: root.pageStack
+ sdkVars: root.sdkVars
+ main: root
}
function activateRoomSettingsPage(room) {
@@ -253,15 +254,6 @@
sdkVars.currentRoomId = '';
}
- Connections {
- target: sdkVars
- function onCurrentRoomIdChanged() {
- if (sdkVars.currentRoomId.length) {
- activateRoomPage()
- }
- }
- }
-
function switchAccount() {
pushLoginPage();
}
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
@@ -254,6 +254,7 @@
notification-message = <b>{ $user }:</b> { $message }
notification-message-no-content = <b>{ $user }</b> 给你发了一条讯息。
+notification-open = 打开
user-page-power-level = 权限等级:{ $powerLevel }
user-page-edit-power-level-action = 编辑
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
@@ -275,6 +275,7 @@
notification-message = <b>{ $user }:</b> { $message }
notification-message-no-content = <b>{ $user }</b> sent you a message.
+notification-open = Open
user-page-power-level = Power level: { $powerLevel }
user-page-edit-power-level-action = Edit
diff --git a/src/resources.qrc b/src/resources.qrc
--- a/src/resources.qrc
+++ b/src/resources.qrc
@@ -1,6 +1,7 @@
<RCC>
<qresource prefix="/">
<file alias="main.qml">contents/ui/main.qml</file>
+ <file alias="PageManager.qml">contents/ui/PageManager.qml</file>
<file alias="LoginPage.qml">contents/ui/LoginPage.qml</file>
<file alias="MainPage.qml">contents/ui/MainPage.qml</file>
<file alias="TabView.qml">contents/ui/TabView.qml</file>
diff --git a/src/tests/quick-tests/tst_Notifications.qml b/src/tests/quick-tests/tst_Notifications.qml
new file mode 100644
--- /dev/null
+++ b/src/tests/quick-tests/tst_Notifications.qml
@@ -0,0 +1,42 @@
+/*
+ * This file is part of kazv.
+ * SPDX-FileCopyrightText: 2024 tusooa <tusooa@kazv.moe>
+ * SPDX-License-Identifier: AGPL-3.0-or-later
+ */
+
+import QtQuick 2.15
+import QtQuick.Layouts 1.15
+import QtTest 1.0
+
+import '../../contents/ui' as Kazv
+import 'test-helpers.js' as Helpers
+import 'test-helpers' as TestHelpers
+
+TestCase {
+ id: notificationsTest
+ name: 'NotificationsTest'
+ when: true
+
+ signal switchToRoomRequested(string roomId)
+
+ SignalSpy {
+ id: switchToRoomSpy
+ }
+
+ Kazv.MessageNotification {
+ id: notification
+ roomId: '!foo:example.com'
+ }
+
+ function init() {
+ switchToRoomSpy.clear();
+ switchToRoomSpy.target = notificationsTest;
+ switchToRoomSpy.signalName = 'switchToRoomRequested';
+ }
+
+ function test_messageNotification() {
+ notification.defaultActivated();
+ tryCompare(switchToRoomSpy, 'count', 1);
+ compare(switchToRoomSpy.signalArguments[0][0], '!foo:example.com');
+ }
+}
diff --git a/src/tests/quick-tests/tst_PageManager.qml b/src/tests/quick-tests/tst_PageManager.qml
new file mode 100644
--- /dev/null
+++ b/src/tests/quick-tests/tst_PageManager.qml
@@ -0,0 +1,77 @@
+/*
+ * This file is part of kazv.
+ * SPDX-FileCopyrightText: 2023 tusooa <tusooa@kazv.moe>
+ * SPDX-License-Identifier: AGPL-3.0-or-later
+ */
+
+import QtQuick 2.3
+import QtQuick.Layouts 1.15
+import QtTest 1.0
+
+import '../../contents/ui' as Kazv
+import 'test-helpers.js' as Helpers
+import 'test-helpers' as TestHelpers
+
+import moe.kazv.mxc.kazv 0.0 as MK
+
+Item {
+ id: item
+ width: 800
+ height: 600
+
+ property string testRoomId: '!roomtest:example.org'
+ property var pageStack: QtObject {
+ property var currentIndex: 0
+ function get(index) {
+ const roomPageComp = Qt.createComponent(Qt.resolvedUrl("../../contents/ui/RoomPage.qml"))
+ return roomPageComp.createObject(item, { roomId: testRoomId })
+ }
+ function goBack() {
+ --currentIndex;
+ }
+ function goForward() {
+ ++currentIndex;
+ }
+ signal push(var url, var args)
+ }
+
+ SignalSpy {
+ id: pushSignalSpy
+ }
+
+ Kazv.PageManager {
+ id: pageManager
+ sdkVars: QtObject {
+ property string currentRoomId: testRoomId
+ }
+ pageStack: item.pageStack
+ main: QtObject {
+ signal switchToRoomRequested(string roomId)
+ }
+ }
+
+ TestCase {
+ id: pageManagerTest
+ name: 'PageManagerTest'
+
+ function init() {
+ pushSignalSpy.clear();
+ pushSignalSpy.target = pageStack;
+ pushSignalSpy.signalName = 'push';
+ pageStack.currentIndex = 0;
+ }
+
+ function test_returnToRoom() {
+ pageManager.main.switchToRoomRequested(testRoomId);
+ compare(pageStack.currentIndex, 1);
+ compare(pushSignalSpy.count, 0);
+ }
+
+ function test_switchToOtherRoom() {
+ compare(pushSignalSpy.count, 0);
+ pageManager.main.switchToRoomRequested('!otherroom:example.org');
+ tryCompare(pushSignalSpy, 'count', 1);
+ verify(Helpers.deepEqual(pushSignalSpy.signalArguments[0][1], { roomId: '!otherroom:example.org' }));
+ }
+ }
+}
diff --git a/src/tests/quick-tests/tst_RoomListViewItemDelegate.qml b/src/tests/quick-tests/tst_RoomListViewItemDelegate.qml
--- a/src/tests/quick-tests/tst_RoomListViewItemDelegate.qml
+++ b/src/tests/quick-tests/tst_RoomListViewItemDelegate.qml
@@ -121,19 +121,14 @@
property var matrixSdk: TestHelpers.MatrixSdkMock {
property var userId: '@foo:example.org'
}
- property var sdkVars: QtObject {
- property string currentRoomId: testRoomId
- }
property string testRoomId: 'room-test'
- property var returnRoom: false
- property var pageStack: QtObject {
- function get(index) {
- const roomPageComp = Qt.createComponent(Qt.resolvedUrl("../../contents/ui/RoomPage.qml"))
- return roomPageComp.createObject(item, { roomId: testRoomId })
- }
- function goForward() {
- returnRoom = true;
- }
+
+ signal switchToRoomRequested(string roomId)
+
+ SignalSpy {
+ id: switchToRoomSpy
+ target: item
+ signalName: 'switchToRoomRequested'
}
ColumnLayout {
@@ -204,9 +199,10 @@
}
function test_returnRoom() {
- verify(sdkVars.currentRoomId === testRoomId);
+ compare(switchToRoomSpy.count, 0);
mouseClick(delegateRoom);
- verify(returnRoom === true);
+ tryCompare(switchToRoomSpy, 'count', 1);
+ verify(Helpers.deepEqual(switchToRoomSpy.signalArguments[0], [testRoomId]));
}
}
}
File Metadata
Details
Attached
Mime Type
text/plain
Expires
Sun, Nov 24, 2:58 PM (9 h, 16 m)
Storage Engine
blob
Storage Format
Raw Data
Storage Handle
39823
Default Alt Text
D24.1732489099.diff (10 KB)
Attached To
Mode
D24: Activate the corresponding room when clicking on notification
Attached
Detach File
Event Timeline
Log In to Comment