diff --git a/imports/NeoChat/Component/ChatBox/ChatBox.qml b/imports/NeoChat/Component/ChatBox/ChatBox.qml index 0efa6af1e..72196c219 100644 --- a/imports/NeoChat/Component/ChatBox/ChatBox.qml +++ b/imports/NeoChat/Component/ChatBox/ChatBox.qml @@ -16,6 +16,7 @@ Item { property alias inputFieldText: chatBar.inputFieldText signal fancyEffectsReasonFound(string fancyEffect) + signal messageSent() Kirigami.Theme.colorSet: Kirigami.Theme.View @@ -150,6 +151,7 @@ Item { onMessageSent: { closeAll() checkForFancyEffectsReason() + root.messageSent(); } } diff --git a/imports/NeoChat/Page/RoomPage.qml b/imports/NeoChat/Page/RoomPage.qml index 1e2a0ffcf..440a41cee 100644 --- a/imports/NeoChat/Page/RoomPage.qml +++ b/imports/NeoChat/Page/RoomPage.qml @@ -567,8 +567,7 @@ Kirigami.ScrollablePage { if (currentRoom && currentRoom.hasUnreadMessages) { goToEvent(currentRoom.readMarkerEventId) } else { - currentRoom.markAllMessagesAsRead() - messageListView.positionViewAtBeginning() + goToLastMessage(); } } icon.name: currentRoom && currentRoom.hasUnreadMessages ? "go-up" : "go-down" @@ -654,6 +653,11 @@ Kirigami.ScrollablePage { footer: ChatBox { id: chatBox visible: !invitation.visible && !(messageListView.count === 0 && !currentRoom.allHistoryLoaded) + onMessageSent: { + if (!messageListView.atYEnd) { + goToLastMessage(); + } + } } background: FancyEffectsContainer { @@ -690,6 +694,12 @@ Kirigami.ScrollablePage { } } + function goToLastMessage() { + currentRoom.markAllMessagesAsRead() + // scroll to the very end, i.e to messageListView.YEnd + messageListView.positionViewAtIndex(0, ListView.End) + } + function goToEvent(eventID) { messageListView.positionViewAtIndex(eventToIndex(eventID), ListView.Contain) }