Correctly open all kinds of matrix.to links in TextDelegate and MessageDelegateContextMenu
This commit is contained in:
@@ -45,15 +45,7 @@ a{
|
|||||||
textFormat: Text.RichText
|
textFormat: Text.RichText
|
||||||
|
|
||||||
onLinkActivated: {
|
onLinkActivated: {
|
||||||
if (link.startsWith("https://matrix.to/")) {
|
applicationWindow().handleLink(link, currentRoom)
|
||||||
var result = link.replace(/\?.*/, "").match("https://matrix.to/#/(!.*:.*)/(\\$.*:.*)")
|
|
||||||
if (!result || result.length < 3) return
|
|
||||||
if (result[1] != currentRoom.id) return
|
|
||||||
if (!result[2]) return
|
|
||||||
goToEvent(result[2])
|
|
||||||
} else {
|
|
||||||
Qt.openUrlExternally(link)
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
MouseArea {
|
MouseArea {
|
||||||
|
|||||||
@@ -57,15 +57,7 @@ Kirigami.OverlaySheet {
|
|||||||
wrapMode: Text.WordWrap
|
wrapMode: Text.WordWrap
|
||||||
|
|
||||||
onLinkActivated: {
|
onLinkActivated: {
|
||||||
if (link.startsWith("https://matrix.to/")) {
|
applicationWindow().handleLink(link, currentRoom)
|
||||||
var result = link.replace(/\?.*/, "").match("https://matrix.to/#/(!.*:.*)/(\\$.*:.*)")
|
|
||||||
if (!result || result.length < 3) return
|
|
||||||
if (result[1] != currentRoom.id) return
|
|
||||||
if (!result[2]) return
|
|
||||||
goToEvent(result[2])
|
|
||||||
} else {
|
|
||||||
Qt.openUrlExternally(link)
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
42
qml/main.qml
42
qml/main.qml
@@ -77,6 +77,15 @@ Kirigami.ApplicationWindow {
|
|||||||
signal leaveRoom(string room);
|
signal leaveRoom(string room);
|
||||||
signal openRoom(string room);
|
signal openRoom(string room);
|
||||||
|
|
||||||
|
function roomByAliasOrId(aliasOrId) {
|
||||||
|
return spectralRoomListModel.roomByAliasOrId(aliasOrId)
|
||||||
|
}
|
||||||
|
|
||||||
|
function openRoomAndEvent(room, event) {
|
||||||
|
enterRoom(room)
|
||||||
|
roomItem.goToEvent(event)
|
||||||
|
}
|
||||||
|
|
||||||
function loadInitialRoom() {
|
function loadInitialRoom() {
|
||||||
if (Config.openRoom) {
|
if (Config.openRoom) {
|
||||||
const room = Controller.activeConnection.room(Config.openRoom);
|
const room = Controller.activeConnection.room(Config.openRoom);
|
||||||
@@ -347,4 +356,37 @@ Kirigami.ApplicationWindow {
|
|||||||
id: roomWindow
|
id: roomWindow
|
||||||
RoomWindow {}
|
RoomWindow {}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function handleLink(link, currentRoom) {
|
||||||
|
if (link.startsWith("https://matrix.to/")) {
|
||||||
|
var content = link.replace("https://matrix.to/#/", "").replace(/\?.*/, "")
|
||||||
|
if(content.match("^[#!]")) {
|
||||||
|
if(content.includes("/")) {
|
||||||
|
var result = content.match("([!#].*:.*)/(\\$.*)")
|
||||||
|
if(!result) {
|
||||||
|
return
|
||||||
|
}
|
||||||
|
if(result[1] == currentRoom.id) {
|
||||||
|
roomManager.roomItem.goToEvent(result[2])
|
||||||
|
} else {
|
||||||
|
roomManager.openRoomAndEvent(roomManager.roomByAliasOrId(result[1]), result[2])
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
roomManager.enterRoom(roomManager.roomByAliasOrId(content))
|
||||||
|
}
|
||||||
|
} else if(content.match("^@")) {
|
||||||
|
let dialog = userDialog.createObject(root.overlay, {room: currentRoom, user: currentRoom.user(content)})
|
||||||
|
dialog.open()
|
||||||
|
console.log(dialog.user)
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
Qt.openUrlExternally(link)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
Component {
|
||||||
|
id: userDialog
|
||||||
|
UserDetailDialog {
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -429,3 +429,13 @@ bool RoomListModel::categoryVisible(int category) const
|
|||||||
{
|
{
|
||||||
return m_categoryVisibility.value(category, true);
|
return m_categoryVisibility.value(category, true);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
NeoChatRoom *RoomListModel::roomByAliasOrId(const QString &aliasOrId)
|
||||||
|
{
|
||||||
|
for(const auto &room : m_rooms) {
|
||||||
|
if(room->aliases().contains(aliasOrId) || room->id() == aliasOrId) {
|
||||||
|
return room;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return nullptr;
|
||||||
|
}
|
||||||
|
|||||||
@@ -80,6 +80,8 @@ public:
|
|||||||
return m_notificationCount;
|
return m_notificationCount;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Q_INVOKABLE NeoChatRoom *roomByAliasOrId(const QString &aliasOrId);
|
||||||
|
|
||||||
private Q_SLOTS:
|
private Q_SLOTS:
|
||||||
void doAddRoom(Quotient::Room *room);
|
void doAddRoom(Quotient::Room *room);
|
||||||
void updateRoom(Quotient::Room *room, Quotient::Room *prev);
|
void updateRoom(Quotient::Room *room, Quotient::Room *prev);
|
||||||
|
|||||||
Reference in New Issue
Block a user