summary refs log tree commit diff
path: root/src/timeline/TimelineModel.cpp
diff options
context:
space:
mode:
authorbrausepulver <34420739+brausepulver@users.noreply.github.com>2022-06-24 01:44:50 +0200
committerGitHub <noreply@github.com>2022-06-23 23:44:50 +0000
commit09c646d3fa33fcb7cd7236a0ae57521ed4f16c91 (patch)
treebe4958486f467383370dca913009b2658e9dd2dd /src/timeline/TimelineModel.cpp
parentMerge pull request #1106 from jevolk/master (diff)
downloadnheko-09c646d3fa33fcb7cd7236a0ae57521ed4f16c91.tar.xz
Add copy link to room context menu (#1101)
Diffstat (limited to 'src/timeline/TimelineModel.cpp')
-rw-r--r--src/timeline/TimelineModel.cpp33
1 files changed, 22 insertions, 11 deletions
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<mtx::events::state::CanonicalAlias>(room_id_.toStdString());
+      cache::client()->getStateEvent<mtx::events::state::CanonicalAlias>(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);
 }