mirror of
https://github.com/Nheko-Reborn/nheko.git
synced 2024-11-22 03:00:46 +03:00
Add copy link to room context menu (#1101)
This commit is contained in:
parent
f189fbc98d
commit
09c646d3fa
5 changed files with 43 additions and 12 deletions
|
@ -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 {
|
||||
|
|
|
@ -5,6 +5,9 @@
|
|||
|
||||
#include "RoomlistModel.h"
|
||||
|
||||
#include <QClipboard>
|
||||
#include <QGuiApplication>
|
||||
|
||||
#include "Cache.h"
|
||||
#include "Cache_p.h"
|
||||
#include "ChatPage.h"
|
||||
|
@ -1081,6 +1084,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()
|
||||
{
|
||||
|
|
|
@ -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(); }
|
||||
|
|
|
@ -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);
|
||||
}
|
||||
|
||||
|
|
|
@ -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;
|
||||
|
|
Loading…
Reference in a new issue