diff --git a/tools/chatgui/src/mainwindow.cpp b/tools/chatgui/src/mainwindow.cpp index e4c4e9ab..881113ba 100644 --- a/tools/chatgui/src/mainwindow.cpp +++ b/tools/chatgui/src/mainwindow.cpp @@ -38,6 +38,8 @@ extern "C" { #include #include #include +#include +#include #include #include #include @@ -550,7 +552,7 @@ void MainWindow::setupConnects() { connect(m_accountList, &AccountList::pmRequested, this, &MainWindow::onPmRequested); connect(m_accountList, &AccountList::inviteRequested, this, &MainWindow::onInviteToPmRequested); connect(m_messageList, &MessageList::inviteRequested, this, &MainWindow::onInviteToPmRequested); - connect(m_messageList, &MessageList::inviteLinkActivated, this, &MainWindow::onInviteLinkActivated); + connect(m_messageList, &MessageList::linkActivated, this, &MainWindow::onMessageLinkActivated); connect(m_messageList, &MessageList::readPositionChanged, this, [this](const QString& channelId, qint64 lastReadMsgId) { Q_UNUSED(lastReadMsgId); @@ -695,7 +697,20 @@ void MainWindow::onInviteToPmRequested(const QString& source, quint64 peer, cons } } -void MainWindow::onInviteLinkActivated(const QString& link) { +void MainWindow::onMessageLinkActivated(const QString& link) { + if (!link.startsWith(QStringLiteral("utun://"))) { + const QUrl url(link, QUrl::StrictMode); + if (!url.isValid() || url.host().isEmpty() || (url.scheme() != "http" && url.scheme() != "https")) { + GUI_ERROR("message link: invalid web address bytes=%d", (int)link.size()); + QMessageBox::warning(this, tr("Ссылка"), tr("Некорректная ссылка.")); return; + } + if (!QDesktopServices::openUrl(url)) { + GUI_ERROR("message link: external open failed scheme=%s host=%s", qPrintable(url.scheme()), qPrintable(url.host())); + QMessageBox::warning(this, tr("Ссылка"), tr("Не удалось открыть ссылку. Проверьте наличие браузера.")); return; + } + GUI_INFO("message link: external open requested scheme=%s host=%s", qPrintable(url.scheme()), qPrintable(url.host())); + return; + } const auto invite = decodeInviteLink(link); if (!invite.error.isEmpty()) { GUI_ERROR("invite link: invalid error=%s", qPrintable(invite.error)); diff --git a/tools/chatgui/src/mainwindow.h b/tools/chatgui/src/mainwindow.h index 7b706130..37fd5d14 100644 --- a/tools/chatgui/src/mainwindow.h +++ b/tools/chatgui/src/mainwindow.h @@ -81,7 +81,7 @@ public: /* DM (p2p чат) */ void onPmRequested(const QString& chId, quint64 nodeId, const QString& name); void onInviteToPmRequested(const QString& source, quint64 peer, const QString& name); - void onInviteLinkActivated(const QString& link); + void onMessageLinkActivated(const QString& link); void onDmConvUpdated(const QString& convId); void onDmMsgReceived(const QString& convId, quint64 author);