From 09c646d3fa33fcb7cd7236a0ae57521ed4f16c91 Mon Sep 17 00:00:00 2001 From: brausepulver <34420739+brausepulver@users.noreply.github.com> Date: Fri, 24 Jun 2022 01:44:50 +0200 Subject: Add copy link to room context menu (#1101) --- src/timeline/TimelineModel.cpp | 33 ++++++++++++++++++++++----------- 1 file changed, 22 insertions(+), 11 deletions(-) (limited to 'src/timeline/TimelineModel.cpp') diff --git a/src/timeline/TimelineModel.cpp b/src/timeline/TimelineModel.cpp index ff722b8b..79ba0c05 100644 --- a/src/timeline/TimelineModel.cpp +++ b/src/timeline/TimelineModel.cpp @@ -1752,13 +1752,11 @@ TimelineModel::requestKeyForEvent(const QString &id) } } -void -TimelineModel::copyLinkToEvent(const QString &eventId) const +QString +TimelineModel::getBareRoomLink(const QString &roomId) { - QStringList vias; - auto alias = - cache::client()->getStateEvent(room_id_.toStdString()); + cache::client()->getStateEvent(roomId.toStdString()); QString room; if (alias) { room = QString::fromStdString(alias->content.alias); @@ -1768,11 +1766,19 @@ TimelineModel::copyLinkToEvent(const QString &eventId) const } if (room.isEmpty()) - room = room_id_; + room = roomId; + + return QStringLiteral("https://matrix.to/#/%1").arg(QString(QUrl::toPercentEncoding(room))); +} + +QString +TimelineModel::getRoomVias(const QString &roomId) +{ + QStringList vias; vias.push_back(QStringLiteral("via=%1").arg(QString( QUrl::toPercentEncoding(QString::fromStdString(http::client()->user_id().hostname()))))); - auto members = cache::getMembers(room_id_.toStdString(), 0, 100); + auto members = cache::getMembers(roomId.toStdString(), 0, 100); for (const auto &m : members) { if (vias.size() >= 4) break; @@ -1785,11 +1791,16 @@ TimelineModel::copyLinkToEvent(const QString &eventId) const vias.push_back(server); } - auto link = QStringLiteral("https://matrix.to/#/%1/%2?%3") - .arg(QString(QUrl::toPercentEncoding(room)), - QString(QUrl::toPercentEncoding(eventId)), - vias.join('&')); + return vias.join("&"); +} +void +TimelineModel::copyLinkToEvent(const QString &eventId) const +{ + auto link = QStringLiteral("%1/%2?%3") + .arg(getBareRoomLink(room_id_), + QString(QUrl::toPercentEncoding(eventId)), + getRoomVias(room_id_)); QGuiApplication::clipboard()->setText(link); } -- cgit 1.4.1