Open user profile on matrix.to links

remotes/origin/HEAD
Konstantinos Sideris 6 years ago
parent e9ee29978d
commit 9c06ba5d25
  1. 2
      CHANGELOG.md
  2. 41
      src/timeline/TimelineItem.cpp
  3. 10
      src/timeline/TimelineItem.h

@ -3,6 +3,8 @@
## [Unreleased] ## [Unreleased]
### Features ### Features
- Support for sending & receiving markdown formatted messages. (#283) - Support for sending & receiving markdown formatted messages. (#283)
- Context menu option to show the raw text message of an event. (#437)
- Clicking on a user pill link will open the user profile.
### Improvements ### Improvements
- Update Polish translation (#430) - Update Polish translation (#430)

@ -16,6 +16,7 @@
*/ */
#include <QContextMenuEvent> #include <QContextMenuEvent>
#include <QDesktopServices>
#include <QFontDatabase> #include <QFontDatabase>
#include <QMenu> #include <QMenu>
#include <QTimer> #include <QTimer>
@ -35,6 +36,7 @@
#include "timeline/widgets/VideoItem.h" #include "timeline/widgets/VideoItem.h"
#include "dialogs/RawMessage.h" #include "dialogs/RawMessage.h"
#include "mtx/identifiers.hpp"
constexpr int MSG_RIGHT_MARGIN = 7; constexpr int MSG_RIGHT_MARGIN = 7;
constexpr int MSG_PADDING = 20; constexpr int MSG_PADDING = 20;
@ -61,8 +63,47 @@ TextLabel::TextLabel(const QString &text, QWidget *parent)
&TextLabel::adjustHeight); &TextLabel::adjustHeight);
document()->setDocumentMargin(0); document()->setDocumentMargin(0);
setFocusPolicy(Qt::NoFocus);
setSizePolicy(QSizePolicy::Preferred, QSizePolicy::Fixed); setSizePolicy(QSizePolicy::Preferred, QSizePolicy::Fixed);
setFixedHeight(0); 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) StatusIndicator::StatusIndicator(QWidget *parent)

@ -105,8 +105,18 @@ public:
void wheelEvent(QWheelEvent *event) override { event->ignore(); } void wheelEvent(QWheelEvent *event) override { event->ignore(); }
protected:
void mousePressEvent(QMouseEvent *e) override;
void mouseReleaseEvent(QMouseEvent *e) override;
private slots: private slots:
void adjustHeight(const QSizeF &size) { setFixedHeight(size.height()); } void adjustHeight(const QSizeF &size) { setFixedHeight(size.height()); }
signals:
void linkActivated(const QUrl &link);
private:
QString link_;
}; };
class UserProfileFilter : public QObject class UserProfileFilter : public QObject

Loading…
Cancel
Save