summary refs log tree commit diff
path: root/src/timeline
diff options
context:
space:
mode:
authorThulinma <jaron@vietors.com>2021-09-16 01:41:55 +0200
committerThulinma <jaron@vietors.com>2021-09-16 02:17:07 +0200
commit1d5bf56cf9dc8aea4aa849ef5f0f580c1eae4cdd (patch)
tree6ac1329f05c014027285cad360ec0c09b972ffdc /src/timeline
parentWorkaround for broken fetchMore() with reuseItems (diff)
downloadnheko-1d5bf56cf9dc8aea4aa849ef5f0f580c1eae4cdd.tar.xz
Improvements for linking to events
- Fixes scrolling to an event not being reliable
- Adds new /goto command that can open URLs, go to events, or go to message indexes.
- Refactored ChatPage::handleMatrixUri() to contain the handling originally in Nheko::openLink(), and makes it return a boolean based on whether the URL was handled internally or not.
Diffstat (limited to 'src/timeline')
-rw-r--r--src/timeline/InputBar.cpp17
-rw-r--r--src/timeline/TimelineModel.cpp16
2 files changed, 32 insertions, 1 deletions
diff --git a/src/timeline/InputBar.cpp b/src/timeline/InputBar.cpp

index ece9db62..a6fbab78 100644 --- a/src/timeline/InputBar.cpp +++ b/src/timeline/InputBar.cpp
@@ -630,6 +630,23 @@ InputBar::command(QString command, QString args) notice(args, false); } else if (command == "rainbownotice") { 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()); } } diff --git a/src/timeline/TimelineModel.cpp b/src/timeline/TimelineModel.cpp
index e03c32a7..00f6d9df 100644 --- a/src/timeline/TimelineModel.cpp +++ b/src/timeline/TimelineModel.cpp
@@ -1534,11 +1534,25 @@ void TimelineModel::showEvent(QString eventId) { 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; emit scrollTargetChanged(); showEventTimer.start(50ms); + return; } + // to message index + eventId = indexToId(eventId.toInt()); + eventIdToShow = eventId; + emit scrollTargetChanged(); + showEventTimer.start(50ms); + return; } void