summary refs log tree commit diff
path: root/src/timeline
diff options
context:
space:
mode:
authorNicolas Werner <nicolas.werner@hotmail.de>2021-04-29 19:09:16 +0200
committerNicolas Werner <nicolas.werner@hotmail.de>2021-04-29 19:09:16 +0200
commit82fa8ab292dc6e3a5a891f3b17c53236911374d1 (patch)
tree5fa4bdff6818190d93dc3cc33a2998e91c798122 /src/timeline
parentFix some encoding issues when translating matrix.to to matrix: (diff)
downloadnheko-82fa8ab292dc6e3a5a891f3b17c53236911374d1.tar.xz
Highlight navigated to message
Diffstat (limited to 'src/timeline')
-rw-r--r--src/timeline/TimelineModel.cpp38
-rw-r--r--src/timeline/TimelineModel.h14
-rw-r--r--src/timeline/TimelineViewManager.cpp16
-rw-r--r--src/timeline/TimelineViewManager.h1
4 files changed, 69 insertions, 0 deletions
diff --git a/src/timeline/TimelineModel.cpp b/src/timeline/TimelineModel.cpp
index 30ce176e..5a0f9bad 100644
--- a/src/timeline/TimelineModel.cpp
+++ b/src/timeline/TimelineModel.cpp
@@ -265,6 +265,8 @@ TimelineModel::TimelineModel(TimelineViewManager *manager, QString room_id, QObj
         connect(&events, &EventStore::updateFlowEventId, this, [this](std::string event_id) {
                 this->updateFlowEventId(event_id);
         });
+
+        showEventTimer.callOnTimeout(this, &TimelineModel::scrollTimerEvent);
 }
 
 QHash<int, QByteArray>
@@ -1298,6 +1300,42 @@ TimelineModel::cacheMedia(QString eventId)
         cacheMedia(eventId, NULL);
 }
 
+void
+TimelineModel::showEvent(QString eventId)
+{
+        using namespace std::chrono_literals;
+        if (idToIndex(eventId) != -1) {
+                eventIdToShow = eventId;
+                emit scrollTargetChanged();
+                showEventTimer.start(50ms);
+        }
+}
+
+void
+TimelineModel::eventShown()
+{
+        eventIdToShow.clear();
+        emit scrollTargetChanged();
+}
+
+QString
+TimelineModel::scrollTarget() const
+{
+        return eventIdToShow;
+}
+
+void
+TimelineModel::scrollTimerEvent()
+{
+        if (eventIdToShow.isEmpty() || showEventTimerCounter > 3) {
+                showEventTimer.stop();
+                showEventTimerCounter = 0;
+        } else {
+                emit scrollToIndex(idToIndex(eventIdToShow));
+                showEventTimerCounter++;
+        }
+}
+
 QString
 TimelineModel::formatTypingUsers(const std::vector<QString> &users, QColor bg)
 {
diff --git a/src/timeline/TimelineModel.h b/src/timeline/TimelineModel.h
index fbe963d2..f46409b3 100644
--- a/src/timeline/TimelineModel.h
+++ b/src/timeline/TimelineModel.h
@@ -9,6 +9,7 @@
 #include <QDate>
 #include <QHash>
 #include <QSet>
+#include <QTimer>
 
 #include <mtxclient/http/errors.hpp>
 
@@ -149,6 +150,7 @@ class TimelineModel : public QAbstractListModel
           int currentIndex READ currentIndex WRITE setCurrentIndex NOTIFY currentIndexChanged)
         Q_PROPERTY(std::vector<QString> typingUsers READ typingUsers WRITE updateTypingUsers NOTIFY
                      typingUsersChanged)
+        Q_PROPERTY(QString scrollTarget READ scrollTarget NOTIFY scrollTargetChanged)
         Q_PROPERTY(QString reply READ reply WRITE setReply NOTIFY replyChanged RESET resetReply)
         Q_PROPERTY(QString edit READ edit WRITE setEdit NOTIFY editChanged RESET resetEdit)
         Q_PROPERTY(
@@ -232,6 +234,7 @@ public:
         Q_INVOKABLE void openMedia(QString eventId);
         Q_INVOKABLE void cacheMedia(QString eventId);
         Q_INVOKABLE bool saveMedia(QString eventId) const;
+        Q_INVOKABLE void showEvent(QString eventId);
         void cacheMedia(QString eventId, std::function<void(const QString filename)> callback);
 
         std::vector<::Reaction> reactions(const std::string &event_id)
@@ -253,6 +256,7 @@ public:
 public slots:
         void setCurrentIndex(int index);
         int currentIndex() const { return idToIndex(currentId); }
+        void eventShown();
         void markEventsAsRead(const std::vector<QString> &event_ids);
         QVariantMap getDump(QString eventId, QString relatedTo) const;
         void updateTypingUsers(const std::vector<QString> &users)
@@ -298,8 +302,11 @@ public slots:
         QString roomAvatarUrl() const;
         QString roomId() const { return room_id_; }
 
+        QString scrollTarget() const;
+
 private slots:
         void addPendingMessage(mtx::events::collections::TimelineEvents event);
+        void scrollTimerEvent();
 
 signals:
         void currentIndexChanged(int index);
@@ -312,6 +319,7 @@ signals:
         void editChanged(QString reply);
         void paginationInProgressChanged(const bool);
         void newCallEvent(const mtx::events::collections::TimelineEvents &event);
+        void scrollToIndex(int index);
 
         void openProfile(UserProfile *profile);
         void openRoomSettingsDialog(RoomSettings *settings);
@@ -325,6 +333,8 @@ signals:
         void roomAvatarUrlChanged();
         void forwardToRoom(mtx::events::collections::TimelineEvents *e, QString roomId);
 
+        void scrollTargetChanged();
+
 private:
         template<typename T>
         void sendEncryptedMessage(mtx::events::RoomEvent<T> msg, mtx::events::EventType eventType);
@@ -350,6 +360,10 @@ private:
 
         InputBar input_{this};
 
+        QTimer showEventTimer{this};
+        QString eventIdToShow;
+        int showEventTimerCounter = 0;
+
         friend struct SendMessageVisitor;
 };
 
diff --git a/src/timeline/TimelineViewManager.cpp b/src/timeline/TimelineViewManager.cpp
index 648b499d..99f0b86e 100644
--- a/src/timeline/TimelineViewManager.cpp
+++ b/src/timeline/TimelineViewManager.cpp
@@ -404,6 +404,22 @@ TimelineViewManager::highlightRoom(const QString &room_id)
         ChatPage::instance()->highlightRoom(room_id);
 }
 
+void
+TimelineViewManager::showEvent(const QString &room_id, const QString &event_id)
+{
+        auto room = models.find(room_id);
+        if (room != models.end()) {
+                if (timeline_ != room.value().data()) {
+                        timeline_ = room.value().data();
+                        emit activeTimelineChanged(timeline_);
+                        container->setFocus();
+                        nhlog::ui()->info("Activated room {}", room_id.toStdString());
+                }
+
+                timeline_->showEvent(event_id);
+        }
+}
+
 QString
 TimelineViewManager::escapeEmoji(QString str) const
 {
diff --git a/src/timeline/TimelineViewManager.h b/src/timeline/TimelineViewManager.h
index 9703ee56..aa24b220 100644
--- a/src/timeline/TimelineViewManager.h
+++ b/src/timeline/TimelineViewManager.h
@@ -106,6 +106,7 @@ public slots:
 
         void setHistoryView(const QString &room_id);
         void highlightRoom(const QString &room_id);
+        void showEvent(const QString &room_id, const QString &event_id);
         void focusTimeline();
         TimelineModel *getHistoryView(const QString &room_id)
         {