From fce213a4328b049b48842cb624a30c17788bb08c Mon Sep 17 00:00:00 2001 From: Black Hat Date: Mon, 22 Oct 2018 09:48:37 +0800 Subject: [PATCH] Init scroll to eventid. --- imports/Spectral/Page/Room.qml | 11 ++++++----- imports/Spectral/Panel/RoomPanel.qml | 6 ++++++ imports/Spectral/Panel/RoomPanelForm.ui.qml | 1 + qml/main.qml | 1 + src/messageeventmodel.cpp | 9 +++++++++ src/messageeventmodel.h | 2 ++ 6 files changed, 25 insertions(+), 5 deletions(-) diff --git a/imports/Spectral/Page/Room.qml b/imports/Spectral/Page/Room.qml index c928529..3cf6980 100644 --- a/imports/Spectral/Page/Room.qml +++ b/imports/Spectral/Page/Room.qml @@ -29,10 +29,8 @@ Page { anchors.fill: parent RoomListPanel { -// Layout.fillHeight: true width: page.width * 0.35 Layout.minimumWidth: 64 -// Layout.maximumWidth: 360 id: roomListForm @@ -47,18 +45,21 @@ Page { z: source.z - 1 source: parent - elevation: 2 + elevation: 4 } } RoomPanel { Layout.fillWidth: true - Layout.minimumWidth: 360 -// Layout.fillHeight: true + Layout.minimumWidth: 480 id: roomForm currentRoom: roomListForm.enteredRoom } } + + function goToEvent(eventID) { + roomForm.goToEvent(eventID) + } } diff --git a/imports/Spectral/Panel/RoomPanel.qml b/imports/Spectral/Panel/RoomPanel.qml index 60b36d7..f1d30f8 100644 --- a/imports/Spectral/Panel/RoomPanel.qml +++ b/imports/Spectral/Panel/RoomPanel.qml @@ -40,4 +40,10 @@ RoomPanelForm { } goTopFab.onClicked: messageListView.positionViewAtBeginning() + + function goToEvent(eventID) { + var index = messageEventModel.eventIDToIndex(eventID) + if (index === -1) return + messageListView.currentIndex = sortedMessageEventModel.mapFromSource(index) + } } diff --git a/imports/Spectral/Panel/RoomPanelForm.ui.qml b/imports/Spectral/Panel/RoomPanelForm.ui.qml index 968a7d6..9163c30 100644 --- a/imports/Spectral/Panel/RoomPanelForm.ui.qml +++ b/imports/Spectral/Panel/RoomPanelForm.ui.qml @@ -22,6 +22,7 @@ Item { property alias roomHeader: roomHeader property alias messageListView: messageListView property alias goTopFab: goTopFab + property alias messageEventModel: messageEventModel property alias sortedMessageEventModel: sortedMessageEventModel property alias roomDrawer: roomDrawer diff --git a/qml/main.qml b/qml/main.qml index d373823..0475737 100644 --- a/qml/main.qml +++ b/qml/main.qml @@ -55,6 +55,7 @@ ApplicationWindow { onNotificationClicked: { roomPage.enteredRoom = currentConnection.room(roomId) + roomPage.goToEvent(eventId) showWindow() } onErrorOccured: { diff --git a/src/messageeventmodel.cpp b/src/messageeventmodel.cpp index ac8d2d7..0340224 100644 --- a/src/messageeventmodel.cpp +++ b/src/messageeventmodel.cpp @@ -470,3 +470,12 @@ QVariant MessageEventModel::data(const QModelIndex& idx, int role) const { return {}; } + +int MessageEventModel::eventIDToIndex(const QString& eventID) { + const auto it = m_currentRoom->findInTimeline(eventID); + if (it == m_currentRoom->timelineEdge()) { + qWarning() << "Trying to find inexistent event:" << eventID; + return -1; + } + return it - m_currentRoom->messageEvents().rbegin() + timelineBaseIndex(); +} diff --git a/src/messageeventmodel.h b/src/messageeventmodel.h index 6ab3ac5..f142a7c 100644 --- a/src/messageeventmodel.h +++ b/src/messageeventmodel.h @@ -45,6 +45,8 @@ class MessageEventModel : public QAbstractListModel { int role = Qt::DisplayRole) const override; QHash roleNames() const override; + Q_INVOKABLE int eventIDToIndex(const QString& eventID); + private slots: int refreshEvent(const QString& eventId); void refreshRow(int row);