summary refs log tree commit diff
diff options
context:
space:
mode:
-rw-r--r--resources/qml/RoomList.qml7
-rw-r--r--src/timeline/RoomlistModel.cpp11
-rw-r--r--src/timeline/RoomlistModel.h1
-rw-r--r--src/timeline/TimelineModel.cpp33
-rw-r--r--src/timeline/TimelineModel.h3
5 files changed, 43 insertions, 12 deletions
diff --git a/resources/qml/RoomList.qml b/resources/qml/RoomList.qml
index 69e12907..f3509f06 100644
--- a/resources/qml/RoomList.qml
+++ b/resources/qml/RoomList.qml
@@ -148,13 +148,18 @@ Page {
                 onTriggered: TimelineManager.openLeaveRoomDialog(roomContextMenu.roomid)
             }
 
+            Platform.MenuItem {
+                text: qsTr("Copy room link")
+                onTriggered: Rooms.copyLink(roomContextMenu.roomid)
+            }
+
             Platform.MenuSeparator {
                 text: qsTr("Tag room as:")
             }
 
             Instantiator {
                 model: Communities.tagsWithDefault
-                onObjectAdded: roomContextMenu.insertItem(index + 3, object)
+                onObjectAdded: roomContextMenu.insertItem(index + 4, object)
                 onObjectRemoved: roomContextMenu.removeItem(object)
 
                 delegate: Platform.MenuItem {
diff --git a/src/timeline/RoomlistModel.cpp b/src/timeline/RoomlistModel.cpp
index 0a49f596..bb2644f3 100644
--- a/src/timeline/RoomlistModel.cpp
+++ b/src/timeline/RoomlistModel.cpp
@@ -5,6 +5,9 @@
 
 #include "RoomlistModel.h"
 
+#include <QClipboard>
+#include <QGuiApplication>
+
 #include "Cache.h"
 #include "Cache_p.h"
 #include "ChatPage.h"
@@ -1082,6 +1085,14 @@ FilteredRoomlistModel::toggleTag(QString roomid, QString tag, bool on)
 }
 
 void
+FilteredRoomlistModel::copyLink(QString roomid)
+{
+    auto link = QStringLiteral("%1?%2").arg(TimelineModel::getBareRoomLink(roomid),
+                                            TimelineModel::getRoomVias(roomid));
+    QGuiApplication::clipboard()->setText(link);
+}
+
+void
 FilteredRoomlistModel::nextRoomWithActivity()
 {
     int roomWithMention       = -1;
diff --git a/src/timeline/RoomlistModel.h b/src/timeline/RoomlistModel.h
index eb42a478..cf2b45d8 100644
--- a/src/timeline/RoomlistModel.h
+++ b/src/timeline/RoomlistModel.h
@@ -178,6 +178,7 @@ public slots:
     void declineInvite(QString roomid) { roomlistmodel->declineInvite(roomid); }
     void leave(QString roomid, QString reason = "") { roomlistmodel->leave(roomid, reason); }
     void toggleTag(QString roomid, QString tag, bool on);
+    void copyLink(QString roomid);
 
     TimelineModel *currentRoom() const { return roomlistmodel->currentRoom(); }
     RoomPreview currentRoomPreview() const { return roomlistmodel->currentRoomPreview(); }
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);
 }
 
diff --git a/src/timeline/TimelineModel.h b/src/timeline/TimelineModel.h
index f569016c..3b954394 100644
--- a/src/timeline/TimelineModel.h
+++ b/src/timeline/TimelineModel.h
@@ -249,6 +249,9 @@ public:
     bool canFetchMore(const QModelIndex &) const override;
     void fetchMore(const QModelIndex &) override;
 
+    static QString getBareRoomLink(const QString &);
+    static QString getRoomVias(const QString &);
+
     Q_INVOKABLE QString displayName(const QString &id) const;
     Q_INVOKABLE QString avatarUrl(const QString &id) const;
     Q_INVOKABLE QString formatDateSeparator(QDate date) const;