summary refs log tree commit diff
path: root/src/timeline/TimelineItem.cpp
diff options
context:
space:
mode:
authorKonstantinos Sideris <sideris.konstantin@gmail.com>2018-09-12 20:54:44 +0300
committerKonstantinos Sideris <sideris.konstantin@gmail.com>2018-09-12 20:54:44 +0300
commit9c06ba5d25e8007f7d21971edce4c9791be009ed (patch)
treed45bc354d3a788fd8907b1825222e719e2a74262 /src/timeline/TimelineItem.cpp
parentAdd context menu option to show the raw message (diff)
downloadnheko-9c06ba5d25e8007f7d21971edce4c9791be009ed.tar.xz
Open user profile on matrix.to links
Diffstat (limited to 'src/timeline/TimelineItem.cpp')
-rw-r--r--src/timeline/TimelineItem.cpp41
1 files changed, 41 insertions, 0 deletions
diff --git a/src/timeline/TimelineItem.cpp b/src/timeline/TimelineItem.cpp

index 5bec4458..1654e451 100644 --- a/src/timeline/TimelineItem.cpp +++ b/src/timeline/TimelineItem.cpp
@@ -16,6 +16,7 @@ */ #include <QContextMenuEvent> +#include <QDesktopServices> #include <QFontDatabase> #include <QMenu> #include <QTimer> @@ -35,6 +36,7 @@ #include "timeline/widgets/VideoItem.h" #include "dialogs/RawMessage.h" +#include "mtx/identifiers.hpp" constexpr int MSG_RIGHT_MARGIN = 7; constexpr int MSG_PADDING = 20; @@ -61,8 +63,47 @@ TextLabel::TextLabel(const QString &text, QWidget *parent) &TextLabel::adjustHeight); document()->setDocumentMargin(0); + setFocusPolicy(Qt::NoFocus); setSizePolicy(QSizePolicy::Preferred, QSizePolicy::Fixed); setFixedHeight(0); + + connect(this, &TextLabel::linkActivated, this, [](const QUrl &url) { + auto parts = url.toString().split('/'); + auto defaultHandler = [](const QUrl &url) { QDesktopServices::openUrl(url); }; + + if (url.host() != "matrix.to" || parts.isEmpty()) + return defaultHandler(url); + + try { + using namespace mtx::identifiers; + parse<User>(parts.last().toStdString()); + } catch (const std::exception &) { + return defaultHandler(url); + } + + auto user_id = parts.last(); + auto room_id = ChatPage::instance()->currentRoom(); + + MainWindow::instance()->openUserProfile(user_id, room_id); + }); +} + +void +TextLabel::mousePressEvent(QMouseEvent *e) +{ + link_ = (e->button() & Qt::LeftButton) ? anchorAt(e->pos()) : QString(); + QTextBrowser::mousePressEvent(e); +} + +void +TextLabel::mouseReleaseEvent(QMouseEvent *e) +{ + if (e->button() & Qt::LeftButton && !link_.isEmpty() && anchorAt(e->pos()) == link_) { + emit linkActivated(link_); + return; + } + + QTextBrowser::mouseReleaseEvent(e); } StatusIndicator::StatusIndicator(QWidget *parent)