mirror of
https://github.com/Nheko-Reborn/nheko.git
synced 2024-11-25 20:48:52 +03:00
Rewrite matrix.to links to matrix uris and handle them the same way
This commit is contained in:
parent
5b6671f063
commit
76a9240076
2 changed files with 48 additions and 14 deletions
|
@ -14,19 +14,7 @@ TextEdit {
|
||||||
selectByMouse: !Settings.mobileMode
|
selectByMouse: !Settings.mobileMode
|
||||||
enabled: selectByMouse
|
enabled: selectByMouse
|
||||||
color: colors.text
|
color: colors.text
|
||||||
onLinkActivated: {
|
onLinkActivated: TimelineManager.openLink(link);
|
||||||
if (/^https:\/\/matrix.to\/#\/(@.*)$/.test(link)) {
|
|
||||||
chat.model.openUserProfile(/^https:\/\/matrix.to\/#\/(@.*)$/.exec(link)[1]);
|
|
||||||
} else if (/^https:\/\/matrix.to\/#\/(![^\/]*)$/.test(link)) {
|
|
||||||
TimelineManager.setHistoryView(/^https:\/\/matrix.to\/#\/(!.*)$/.exec(link)[1]);
|
|
||||||
} else if (/^https:\/\/matrix.to\/#\/(![^\/]*)\/(\$.*)$/.test(link)) {
|
|
||||||
var match = /^https:\/\/matrix.to\/#\/(![^\/]*)\/(\$.*)$/.exec(link);
|
|
||||||
TimelineManager.setHistoryView(match[1]);
|
|
||||||
chat.positionViewAtIndex(chat.model.idToIndex(match[2]), ListView.Contain);
|
|
||||||
} else {
|
|
||||||
TimelineManager.openLink(link);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
ToolTip.visible: hoveredLink
|
ToolTip.visible: hoveredLink
|
||||||
ToolTip.text: hoveredLink
|
ToolTip.text: hoveredLink
|
||||||
|
|
||||||
|
|
|
@ -451,7 +451,53 @@ TimelineViewManager::openImageOverlayInternal(QString eventId, QImage img)
|
||||||
void
|
void
|
||||||
TimelineViewManager::openLink(QString link) const
|
TimelineViewManager::openLink(QString link) const
|
||||||
{
|
{
|
||||||
QDesktopServices::openUrl(link);
|
QUrl url(link);
|
||||||
|
if (url.scheme() == "https" && url.host() == "matrix.to") {
|
||||||
|
// handle matrix.to links internally
|
||||||
|
QString p = url.fragment(QUrl::FullyDecoded);
|
||||||
|
if (p.startsWith("/"))
|
||||||
|
p.remove(0, 1);
|
||||||
|
|
||||||
|
auto temp = p.split("?");
|
||||||
|
QString query;
|
||||||
|
if (temp.size() >= 2)
|
||||||
|
query = temp.takeAt(1);
|
||||||
|
|
||||||
|
temp = temp.first().split("/");
|
||||||
|
auto identifier = temp.first();
|
||||||
|
QString eventId;
|
||||||
|
if (temp.size() >= 2)
|
||||||
|
eventId = temp.takeAt(1);
|
||||||
|
if (!identifier.isEmpty()) {
|
||||||
|
if (identifier.startsWith("@")) {
|
||||||
|
QByteArray uri =
|
||||||
|
"matrix:u/" + QUrl::toPercentEncoding(identifier.remove(0, 1));
|
||||||
|
if (!query.isEmpty())
|
||||||
|
uri.append("?" + query.toUtf8());
|
||||||
|
ChatPage::instance()->handleMatrixUri(QUrl::fromEncoded(uri));
|
||||||
|
} else if (identifier.startsWith("#")) {
|
||||||
|
QByteArray uri =
|
||||||
|
"matrix:r/" + QUrl::toPercentEncoding(identifier.remove(0, 1));
|
||||||
|
if (!eventId.isEmpty())
|
||||||
|
uri.append("/e/" +
|
||||||
|
QUrl::toPercentEncoding(eventId.remove(0, 1)));
|
||||||
|
if (!query.isEmpty())
|
||||||
|
uri.append("?" + query.toUtf8());
|
||||||
|
ChatPage::instance()->handleMatrixUri(QUrl::fromEncoded(uri));
|
||||||
|
} else if (identifier.startsWith("!")) {
|
||||||
|
QByteArray uri = "matrix:roomid/" +
|
||||||
|
QUrl::toPercentEncoding(identifier.remove(0, 1));
|
||||||
|
if (!eventId.isEmpty())
|
||||||
|
uri.append("/e/" +
|
||||||
|
QUrl::toPercentEncoding(eventId.remove(0, 1)));
|
||||||
|
if (!query.isEmpty())
|
||||||
|
uri.append("?" + query.toUtf8());
|
||||||
|
ChatPage::instance()->handleMatrixUri(QUrl::fromEncoded(uri));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
QDesktopServices::openUrl(url);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void
|
void
|
||||||
|
|
Loading…
Reference in a new issue