mirror of
https://github.com/Nheko-Reborn/nheko.git
synced 2024-10-30 17:40:47 +03:00
Move openLink to Nheko globals
This commit is contained in:
parent
a7f8b23b52
commit
22afa122c4
6 changed files with 59 additions and 55 deletions
|
@ -14,7 +14,7 @@ TextEdit {
|
|||
selectByMouse: !Settings.mobileMode
|
||||
enabled: selectByMouse
|
||||
color: Nheko.colors.text
|
||||
onLinkActivated: TimelineManager.openLink(link)
|
||||
onLinkActivated: Nheko.openLink(link)
|
||||
ToolTip.visible: hoveredLink
|
||||
ToolTip.text: hoveredLink
|
||||
|
||||
|
|
|
@ -128,7 +128,7 @@ ApplicationWindow {
|
|||
selectByMouse: true
|
||||
color: Nheko.colors.text
|
||||
horizontalAlignment: TextEdit.AlignHCenter
|
||||
onLinkActivated: TimelineManager.openLink(link)
|
||||
onLinkActivated: Nheko.openLink(link)
|
||||
|
||||
CursorShape {
|
||||
anchors.fill: parent
|
||||
|
|
|
@ -4,7 +4,6 @@
|
|||
|
||||
#include "TimelineViewManager.h"
|
||||
|
||||
#include <QDesktopServices>
|
||||
#include <QDropEvent>
|
||||
#include <QMetaType>
|
||||
#include <QPalette>
|
||||
|
@ -476,56 +475,6 @@ TimelineViewManager::openImageOverlayInternal(QString eventId, QImage img)
|
|||
});
|
||||
}
|
||||
|
||||
void
|
||||
TimelineViewManager::openLink(QString link) const
|
||||
{
|
||||
QUrl url(link);
|
||||
if (url.scheme() == "https" && url.host() == "matrix.to") {
|
||||
// handle matrix.to links internally
|
||||
QString p = url.fragment(QUrl::FullyEncoded);
|
||||
if (p.startsWith("/"))
|
||||
p.remove(0, 1);
|
||||
|
||||
auto temp = p.split("?");
|
||||
QString query;
|
||||
if (temp.size() >= 2)
|
||||
query = QUrl::fromPercentEncoding(temp.takeAt(1).toUtf8());
|
||||
|
||||
temp = temp.first().split("/");
|
||||
auto identifier = QUrl::fromPercentEncoding(temp.takeFirst().toUtf8());
|
||||
QString eventId = QUrl::fromPercentEncoding(temp.join('/').toUtf8());
|
||||
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
|
||||
TimelineViewManager::openInviteUsersDialog()
|
||||
{
|
||||
|
|
|
@ -68,8 +68,6 @@ public:
|
|||
Q_INVOKABLE QString userPresence(QString id) const;
|
||||
Q_INVOKABLE QString userStatus(QString id) const;
|
||||
|
||||
Q_INVOKABLE void openLink(QString link) const;
|
||||
|
||||
Q_INVOKABLE void focusMessageInput();
|
||||
Q_INVOKABLE void openInviteUsersDialog();
|
||||
Q_INVOKABLE void openMemberListDialog() const;
|
||||
|
|
|
@ -4,6 +4,10 @@
|
|||
|
||||
#include "NhekoGlobalObject.h"
|
||||
|
||||
#include <QDesktopServices>
|
||||
#include <QUrl>
|
||||
|
||||
#include "ChatPage.h"
|
||||
#include "UserSettingsPage.h"
|
||||
|
||||
Nheko::Nheko()
|
||||
|
@ -25,3 +29,53 @@ Nheko::inactiveColors() const
|
|||
p.setCurrentColorGroup(QPalette::ColorGroup::Inactive);
|
||||
return p;
|
||||
}
|
||||
|
||||
void
|
||||
Nheko::openLink(QString link) const
|
||||
{
|
||||
QUrl url(link);
|
||||
if (url.scheme() == "https" && url.host() == "matrix.to") {
|
||||
// handle matrix.to links internally
|
||||
QString p = url.fragment(QUrl::FullyEncoded);
|
||||
if (p.startsWith("/"))
|
||||
p.remove(0, 1);
|
||||
|
||||
auto temp = p.split("?");
|
||||
QString query;
|
||||
if (temp.size() >= 2)
|
||||
query = QUrl::fromPercentEncoding(temp.takeAt(1).toUtf8());
|
||||
|
||||
temp = temp.first().split("/");
|
||||
auto identifier = QUrl::fromPercentEncoding(temp.takeFirst().toUtf8());
|
||||
QString eventId = QUrl::fromPercentEncoding(temp.join('/').toUtf8());
|
||||
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);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -20,6 +20,9 @@ public:
|
|||
QPalette colors() const;
|
||||
QPalette inactiveColors() const;
|
||||
|
||||
Q_INVOKABLE void openLink(QString link) const;
|
||||
|
||||
signals:
|
||||
void colorsChanged();
|
||||
};
|
||||
|
||||
|
|
Loading…
Reference in a new issue