From fcc46fbc945b3a7d7001dfd00a4748a93c2ad71a Mon Sep 17 00:00:00 2001 From: "Sebastian J. Wolf" Date: Tue, 22 Sep 2020 20:32:35 +0200 Subject: [PATCH] Auto-scroll to message if user sent it --- harbour-fernschreiber.pro | 1 + qml/components/ProfileThumbnail.qml | 3 --- qml/pages/ChatPage.qml | 5 ++++- src/chatmodel.cpp | 2 +- src/chatmodel.h | 2 +- src/tdlibreceiver.cpp | 2 +- 6 files changed, 8 insertions(+), 7 deletions(-) diff --git a/harbour-fernschreiber.pro b/harbour-fernschreiber.pro index 20901a0..3a44be9 100644 --- a/harbour-fernschreiber.pro +++ b/harbour-fernschreiber.pro @@ -52,6 +52,7 @@ SAILFISHAPP_ICONS = 86x86 108x108 128x128 172x172 256x256 TRANSLATIONS += translations/harbour-fernschreiber-de.ts \ translations/harbour-fernschreiber-es.ts \ + translations/harbour-fernschreiber-pl.ts \ translations/harbour-fernschreiber-zh_CN.ts LIBS += -L$$PWD/tdlib/lib/ -ltdjson diff --git a/qml/components/ProfileThumbnail.qml b/qml/components/ProfileThumbnail.qml index fc7828f..a24bf14 100644 --- a/qml/components/ProfileThumbnail.qml +++ b/qml/components/ProfileThumbnail.qml @@ -137,9 +137,6 @@ Item { asynchronous: true width: parent.width sourceComponent: profileImageComponent - onLoaded: { - console.log(profileThumbnail.photoData.local.path); - } } Item { diff --git a/qml/pages/ChatPage.qml b/qml/pages/ChatPage.qml index 359024f..4170abf 100644 --- a/qml/pages/ChatPage.qml +++ b/qml/pages/ChatPage.qml @@ -201,7 +201,10 @@ Page { } } onNewMessageReceived: { - // Notify user about new messages... + if (message.sender_user_id === chatPage.myUserId) { + console.log("[ChatPage] Own message received, scrolling down to see it..."); + chatView.scrollToBottom(); + } } onUnreadCountUpdated: { console.log("[ChatPage] Unread count updated, new count: " + unreadCount); diff --git a/src/chatmodel.cpp b/src/chatmodel.cpp index cd4c409..2eb9963 100644 --- a/src/chatmodel.cpp +++ b/src/chatmodel.cpp @@ -175,7 +175,7 @@ void ChatModel::handleNewMessageReceived(const QString &chatId, const QVariantMa this->insertMessages(); this->messagesMutex.unlock(); - emit newMessageReceived(); + emit newMessageReceived(message); } } diff --git a/src/chatmodel.h b/src/chatmodel.h index a345b6a..7f57c7b 100644 --- a/src/chatmodel.h +++ b/src/chatmodel.h @@ -44,7 +44,7 @@ public: signals: void messagesReceived(const int &modelIndex, const int &lastReadSentIndex); void messagesIncrementalUpdate(const int &modelIndex, const int &lastReadSentIndex); - void newMessageReceived(); + void newMessageReceived(const QVariantMap &message); void unreadCountUpdated(const int &unreadCount, const QString &lastReadInboxMessageId); void lastReadSentMessageUpdated(const int &lastReadSentIndex); void notificationSettingsUpdated(); diff --git a/src/tdlibreceiver.cpp b/src/tdlibreceiver.cpp index a78269e..61bc0c0 100644 --- a/src/tdlibreceiver.cpp +++ b/src/tdlibreceiver.cpp @@ -42,7 +42,7 @@ void TDLibReceiver::receiverLoop() const char *result = td_json_client_receive(this->tdLibClient, WAIT_TIMEOUT); if (result) { QJsonDocument receivedJsonDocument = QJsonDocument::fromJson(QByteArray(result)); - // Too much information... qDebug().noquote() << "[TDLibReceiver] Raw result: " << receivedJsonDocument.toJson(QJsonDocument::Indented); + qDebug().noquote() << "[TDLibReceiver] Raw result: " << receivedJsonDocument.toJson(QJsonDocument::Indented); processReceivedDocument(receivedJsonDocument); } }