mirror of
https://github.com/Nheko-Reborn/nheko.git
synced 2024-11-26 13:08:48 +03:00
Merge pull request #728 from Thulinma/goto
Improvements for linking to events
This commit is contained in:
commit
e118f3882d
6 changed files with 101 additions and 56 deletions
|
@ -21,6 +21,9 @@ ScrollView {
|
||||||
ListView {
|
ListView {
|
||||||
id: chat
|
id: chat
|
||||||
|
|
||||||
|
displayMarginBeginning: height/2
|
||||||
|
displayMarginEnd: height/2
|
||||||
|
|
||||||
property int delegateMaxWidth: ((Settings.timelineMaxWidth > 100 && Settings.timelineMaxWidth < parent.availableWidth) ? Settings.timelineMaxWidth : parent.availableWidth) - parent.padding * 2
|
property int delegateMaxWidth: ((Settings.timelineMaxWidth > 100 && Settings.timelineMaxWidth < parent.availableWidth) ? Settings.timelineMaxWidth : parent.availableWidth) - parent.padding * 2
|
||||||
|
|
||||||
model: room
|
model: room
|
||||||
|
@ -276,7 +279,7 @@ ScrollView {
|
||||||
}
|
}
|
||||||
|
|
||||||
function onScrollToIndex(index) {
|
function onScrollToIndex(index) {
|
||||||
chat.positionViewAtIndex(index, ListView.Visible);
|
chat.positionViewAtIndex(index, ListView.Center);
|
||||||
}
|
}
|
||||||
|
|
||||||
target: chat.model
|
target: chat.model
|
||||||
|
|
|
@ -1233,14 +1233,58 @@ mxidFromSegments(QStringRef sigil, QStringRef mxid)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void
|
bool
|
||||||
ChatPage::handleMatrixUri(const QByteArray &uri)
|
ChatPage::handleMatrixUri(const QByteArray &uri)
|
||||||
{
|
{
|
||||||
nhlog::ui()->info("Received uri! {}", uri.toStdString());
|
nhlog::ui()->info("Received uri! {}", uri.toStdString());
|
||||||
QUrl uri_{QString::fromUtf8(uri)};
|
QUrl uri_{QString::fromUtf8(uri)};
|
||||||
|
|
||||||
|
// Convert matrix.to URIs to proper format
|
||||||
|
if (uri_.scheme() == "https" && uri_.host() == "matrix.to") {
|
||||||
|
QString p = uri_.fragment(QUrl::FullyEncoded);
|
||||||
|
if (p.startsWith("/"))
|
||||||
|
p.remove(0, 1);
|
||||||
|
|
||||||
|
auto temp = p.split("?");
|
||||||
|
QString query;
|
||||||
|
if (temp.size() >= 2)
|
||||||
|
query = QUrl::fromPercentEncoding(temp.takeAt(1).toUtf8());
|
||||||
|
|
||||||
|
temp = temp.first().split("/");
|
||||||
|
auto identifier = QUrl::fromPercentEncoding(temp.takeFirst().toUtf8());
|
||||||
|
QString eventId = QUrl::fromPercentEncoding(temp.join('/').toUtf8());
|
||||||
|
if (!identifier.isEmpty()) {
|
||||||
|
if (identifier.startsWith("@")) {
|
||||||
|
QByteArray newUri =
|
||||||
|
"matrix:u/" + QUrl::toPercentEncoding(identifier.remove(0, 1));
|
||||||
|
if (!query.isEmpty())
|
||||||
|
newUri.append("?" + query.toUtf8());
|
||||||
|
return handleMatrixUri(QUrl::fromEncoded(newUri));
|
||||||
|
} else if (identifier.startsWith("#")) {
|
||||||
|
QByteArray newUri =
|
||||||
|
"matrix:r/" + QUrl::toPercentEncoding(identifier.remove(0, 1));
|
||||||
|
if (!eventId.isEmpty())
|
||||||
|
newUri.append(
|
||||||
|
"/e/" + QUrl::toPercentEncoding(eventId.remove(0, 1)));
|
||||||
|
if (!query.isEmpty())
|
||||||
|
newUri.append("?" + query.toUtf8());
|
||||||
|
return handleMatrixUri(QUrl::fromEncoded(newUri));
|
||||||
|
} else if (identifier.startsWith("!")) {
|
||||||
|
QByteArray newUri = "matrix:roomid/" + QUrl::toPercentEncoding(
|
||||||
|
identifier.remove(0, 1));
|
||||||
|
if (!eventId.isEmpty())
|
||||||
|
newUri.append(
|
||||||
|
"/e/" + QUrl::toPercentEncoding(eventId.remove(0, 1)));
|
||||||
|
if (!query.isEmpty())
|
||||||
|
newUri.append("?" + query.toUtf8());
|
||||||
|
return handleMatrixUri(QUrl::fromEncoded(newUri));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// non-matrix URIs are not handled by us, return false
|
||||||
if (uri_.scheme() != "matrix")
|
if (uri_.scheme() != "matrix")
|
||||||
return;
|
return false;
|
||||||
|
|
||||||
auto tempPath = uri_.path(QUrl::ComponentFormattingOption::FullyEncoded);
|
auto tempPath = uri_.path(QUrl::ComponentFormattingOption::FullyEncoded);
|
||||||
if (tempPath.startsWith('/'))
|
if (tempPath.startsWith('/'))
|
||||||
|
@ -1248,17 +1292,17 @@ ChatPage::handleMatrixUri(const QByteArray &uri)
|
||||||
auto segments = tempPath.splitRef('/');
|
auto segments = tempPath.splitRef('/');
|
||||||
|
|
||||||
if (segments.size() != 2 && segments.size() != 4)
|
if (segments.size() != 2 && segments.size() != 4)
|
||||||
return;
|
return false;
|
||||||
|
|
||||||
auto sigil1 = segments[0];
|
auto sigil1 = segments[0];
|
||||||
auto mxid1 = mxidFromSegments(sigil1, segments[1]);
|
auto mxid1 = mxidFromSegments(sigil1, segments[1]);
|
||||||
if (mxid1.isEmpty())
|
if (mxid1.isEmpty())
|
||||||
return;
|
return false;
|
||||||
|
|
||||||
QString mxid2;
|
QString mxid2;
|
||||||
if (segments.size() == 4 && segments[2] == "e") {
|
if (segments.size() == 4 && segments[2] == "e") {
|
||||||
if (segments[3].isEmpty())
|
if (segments[3].isEmpty())
|
||||||
return;
|
return false;
|
||||||
else
|
else
|
||||||
mxid2 = "$" + QUrl::fromPercentEncoding(segments[3].toUtf8());
|
mxid2 = "$" + QUrl::fromPercentEncoding(segments[3].toUtf8());
|
||||||
}
|
}
|
||||||
|
@ -1283,12 +1327,13 @@ ChatPage::handleMatrixUri(const QByteArray &uri)
|
||||||
if (t &&
|
if (t &&
|
||||||
cache::isRoomMember(mxid1.toStdString(), t->roomId().toStdString())) {
|
cache::isRoomMember(mxid1.toStdString(), t->roomId().toStdString())) {
|
||||||
t->openUserProfile(mxid1);
|
t->openUserProfile(mxid1);
|
||||||
return;
|
return true;
|
||||||
}
|
}
|
||||||
emit view_manager_->openGlobalUserProfile(mxid1);
|
emit view_manager_->openGlobalUserProfile(mxid1);
|
||||||
} else if (action == "chat") {
|
} else if (action == "chat") {
|
||||||
this->startChat(mxid1);
|
this->startChat(mxid1);
|
||||||
}
|
}
|
||||||
|
return true;
|
||||||
} else if (sigil1 == "roomid") {
|
} else if (sigil1 == "roomid") {
|
||||||
auto joined_rooms = cache::joinedRooms();
|
auto joined_rooms = cache::joinedRooms();
|
||||||
auto targetRoomId = mxid1.toStdString();
|
auto targetRoomId = mxid1.toStdString();
|
||||||
|
@ -1298,13 +1343,15 @@ ChatPage::handleMatrixUri(const QByteArray &uri)
|
||||||
view_manager_->rooms()->setCurrentRoom(mxid1);
|
view_manager_->rooms()->setCurrentRoom(mxid1);
|
||||||
if (!mxid2.isEmpty())
|
if (!mxid2.isEmpty())
|
||||||
view_manager_->showEvent(mxid1, mxid2);
|
view_manager_->showEvent(mxid1, mxid2);
|
||||||
return;
|
return true;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (action == "join" || action.isEmpty()) {
|
if (action == "join" || action.isEmpty()) {
|
||||||
joinRoomVia(targetRoomId, vias);
|
joinRoomVia(targetRoomId, vias);
|
||||||
|
return true;
|
||||||
}
|
}
|
||||||
|
return false;
|
||||||
} else if (sigil1 == "r") {
|
} else if (sigil1 == "r") {
|
||||||
auto joined_rooms = cache::joinedRooms();
|
auto joined_rooms = cache::joinedRooms();
|
||||||
auto targetRoomAlias = mxid1.toStdString();
|
auto targetRoomAlias = mxid1.toStdString();
|
||||||
|
@ -1318,21 +1365,25 @@ ChatPage::handleMatrixUri(const QByteArray &uri)
|
||||||
if (!mxid2.isEmpty())
|
if (!mxid2.isEmpty())
|
||||||
view_manager_->showEvent(
|
view_manager_->showEvent(
|
||||||
QString::fromStdString(roomid), mxid2);
|
QString::fromStdString(roomid), mxid2);
|
||||||
return;
|
return true;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (action == "join" || action.isEmpty()) {
|
if (action == "join" || action.isEmpty()) {
|
||||||
joinRoomVia(mxid1.toStdString(), vias);
|
joinRoomVia(mxid1.toStdString(), vias);
|
||||||
|
return true;
|
||||||
}
|
}
|
||||||
|
return false;
|
||||||
}
|
}
|
||||||
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
void
|
bool
|
||||||
ChatPage::handleMatrixUri(const QUrl &uri)
|
ChatPage::handleMatrixUri(const QUrl &uri)
|
||||||
{
|
{
|
||||||
handleMatrixUri(uri.toString(QUrl::ComponentFormattingOption::FullyEncoded).toUtf8());
|
return handleMatrixUri(
|
||||||
|
uri.toString(QUrl::ComponentFormattingOption::FullyEncoded).toUtf8());
|
||||||
}
|
}
|
||||||
|
|
||||||
bool
|
bool
|
||||||
|
|
|
@ -78,8 +78,8 @@ public:
|
||||||
QString currentRoom() const;
|
QString currentRoom() const;
|
||||||
|
|
||||||
public slots:
|
public slots:
|
||||||
void handleMatrixUri(const QByteArray &uri);
|
bool handleMatrixUri(const QByteArray &uri);
|
||||||
void handleMatrixUri(const QUrl &uri);
|
bool handleMatrixUri(const QUrl &uri);
|
||||||
|
|
||||||
void startChat(QString userid);
|
void startChat(QString userid);
|
||||||
void leaveRoom(const QString &room_id);
|
void leaveRoom(const QString &room_id);
|
||||||
|
|
|
@ -630,6 +630,23 @@ InputBar::command(QString command, QString args)
|
||||||
notice(args, false);
|
notice(args, false);
|
||||||
} else if (command == "rainbownotice") {
|
} else if (command == "rainbownotice") {
|
||||||
notice(args, true);
|
notice(args, true);
|
||||||
|
} else if (command == "goto") {
|
||||||
|
// Goto has three different modes:
|
||||||
|
// 1 - Going directly to a given event ID
|
||||||
|
if (args[0] == '$') {
|
||||||
|
room->showEvent(args);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
// 2 - Going directly to a given message index
|
||||||
|
if (args[0] >= '0' && args[0] <= '9') {
|
||||||
|
room->showEvent(args);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
// 3 - Matrix URI handler, as if you clicked the URI
|
||||||
|
if (ChatPage::instance()->handleMatrixUri(args)) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
nhlog::net()->error("Could not resolve goto: {}", args.toStdString());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -1534,11 +1534,25 @@ void
|
||||||
TimelineModel::showEvent(QString eventId)
|
TimelineModel::showEvent(QString eventId)
|
||||||
{
|
{
|
||||||
using namespace std::chrono_literals;
|
using namespace std::chrono_literals;
|
||||||
if (idToIndex(eventId) != -1) {
|
// Direct to eventId
|
||||||
|
if (eventId[0] == '$') {
|
||||||
|
int idx = idToIndex(eventId);
|
||||||
|
if (idx == -1) {
|
||||||
|
nhlog::ui()->warn("Scrolling to event id {}, failed - no known index",
|
||||||
|
eventId.toStdString());
|
||||||
|
return;
|
||||||
|
}
|
||||||
eventIdToShow = eventId;
|
eventIdToShow = eventId;
|
||||||
emit scrollTargetChanged();
|
emit scrollTargetChanged();
|
||||||
showEventTimer.start(50ms);
|
showEventTimer.start(50ms);
|
||||||
|
return;
|
||||||
}
|
}
|
||||||
|
// to message index
|
||||||
|
eventId = indexToId(eventId.toInt());
|
||||||
|
eventIdToShow = eventId;
|
||||||
|
emit scrollTargetChanged();
|
||||||
|
showEventTimer.start(50ms);
|
||||||
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
void
|
void
|
||||||
|
|
|
@ -57,48 +57,8 @@ void
|
||||||
Nheko::openLink(QString link) const
|
Nheko::openLink(QString link) const
|
||||||
{
|
{
|
||||||
QUrl url(link);
|
QUrl url(link);
|
||||||
if (url.scheme() == "https" && url.host() == "matrix.to") {
|
// Open externally if we couldn't handle it internally
|
||||||
// handle matrix.to links internally
|
if (!ChatPage::instance()->handleMatrixUri(url)) {
|
||||||
QString p = url.fragment(QUrl::FullyEncoded);
|
|
||||||
if (p.startsWith("/"))
|
|
||||||
p.remove(0, 1);
|
|
||||||
|
|
||||||
auto temp = p.split("?");
|
|
||||||
QString query;
|
|
||||||
if (temp.size() >= 2)
|
|
||||||
query = QUrl::fromPercentEncoding(temp.takeAt(1).toUtf8());
|
|
||||||
|
|
||||||
temp = temp.first().split("/");
|
|
||||||
auto identifier = QUrl::fromPercentEncoding(temp.takeFirst().toUtf8());
|
|
||||||
QString eventId = QUrl::fromPercentEncoding(temp.join('/').toUtf8());
|
|
||||||
if (!identifier.isEmpty()) {
|
|
||||||
if (identifier.startsWith("@")) {
|
|
||||||
QByteArray uri =
|
|
||||||
"matrix:u/" + QUrl::toPercentEncoding(identifier.remove(0, 1));
|
|
||||||
if (!query.isEmpty())
|
|
||||||
uri.append("?" + query.toUtf8());
|
|
||||||
ChatPage::instance()->handleMatrixUri(QUrl::fromEncoded(uri));
|
|
||||||
} else if (identifier.startsWith("#")) {
|
|
||||||
QByteArray uri =
|
|
||||||
"matrix:r/" + QUrl::toPercentEncoding(identifier.remove(0, 1));
|
|
||||||
if (!eventId.isEmpty())
|
|
||||||
uri.append("/e/" +
|
|
||||||
QUrl::toPercentEncoding(eventId.remove(0, 1)));
|
|
||||||
if (!query.isEmpty())
|
|
||||||
uri.append("?" + query.toUtf8());
|
|
||||||
ChatPage::instance()->handleMatrixUri(QUrl::fromEncoded(uri));
|
|
||||||
} else if (identifier.startsWith("!")) {
|
|
||||||
QByteArray uri = "matrix:roomid/" +
|
|
||||||
QUrl::toPercentEncoding(identifier.remove(0, 1));
|
|
||||||
if (!eventId.isEmpty())
|
|
||||||
uri.append("/e/" +
|
|
||||||
QUrl::toPercentEncoding(eventId.remove(0, 1)));
|
|
||||||
if (!query.isEmpty())
|
|
||||||
uri.append("?" + query.toUtf8());
|
|
||||||
ChatPage::instance()->handleMatrixUri(QUrl::fromEncoded(uri));
|
|
||||||
}
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
QDesktopServices::openUrl(url);
|
QDesktopServices::openUrl(url);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue