Page MenuHomePhorge

D229.1758917335.diff
No OneTemporary

Size
27 KB
Referenced Files
None
Subscribers
None

D229.1758917335.diff

diff --git a/src/contents/ui/CreateRoomPage.qml b/src/contents/ui/CreateRoomPage.qml
--- a/src/contents/ui/CreateRoomPage.qml
+++ b/src/contents/ui/CreateRoomPage.qml
@@ -11,6 +11,7 @@
import org.kde.kirigami 2.13 as Kirigami
import '.' as Kazv
+import './matrix-helpers.js' as Helpers
import moe.kazv.mxc.kazv 0.0 as MK
@@ -140,6 +141,7 @@
Layout.fillWidth: true
}
Button {
+ id: addInviteUserButton
objectName: 'addInviteUserButton'
text: l10n.get('create-room-page-action-add-invite')
Layout.fillWidth: true
@@ -180,6 +182,9 @@
onResolved: {
if (success) {
+ if (typeDirect.checked && createRoomPage.inviteUserIds.length === 1) {
+ matrixSdk.addDirectRoom(createRoomPage.inviteUserIds[0], data.roomId);
+ }
showPassiveNotification(l10n.get('create-room-page-success-prompt'));
pageStack.removePage(createRoomPage);
} else {
@@ -187,4 +192,10 @@
}
}
}
+
+ function presetPage(userId) {
+ typeDirect.checked = true;
+ newInviteUserId.text = userId;
+ addInviteUserButton.click();
+ }
}
diff --git a/src/contents/ui/EventView.qml b/src/contents/ui/EventView.qml
--- a/src/contents/ui/EventView.qml
+++ b/src/contents/ui/EventView.qml
@@ -149,6 +149,7 @@
Loader {
sourceComponent: getSource(messageType)
id: loader
+ objectName: 'loader'
anchors.left: eventView.left
anchors.right: eventView.right
anchors.top: eventView.top
diff --git a/src/contents/ui/JoinRoomPage.qml b/src/contents/ui/JoinRoomPage.qml
--- a/src/contents/ui/JoinRoomPage.qml
+++ b/src/contents/ui/JoinRoomPage.qml
@@ -72,4 +72,9 @@
{
joinRoomHandler.call();
}
+
+ function presetPage(roomIdOrAlias, routingServers) {
+ idOrAlias.text = roomIdOrAlias;
+ servers.text = routingServers.join('\n');
+ }
}
diff --git a/src/contents/ui/RoomPage.qml b/src/contents/ui/RoomPage.qml
--- a/src/contents/ui/RoomPage.qml
+++ b/src/contents/ui/RoomPage.qml
@@ -265,4 +265,19 @@
onViewEventHistoryRequested: (eventId) => {
eventHistoryPopupComp.createObject(applicationWindow().overlay, { eventId }).open();
}
+
+ Timer {
+ id: goToEventTimer
+ property var eventId
+ onTriggered: {
+ console.log('goto event');
+ roomTimelineView.goToEvent(eventId);
+ }
+ }
+
+ function delayGoToEvent(eventId, time) {
+ goToEventTimer.interval = time;
+ goToEventTimer.eventId = eventId
+ goToEventTimer.start();
+ }
}
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
@@ -84,6 +84,24 @@
property var isHtmlFormatted: event.content.format === 'org.matrix.custom.html' && event.content.formatted_body
+ property var openRoomAliasLink: Kazv.AsyncHandler {
+ property var link
+ property var joinRoom
+ trigger: () => matrixSdk.getRoomIdByAlias(link.identifiers[0])
+
+ onResolved: {
+ if (success) {
+ if (sdkVars.roomList.contains(data.roomId)) {
+ switchToRoomRequested(data.roomId);
+ } else {
+ joinRoom(link.identifiers[0], link.routingServers);
+ }
+ } else {
+ showPassiveNotification(l10n.get('get-room-id-by-alias-failed-prompt', { errorCode: data.errorCode, errorMsg: data.error }));
+ }
+ }
+ }
+
function getMaybeFormattedText() {
if (isHtmlFormatted) {
const stylesheet = `
@@ -109,7 +127,77 @@
}
}
+ // https://github.com/matrix-org/matrix-spec-proposals/blob/main/proposals/2312-matrix-uri.md#operations-on-matrix-uris
function openLink(link) {
- Qt.openUrlExternally(link);
+ const matrixLink = MK.KazvUtil.matrixLink(link);
+
+ // Not a valid matrix uri
+ if (!matrixLink.isValid) {
+ Qt.openUrlExternally(link);
+ return;
+ }
+
+ const action = matrixLink.action;
+ const servers = matrixLink.routingServers;
+ const joinRoom = (roomId, servers) => {
+ pushJoinRoomPage();
+ pageStack.currentItem.presetPage(roomId, servers);
+ };
+
+ // Handle link to a user
+ if (matrixLink.isUser) {
+ const userId = matrixLink.identifiers[0];
+ if (action !== 'chat') {
+ mentionUserRequested(userId);
+ return;
+ }
+ // If the room with the user already exists, switch to the room.
+ // Otherwise try to create the room.
+ for (const roomId of matrixSdk.directRoomIds(userId)) {
+ const invitedOrJoined = (roomId) => {
+ const membership = sdkVars.roomList.room(roomId).membership;
+ return (membership == MK.MatrixRoom.Invite) || (membership == MK.MatrixRoom.Join);
+ };
+ if (sdkVars.roomList.contains(roomId) && invitedOrJoined(roomId)) {
+ switchToRoomRequested(roomId);
+ return;
+ }
+ }
+ pushCreateRoomPage();
+ pageStack.currentItem.presetPage(userId);
+ return;
+ }
+
+ // Handle link to a event
+ if (matrixLink.isEvent) {
+ const roomId = matrixLink.identifiers[0];
+ const eventId = matrixLink.identifiers[1];
+ if (sdkVars.roomList.contains(roomId)) {
+ switchToRoomRequested(roomId);
+ pageStack.currentItem.delayGoToEvent(eventId, 500);
+ } else {
+ joinRoom(roomId, servers);
+ }
+ return;
+ }
+
+ // Handle link to a room
+ if (matrixLink.isRoom) {
+ // If user has joined the room, open it.
+ // Otherwise try to join it.
+ if (matrixLink.isRoomAlias) {
+ openRoomAliasLink.link = matrixLink;
+ openRoomAliasLink.joinRoom = joinRoom;
+ openRoomAliasLink.call();
+ return;
+ }
+ const roomId = matrixLink.identifiers[0];
+ if (sdkVars.roomList.contains(roomId)) {
+ switchToRoomRequested(roomId);
+ } else {
+ joinRoom(roomId, servers);
+ }
+ return;
+ }
}
}
diff --git a/src/kazv-util.hpp b/src/kazv-util.hpp
--- a/src/kazv-util.hpp
+++ b/src/kazv-util.hpp
@@ -7,6 +7,8 @@
#pragma once
#include <kazv-defs.hpp>
+#include "matrix-link.hpp"
+
#include <QObject>
#include <QString>
#include <QQmlEngine>
@@ -30,6 +32,7 @@
/// @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;
+ MatrixLink *matrixLink(const QString &url) const;
private:
int m_kfQtMajorVersion;
diff --git a/src/kazv-util.cpp b/src/kazv-util.cpp
--- a/src/kazv-util.cpp
+++ b/src/kazv-util.cpp
@@ -37,3 +37,8 @@
}
return QStringLiteral("");
}
+
+MatrixLink *KazvUtil::matrixLink(const QString &url) const
+{
+ return new MatrixLink(QUrl(url));
+}
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
@@ -420,3 +420,5 @@
confirm-deletion-popup-message = 你确定要删除这个事件吗?
confirm-deletion-popup-confirm-action = 删除
confirm-deletion-popup-cancel-action = 取消
+
+get-room-id-by-alias-failed-prompt = 无法通过房间别名获取房间 id。错误码:{ $errorCode }。错误讯息:{ $errorMsg }。
\ No newline at end of file
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
@@ -442,3 +442,5 @@
confirm-deletion-popup-message = Are you sure you want to delete this event?
confirm-deletion-popup-confirm-action = Delete
confirm-deletion-popup-cancel-action = Cancel
+
+get-room-id-by-alias-failed-prompt = Unable to get room id by alias. Error code: { $errorCode }. Error message: { $errorMsg }.
\ No newline at end of file
diff --git a/src/matrix-link.hpp b/src/matrix-link.hpp
--- a/src/matrix-link.hpp
+++ b/src/matrix-link.hpp
@@ -17,14 +17,17 @@
/**
* A link that represents a Matrix object.
*/
-class MatrixLink
+class MatrixLink : public QObject
{
- Q_GADGET
+ Q_OBJECT
+ Q_PROPERTY(bool isValid READ isValid CONSTANT)
Q_PROPERTY(bool isUser READ isUser CONSTANT)
Q_PROPERTY(bool isRoom READ isRoom CONSTANT)
+ Q_PROPERTY(bool isRoomAlias READ isRoomAlias CONSTANT)
Q_PROPERTY(bool isEvent READ isEvent CONSTANT)
Q_PROPERTY(QStringList identifiers READ identifiers CONSTANT)
Q_PROPERTY(QStringList routingServers READ routingServers CONSTANT)
+ Q_PROPERTY(QString action READ action CONSTANT)
public:
enum Type {
@@ -40,6 +43,7 @@
bool isValid() const;
bool isUser() const;
bool isRoom() const;
+ bool isRoomAlias() const;
bool isEvent() const;
QStringList identifiers() const;
QStringList routingServers() const;
diff --git a/src/matrix-link.cpp b/src/matrix-link.cpp
--- a/src/matrix-link.cpp
+++ b/src/matrix-link.cpp
@@ -124,6 +124,11 @@
|| m_identifiers[0].first == RoomAlias);
}
+bool MatrixLink::isRoomAlias() const
+{
+ return isValid() && (m_identifiers[0].first == RoomAlias);
+}
+
bool MatrixLink::isEvent() const
{
return isValid() && m_identifiers.size() == 2;
diff --git a/src/matrix-room-list.hpp b/src/matrix-room-list.hpp
--- a/src/matrix-room-list.hpp
+++ b/src/matrix-room-list.hpp
@@ -45,4 +45,5 @@
Q_INVOKABLE MatrixRoom *at(int index) const;
Q_INVOKABLE QString roomIdAt(int index) const;
Q_INVOKABLE MatrixRoom *room(QString roomId) const;
+ Q_INVOKABLE bool contains(QString roomId) const;
};
diff --git a/src/matrix-room-list.cpp b/src/matrix-room-list.cpp
--- a/src/matrix-room-list.cpp
+++ b/src/matrix-room-list.cpp
@@ -192,3 +192,8 @@
userGivenNicknameMapFor(m_client)
);
}
+
+bool MatrixRoomList::contains(QString roomId) const
+{
+ return roomIds().contains(roomId);
+}
diff --git a/src/matrix-sdk.hpp b/src/matrix-sdk.hpp
--- a/src/matrix-sdk.hpp
+++ b/src/matrix-sdk.hpp
@@ -11,10 +11,12 @@
#include <QQmlEngine>
#include <QString>
+#include <string>
#include <memory>
#include <filesystem>
#include <lager/extra/qt.hpp>
+#include <immer/map.hpp>
#include <sdk-model.hpp>
#include <random-generator.hpp>
@@ -113,6 +115,8 @@
// Return true if the spec version of server in the range [minVer, maxVer]
Q_INVOKABLE bool checkSpecVersionRange(QString minVer, QString maxVer) const;
+ Q_INVOKABLE QStringList directRoomIds(QString userId) const;
+
Kazv::RandomInterface &randomGenerator() const;
private:
@@ -300,6 +304,10 @@
*/
MatrixPromise *getSpecVersions();
+ MatrixPromise *addDirectRoom(const QString &userId, const QString &roomId);
+
+ MatrixPromise *getRoomIdByAlias(const QString &roomAlias);
+
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
@@ -24,6 +24,8 @@
#include <client/sdk.hpp>
#include <client/notification-handler.hpp>
#include <crypto/base64.hpp>
+#include <csapi/directory.hpp>
+#include <client/alias.hpp>
#include <zug/util.hpp>
#include <lager/event_loop/qt.hpp>
@@ -459,6 +461,17 @@
}) != specVersions().end();
}
+QStringList MatrixSdk::directRoomIds(QString userId) const
+{
+ auto content = m_d->clientOnSecondaryRoot.
+ accountData().get()["m.direct"].content().get();
+ auto roomIds = QStringList{};
+ for (auto i : content[userId.toStdString()]) {
+ roomIds.push_back(QString::fromStdString(i.get<std::string>()));
+ }
+ return roomIds;
+}
+
std::string MatrixSdk::validateHomeserverUrl(const QString &url)
{
if (url.isEmpty()) {
@@ -887,6 +900,24 @@
return new MatrixPromise(m_d->clientOnSecondaryRoot.getVersions(LAGER_QT(serverUrl).get().toStdString()));
}
+MatrixPromise *MatrixSdk::addDirectRoom(const QString &userId, const QString &roomId)
+{
+ return new MatrixPromise(m_d->clientOnSecondaryRoot.addDirectRoom(userId.toStdString(), roomId.toStdString()));
+}
+
+MatrixPromise *MatrixSdk::getRoomIdByAlias(const QString &roomAlias)
+{
+ auto job = m_d->clientOnSecondaryRoot
+ .getRoomIdByAliasJob(roomAlias.toStdString());
+ auto jh = m_d->jobHandler;
+ return new MatrixPromise(
+ m_d->sdk.context().createPromise([jh, job](auto resolve) {
+ jh->submit(job, [resolve](GetRoomIdByAliasResponse r) {
+ resolve(parseGetRoomIdByAliasResponse(r));
+ });
+ }));
+}
+
void MatrixSdk::setUserDataDir(const std::string &userDataDir)
{
m_d->userDataDir = userDataDir;
diff --git a/src/tests/matrix-link-test.cpp b/src/tests/matrix-link-test.cpp
--- a/src/tests/matrix-link-test.cpp
+++ b/src/tests/matrix-link-test.cpp
@@ -21,6 +21,7 @@
void testInvalidLink();
void testUserLink();
void testRoomLink();
+ void testRoomAliasLink();
void testEventLink();
void testRoutingServers();
void testAction();
@@ -89,6 +90,23 @@
}
}
+void MatrixLinkTest::testRoomAliasLink()
+{
+ std::vector<std::tuple<QUrl, QString>> links = {
+ {QUrl(u"https://matrix.to/#/%23somewhere%3Aexample.org"_s), u"#somewhere:example.org"_s},
+ {QUrl(u"https://matrix.to/#/%23somewhere:example.org"_s), u"#somewhere:example.org"_s},
+ {QUrl(u"https://matrix.to/#/#somewhere%3Aexample.org"_s), u"#somewhere:example.org"_s},
+ {QUrl(u"https://matrix.to/#/#somewhere:example.org"_s), u"#somewhere:example.org"_s},
+ {QUrl(u"matrix:r/somewhere:example.org"_s), u"#somewhere:example.org"_s},
+ {QUrl{u"matrix:r/somewhere%3Aexample.org"_s}, u"#somewhere:example.org"_s},
+ };
+ for (auto [link, pointed] : links) {
+ MatrixLink ml(link);
+ QVERIFY(ml.isRoomAlias());
+ QCOMPARE(ml.identifiers(), QStringList{pointed});
+ }
+}
+
void MatrixLinkTest::testEventLink()
{
std::vector<std::tuple<QUrl, QString>> links = {
diff --git a/src/tests/matrix-room-list-test.cpp b/src/tests/matrix-room-list-test.cpp
--- a/src/tests/matrix-room-list-test.cpp
+++ b/src/tests/matrix-room-list-test.cpp
@@ -34,6 +34,7 @@
void testSortedWithTag();
void testFilter();
void testPriority();
+ void testExist();
};
static auto tagEvent = Event{R"({
@@ -230,6 +231,19 @@
QCOMPARE(roomList->roomIdAt(1), u"!favourite:tusooa.xyz"_s);
}
+void MatrixRoomListTest::testExist()
+{
+ auto model = makeTestModel();
+ RoomModel room;
+ room.roomId = "!test:tusooa.xyz";
+ model.client.roomList.rooms = model.client.roomList.rooms.set(room.roomId, room);
+
+ std::unique_ptr<MatrixSdk> sdk{makeTestSdk(model)};
+ auto roomList = toUniquePtr(sdk->roomList());
+ QVERIFY(roomList->contains(u"!test:tusooa.xyz"_s));
+ QVERIFY(!roomList->contains(u"!notexist:tusooa.xyz"_s));
+}
+
QTEST_MAIN(MatrixRoomListTest)
#include "matrix-room-list-test.moc"
diff --git a/src/tests/matrix-sdk-test.cpp b/src/tests/matrix-sdk-test.cpp
--- a/src/tests/matrix-sdk-test.cpp
+++ b/src/tests/matrix-sdk-test.cpp
@@ -31,6 +31,7 @@
void testSetDeviceTrustLevel();
void testValidateHomeserverUrl();
void testSpecVersion();
+ void testDirectRoomIds();
};
void MatrixSdkTest::testDevicesOfUser()
@@ -108,6 +109,26 @@
QVERIFY(!sdk->checkSpecVersionRange(u"v1.1"_s, u"v1.2"_s));
}
+void MatrixSdkTest::testDirectRoomIds()
+{
+ auto model = makeTestModel();
+ auto j = R"({
+ "type": "m.direct",
+ "content": {
+ "@mew:example.org": [
+ "!somewhere1:example.org",
+ "!somewhere2:example.org"
+ ]
+ }
+ })"_json;
+ model.client.accountData = model.client.accountData.set("m.direct", j);
+ std::unique_ptr<MatrixSdk> sdk{new MatrixSdk(model, /* testing = */ true)};
+ const auto rooms = QStringList{u"!somewhere1:example.org"_s, u"!somewhere2:example.org"_s};
+ const auto directRoomIds = sdk->directRoomIds(u"@mew:example.org"_s);
+ QCOMPARE(QSet(directRoomIds.begin(), directRoomIds.end()),
+ QSet(rooms.begin(), rooms.end()));
+}
+
QTEST_MAIN(MatrixSdkTest)
#include "matrix-sdk-test.moc"
diff --git a/src/tests/quick-tests/test-helpers/MatrixSdkMock.qml b/src/tests/quick-tests/test-helpers/MatrixSdkMock.qml
--- a/src/tests/quick-tests/test-helpers/MatrixSdkMock.qml
+++ b/src/tests/quick-tests/test-helpers/MatrixSdkMock.qml
@@ -26,6 +26,13 @@
property var joinRoom: mockHelper.promise()
property var sendAccountData: mockHelper.promise()
property var login: mockHelper.noop()
+ property var addDirectRoom: mockHelper.promise([
+ 'userId',
+ 'roomId'
+ ])
+ property var getRoomIdByAlias: mockHelper.promise([
+ 'roomAlias'
+ ])
property var sessions: []
@@ -52,4 +59,16 @@
function checkSpecVersion (ver) {
return !!specVersions.includes(ver);
}
+
+ function directRoomIds(userId) {
+ const directRoomMap = {
+ "@someonejoined:example.org": ["!joinedroomid:example.org"],
+ "@someoneinvited:example.org": ["!invitedroomid:example.org"],
+ "@someoneleft:example.org": ["!leftroomid:example.org"]
+ };
+ if (!directRoomMap[userId]) {
+ return [];
+ }
+ return directRoomMap[userId];
+ }
}
diff --git a/src/tests/quick-tests/tst_CreateRoomPage.qml b/src/tests/quick-tests/tst_CreateRoomPage.qml
--- a/src/tests/quick-tests/tst_CreateRoomPage.qml
+++ b/src/tests/quick-tests/tst_CreateRoomPage.qml
@@ -114,6 +114,7 @@
preset: MK.MatrixSdk.TrustedPrivateChat,
encrypted: true,
}));
+ tryVerify(() => item.matrixSdk.addDirectRoom.calledTimes() === 0, 1000);
}
function test_createRoomDirectInviteOne() {
@@ -146,6 +147,12 @@
preset: MK.MatrixSdk.TrustedPrivateChat,
encrypted: true,
}));
+ item.matrixSdk.createRoom.lastRetVal().resolve(true, { 'roomId': '!somewhere:example.org' });
+ tryVerify(() => item.matrixSdk.addDirectRoom.calledTimes() === 1, 1000);
+ verify(JsHelpers.deepEqual(item.matrixSdk.addDirectRoom.lastArgs(), {
+ userId: '@foo:example.org',
+ roomId: '!somewhere:example.org'
+ }));
}
function test_createRoomDirectInviteMultiple() {
diff --git a/src/tests/quick-tests/tst_MatrixLink.qml b/src/tests/quick-tests/tst_MatrixLink.qml
new file mode 100644
--- /dev/null
+++ b/src/tests/quick-tests/tst_MatrixLink.qml
@@ -0,0 +1,218 @@
+/*
+ * This file is part of kazv.
+ * SPDX-FileCopyrightText: 2025 nannanko <nannanko@kazv.moe>
+ * SPDX-License-Identifier: AGPL-3.0-or-later
+ */
+
+import QtTest
+import QtQml.Models
+
+import 'test-helpers' as QmlHelpers
+import 'test-helpers.js' as JsHelpers
+import '../../contents/ui/event-types' as Events
+
+import moe.kazv.mxc.kazv as MK
+
+QmlHelpers.TestItem {
+ id: item
+
+ property var mentionUserRequested: mockHelper.noop()
+ property var matrixSdk: QmlHelpers.MatrixSdkMock {}
+ property var switchToRoomRequested: mockHelper.noop()
+ property var pushCreateRoomPage: mockHelper.noop()
+ property var pageStack: ({
+ currentItem: {
+ presetPage: mockHelper.noop(),
+ delayGoToEvent: mockHelper.noop()
+ }
+ })
+ property var sdkVars: ({
+ roomList: {
+ contains: (roomId) => {
+ const rooms = [
+ "!directroom:example.org",
+ "!joinedroomid:example.org",
+ "!invitedroomid:example.org",
+ "!leftroomid:example.org"];
+ return rooms.includes(roomId);
+ },
+ room: (roomId) => {
+ const rooms = {
+ "!joinedroomid:example.org": JsHelpers.factory.room({
+ membership: MK.MatrixRoom.Join
+ }),
+ "!invitedroomid:example.org": JsHelpers.factory.room({
+ membership: MK.MatrixRoom.Invite
+ }),
+ "!leftroomid:example.org": JsHelpers.factory.room({
+ membership: MK.MatrixRoom.Leave
+ })
+ };
+ return rooms[roomId];
+ }
+ }
+ })
+ property var pushJoinRoomPage: mockHelper.noop()
+
+ Events.Text {
+ id: textEvent
+ }
+
+ TestCase {
+ id: matrixLinkTest
+ name: 'matrixLinkTest'
+ when: windowShown
+
+ function init() {
+ mockHelper.clearAll();
+ }
+
+ function test_matrixSchemeUser() {
+ textEvent.openLink("matrix:u/someone:example.org");
+ compare(mentionUserRequested.calledTimes(), 1);
+ compare(mentionUserRequested.lastArgs()[0], "@someone:example.org");
+ }
+
+ function test_matrixToUser() {
+ textEvent.openLink("https://matrix.to/#/@someone:example.org");
+ compare(mentionUserRequested.calledTimes(), 1);
+ compare(mentionUserRequested.lastArgs()[0], "@someone:example.org");
+ }
+
+ function test_matrixSchemeUserJoined() {
+ textEvent.openLink("matrix:u/someonejoined:example.org?action=chat");
+ compare(switchToRoomRequested.calledTimes(), 1);
+ compare(switchToRoomRequested.lastArgs()[0], "!joinedroomid:example.org");
+ }
+
+ function test_matrixSchemeUserInvited() {
+ textEvent.openLink("matrix:u/someoneinvited:example.org?action=chat");
+ compare(switchToRoomRequested.calledTimes(), 1);
+ compare(switchToRoomRequested.lastArgs()[0], "!invitedroomid:example.org");
+ }
+
+ function test_matrixSchemeUserLeft() {
+ textEvent.openLink("matrix:u/someoneleft:example.org?action=chat");
+ compare(pushCreateRoomPage.calledTimes(), 1);
+ compare(pageStack.currentItem.presetPage.calledTimes(), 1);
+ compare(pageStack.currentItem.presetPage.lastArgs()[0], "@someoneleft:example.org");
+ }
+
+ function test_matrixSchemeUserCreateDirectRoom() {
+ textEvent.openLink("matrix:u/someonewithoutchat:example.org?action=chat");
+ compare(pushCreateRoomPage.calledTimes(), 1);
+ compare(pageStack.currentItem.presetPage.calledTimes(), 1);
+ compare(pageStack.currentItem.presetPage.lastArgs()[0], "@someonewithoutchat:example.org");
+ }
+
+ function test_matrixSchemeRoomId() {
+ textEvent.openLink("matrix:roomid/joinedroomid:example.org");
+ compare(switchToRoomRequested.calledTimes(), 1);
+ compare(switchToRoomRequested.lastArgs()[0], "!joinedroomid:example.org");
+ }
+
+ function test_matrixToRoomId() {
+ textEvent.openLink("https://matrix.to/#/!joinedroomid:example.org");
+ compare(switchToRoomRequested.calledTimes(), 1);
+ compare(switchToRoomRequested.lastArgs()[0], "!joinedroomid:example.org");
+ }
+
+ function test_matrixSchemeRoomAlias() {
+ textEvent.openLink("matrix:r/joinedroomalias:example.org");
+ compare(matrixSdk.getRoomIdByAlias.calledTimes(), 1);
+ compare(matrixSdk.getRoomIdByAlias.lastArgs()["roomAlias"], "#joinedroomalias:example.org")
+ matrixSdk.getRoomIdByAlias.lastRetVal().resolve(true, { "roomId": "!joinedroomid:example.org" });
+ compare(switchToRoomRequested.calledTimes(), 1);
+ compare(switchToRoomRequested.lastArgs()[0], "!joinedroomid:example.org");
+ }
+
+ function test_matrixToRoomAlias() {
+ textEvent.openLink("https://matrix.to/#/#joinedroomalias:example.org");
+ compare(matrixSdk.getRoomIdByAlias.calledTimes(), 1);
+ compare(matrixSdk.getRoomIdByAlias.lastArgs()["roomAlias"], "#joinedroomalias:example.org")
+ matrixSdk.getRoomIdByAlias.lastRetVal().resolve(true, { "roomId": "!joinedroomid:example.org" });
+ compare(switchToRoomRequested.calledTimes(), 1);
+ compare(switchToRoomRequested.lastArgs()[0], "!joinedroomid:example.org");
+ }
+
+ function test_matrixSchemeRoomIdUnjoined() {
+ textEvent.openLink("matrix:roomid/unjoinedroomid:example.org?action=join&via=server1.ca&via=server2.ca");
+ compare(pushJoinRoomPage.calledTimes(), 1);
+ compare(pageStack.currentItem.presetPage.calledTimes(), 1);
+ compare(pageStack.currentItem.presetPage.lastArgs()[0], "!unjoinedroomid:example.org");
+ compare(pageStack.currentItem.presetPage.lastArgs()[1], ["server1.ca", "server2.ca"]);
+ }
+
+ function test_matrixToRoomIdUnjoined() {
+ textEvent.openLink("https://matrix.to/#/!unjoinedroomid:example.org?via=server1.ca&via=server2.ca");
+ compare(pageStack.currentItem.presetPage.calledTimes(), 1);
+ compare(pageStack.currentItem.presetPage.lastArgs()[0], "!unjoinedroomid:example.org");
+ compare(pageStack.currentItem.presetPage.lastArgs()[1], ["server1.ca", "server2.ca"]);
+ }
+
+ function test_matrixSchemeRoomAliasUnjoined() {
+ textEvent.openLink("matrix:r/unjoinedroomalias:example.org?action=join&via=server1.ca&via=server2.ca");
+ compare(matrixSdk.getRoomIdByAlias.calledTimes(), 1);
+ compare(matrixSdk.getRoomIdByAlias.lastArgs()["roomAlias"], "#unjoinedroomalias:example.org")
+ matrixSdk.getRoomIdByAlias.lastRetVal().resolve(true, { "roomId": "!unjoinedroomid:example.org" });
+ compare(pushJoinRoomPage.calledTimes(), 1);
+ compare(pageStack.currentItem.presetPage.calledTimes(), 1);
+ compare(pageStack.currentItem.presetPage.lastArgs()[0], "#unjoinedroomalias:example.org");
+ compare(pageStack.currentItem.presetPage.lastArgs()[1], ["server1.ca", "server2.ca"]);
+ }
+
+ function test_matrixToRoomAliasUnjoined() {
+ textEvent.openLink("https://matrix.to/#/#unjoinedroomalias:example.org?action=join&via=server1.ca&via=server2.ca");
+ compare(matrixSdk.getRoomIdByAlias.calledTimes(), 1);
+ compare(matrixSdk.getRoomIdByAlias.lastArgs()["roomAlias"], "#unjoinedroomalias:example.org")
+ matrixSdk.getRoomIdByAlias.lastRetVal().resolve(true, { "roomId": "!unjoinedroomid:example.org" });
+ compare(pushJoinRoomPage.calledTimes(), 1);
+ compare(pageStack.currentItem.presetPage.calledTimes(), 1);
+ compare(pageStack.currentItem.presetPage.lastArgs()[0], "#unjoinedroomalias:example.org");
+ compare(pageStack.currentItem.presetPage.lastArgs()[1], ["server1.ca", "server2.ca"]);
+ }
+
+ function test_matrixSchemeEvent() {
+ textEvent.openLink("matrix:roomid/joinedroomid:example.org/e/eventid");
+ compare(switchToRoomRequested.calledTimes(), 1);
+ compare(switchToRoomRequested.lastArgs()[0], "!joinedroomid:example.org");
+ compare(pageStack.currentItem.delayGoToEvent.calledTimes(), 1);
+ compare(pageStack.currentItem.delayGoToEvent.lastArgs()[0], "$eventid");
+ }
+
+ function test_matrixToEvent() {
+ textEvent.openLink("https://matrix.to/#/!joinedroomid:example.org/$eventid");
+ compare(switchToRoomRequested.calledTimes(), 1);
+ compare(switchToRoomRequested.lastArgs()[0], "!joinedroomid:example.org");
+ compare(pageStack.currentItem.delayGoToEvent.calledTimes(), 1);
+ compare(pageStack.currentItem.delayGoToEvent.lastArgs()[0], "$eventid");
+ }
+
+ function test_matrixSchemeEventUnjoined() {
+ textEvent.openLink("matrix:roomid/unjoinedroomid:example.org/e/eventid?via=server1.ca&via=server2.ca");
+ compare(pushJoinRoomPage.calledTimes(), 1);
+ compare(pageStack.currentItem.presetPage.calledTimes(), 1);
+ compare(pageStack.currentItem.presetPage.lastArgs()[0], "!unjoinedroomid:example.org");
+ compare(pageStack.currentItem.presetPage.lastArgs()[1], ["server1.ca", "server2.ca"]);
+ }
+
+ function test_matrixToEventUnjoined() {
+ textEvent.openLink("https://matrix.to/#/!unjoinedroomid:example.org/$eventid?via=server1.ca&via=server2.ca");
+ compare(pushJoinRoomPage.calledTimes(), 1);
+ compare(pageStack.currentItem.presetPage.calledTimes(), 1);
+ compare(pageStack.currentItem.presetPage.lastArgs()[0], "!unjoinedroomid:example.org");
+ compare(pageStack.currentItem.presetPage.lastArgs()[1], ["server1.ca", "server2.ca"]);
+ }
+
+ function test_matrixSchemeRoomAliasFailed() {
+ textEvent.openLink("matrix:r/room:example.org");
+ compare(matrixSdk.getRoomIdByAlias.calledTimes(), 1);
+ compare(matrixSdk.getRoomIdByAlias.lastArgs()["roomAlias"], "#room:example.org")
+ matrixSdk.getRoomIdByAlias.lastRetVal().resolve(false, { errorCode: 'M_NOT_FOUND', error: 'Room alias #room:example.org not found.' });
+ compare(switchToRoomRequested.calledTimes(), 0);
+ compare(showPassiveNotification.calledTimes(), 1);
+ compare(showPassiveNotification.lastArgs()[0], l10n.get('get-room-id-by-alias-failed-prompt',
+ { errorCode: 'M_NOT_FOUND', errorMsg: 'Room alias #room:example.org not found.' }));
+ }
+ }
+}

File Metadata

Mime Type
text/plain
Expires
Fri, Sep 26, 1:08 PM (4 h, 43 m)
Storage Engine
blob
Storage Format
Raw Data
Storage Handle
476136
Default Alt Text
D229.1758917335.diff (27 KB)

Event Timeline