Page MenuHomePhorge

D36.1732380334.diff
No OneTemporary

Size
5 KB
Referenced Files
None
Subscribers
None

D36.1732380334.diff

diff --git a/src/contents/ui/event-types/TextTemplate.qml b/src/contents/ui/event-types/TextTemplate.qml
--- a/src/contents/ui/event-types/TextTemplate.qml
+++ b/src/contents/ui/event-types/TextTemplate.qml
@@ -9,6 +9,7 @@
import QtQuick.Controls 2.15
import org.kde.kirigami 2.13 as Kirigami
+import moe.kazv.mxc.kazv 0.0 as MK
import '.' as Types
import '..' as Kazv
@@ -18,6 +19,23 @@
property var text
default property var children
property alias textFormat: label.textFormat
+
+ property var linkToActivate
+ property var selectedUserId
+ property var ensureMemberEvent: Kazv.AsyncHandler {
+ trigger: () => room.ensureStateEvent('m.room.member', upper.selectedUserId)
+ onResolved: (success, data) => {
+ if (success) {
+ activateUserPage(room.member(upper.selectedUserId), room);
+ } else {
+ // TODO: This opens the matrix.to url directly.
+ // In a future version this should take you to a window that
+ // gives you the option to create a DM with that user.
+ openLink(upper.linkToActivate);
+ }
+ }
+ }
+
Kazv.Bubble {
id: bubble
Layout.fillWidth: true
@@ -31,7 +49,14 @@
wrapMode: Text.Wrap
text: upper.text
onLinkActivated: (link) => {
- Qt.openUrlExternally(link);
+ const userId = MK.KazvUtil.matrixLinkUserId(link);
+ if (userId) {
+ upper.selectedUserId = userId;
+ upper.linkToActivate = link;
+ ensureMemberEvent.call();
+ } else {
+ openLink(link);
+ }
}
onHoveredLinkChanged: (link) => {
if (link) {
@@ -81,4 +106,8 @@
return event.content.body;
}
}
+
+ function openLink(link) {
+ Qt.openUrlExternally(link);
+ }
}
diff --git a/src/kazv-util.hpp b/src/kazv-util.hpp
--- a/src/kazv-util.hpp
+++ b/src/kazv-util.hpp
@@ -21,4 +21,8 @@
public Q_SLOTS:
QString escapeHtml(const QString &orig) const;
QString mimeTypeForUrl(const QUrl &url) const;
+
+ /// @return The user id for a given matrix link, or the empty string
+ /// if @c url is not a matrix link pointing to a user
+ QString matrixLinkUserId(const QString &url) const;
};
diff --git a/src/kazv-util.cpp b/src/kazv-util.cpp
--- a/src/kazv-util.cpp
+++ b/src/kazv-util.cpp
@@ -7,8 +7,10 @@
#include <libkazv-config.hpp>
#include <immer/config.hpp>
+#include <QUrl>
#include <QMimeDatabase>
+#include "matrix-link.hpp"
#include "kazv-util.hpp"
KazvUtil::KazvUtil(QObject *parent)
@@ -26,3 +28,12 @@
{
return QMimeDatabase().mimeTypeForUrl(url).name();
}
+
+QString KazvUtil::matrixLinkUserId(const QString &url) const
+{
+ MatrixLink link = QUrl(url);
+ if (link.isUser()) {
+ return link.identifiers()[0];
+ }
+ return QStringLiteral("");
+}
diff --git a/src/tests/quick-tests/tst_EventView.qml b/src/tests/quick-tests/tst_EventView.qml
--- a/src/tests/quick-tests/tst_EventView.qml
+++ b/src/tests/quick-tests/tst_EventView.qml
@@ -8,6 +8,8 @@
import QtQuick.Layouts 1.15
import QtTest 1.0
+import moe.kazv.mxc.kazv 0.0 as MK
+
import '../../contents/ui' as Kazv
import 'test-helpers.js' as Helpers
import 'test-helpers' as TestHelpers
@@ -17,6 +19,16 @@
width: 800
height: 600
+ property var promiseComp: Component {
+ TestHelpers.MatrixPromiseMock {
+ }
+ }
+
+ property var activateUserPageCalled: 0
+ function activateUserPage() {
+ ++activateUserPageCalled;
+ }
+
property var timeline: ({
gaps: [],
})
@@ -25,6 +37,9 @@
test_resendMessageLastTxnId: '',
test_removeLocalEchoCalled: 0,
test_removeLocalEchoLastTxnId: '',
+ test_ensureStateEventCalled: 0,
+ test_ensureStateEventCalledArgs: [],
+ test_ensureStateEventPromise: null,
resendMessage: (txnId) => {
++item.room.test_resendMessageCalled;
item.room.test_resendMessageLastTxnId = txnId;
@@ -33,6 +48,12 @@
++item.room.test_removeLocalEchoCalled;
item.room.test_removeLocalEchoLastTxnId = txnId;
},
+ ensureStateEvent: (type, stateKey) => {
+ ++item.room.test_ensureStateEventCalled;
+ item.room.test_ensureStateEventCalledArgs = [type, stateKey];
+ item.room.test_ensureStateEventPromise = promiseComp.createObject(item);
+ return item.room.test_ensureStateEventPromise;
+ },
messageById: (_id) => item.textEvent,
member: (_id) => ({}),
})
@@ -345,6 +366,10 @@
item.room.test_resendMessageLastTxnId = '';
item.room.test_removeLocalEchoCalled = 0;
item.room.test_removeLocalEchoLastTxnId = '';
+ item.room.test_ensureStateEventCalled = 0;
+ item.room.test_ensureStateEventCalledArgs = [];
+ item.room.test_ensureStateEventPromise = null;
+ item.activateUserPageCalled = 0;
}
function test_localEcho() {
@@ -454,5 +479,16 @@
verify(menu);
tryVerify(() => !findChild(menu, 'editMenuItem').enabled);
}
+
+ function test_userLink() {
+ const text = findChild(eventViewText, 'textEventContent');
+ text.linkActivated('https://matrix.to/#/@mew:example.com');
+ tryVerify(() => item.room.test_ensureStateEventCalled);
+ verify(Helpers.deepEqual(
+ item.room.test_ensureStateEventCalledArgs,
+ ['m.room.member', '@mew:example.com']));
+ item.room.test_ensureStateEventPromise.resolve(true, {});
+ tryVerify(() => item.activateUserPageCalled);
+ }
}
}

File Metadata

Mime Type
text/plain
Expires
Sat, Nov 23, 8:45 AM (14 h, 22 m)
Storage Engine
blob
Storage Format
Raw Data
Storage Handle
39260
Default Alt Text
D36.1732380334.diff (5 KB)

Event Timeline