parent
f91079ca43
commit
5903fbc4da
2 changed files with 32 additions and 14 deletions
|
@ -106,7 +106,6 @@ Item {
|
||||||
height: parent.height - Theme.paddingSmall
|
height: parent.height - Theme.paddingSmall
|
||||||
anchors.centerIn: parent
|
anchors.centerIn: parent
|
||||||
source: profileThumbnail.photoData.local.path
|
source: profileThumbnail.photoData.local.path
|
||||||
|
|
||||||
fillMode: Image.PreserveAspectCrop
|
fillMode: Image.PreserveAspectCrop
|
||||||
autoTransform: true
|
autoTransform: true
|
||||||
asynchronous: true
|
asynchronous: true
|
||||||
|
|
|
@ -270,18 +270,13 @@ Page {
|
||||||
console.log("[ChatPage] Messages received, view has " + chatView.count + " messages, setting view to index " + modelIndex + ", own messages were read before index " + lastReadSentIndex);
|
console.log("[ChatPage] Messages received, view has " + chatView.count + " messages, setting view to index " + modelIndex + ", own messages were read before index " + lastReadSentIndex);
|
||||||
if(totalCount === 0) {
|
if(totalCount === 0) {
|
||||||
console.log("[ChatPage] actually, skipping that: No Messages in Chat.");
|
console.log("[ChatPage] actually, skipping that: No Messages in Chat.");
|
||||||
|
|
||||||
chatView.positionViewAtEnd();
|
chatView.positionViewAtEnd();
|
||||||
chatPage.loading = false;
|
chatPage.loading = false;
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
chatView.lastReadSentIndex = lastReadSentIndex;
|
chatView.lastReadSentIndex = lastReadSentIndex;
|
||||||
if (modelIndex === (chatView.count - 1)) {
|
chatView.scrollToIndex(modelIndex);
|
||||||
chatView.positionViewAtEnd();
|
|
||||||
} else {
|
|
||||||
chatView.positionViewAtIndex(modelIndex, ListView.Beginning);
|
|
||||||
}
|
|
||||||
chatPage.loading = false;
|
chatPage.loading = false;
|
||||||
if (chatView.height > chatView.contentHeight) {
|
if (chatView.height > chatView.contentHeight) {
|
||||||
console.log("[ChatPage] Chat content quite small...");
|
console.log("[ChatPage] Chat content quite small...");
|
||||||
|
@ -289,9 +284,9 @@ Page {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
onNewMessageReceived: {
|
onNewMessageReceived: {
|
||||||
if (message.sender_user_id === chatPage.myUserId) {
|
if (chatView.manuallyScrolledToBottom || message.sender_user_id === chatPage.myUserId) {
|
||||||
console.log("[ChatPage] Own message received, scrolling down to see it...");
|
console.log("[ChatPage] Own message received or was scrolled to bottom, scrolling down to see it...");
|
||||||
chatView.scrollToBottom();
|
chatView.scrollToIndex(chatView.count - 1);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
onUnreadCountUpdated: {
|
onUnreadCountUpdated: {
|
||||||
|
@ -306,7 +301,6 @@ Page {
|
||||||
}
|
}
|
||||||
onMessagesIncrementalUpdate: {
|
onMessagesIncrementalUpdate: {
|
||||||
console.log("Incremental update received. View now has " + chatView.count + " messages, view is on index " + modelIndex + ", own messages were read before index " + lastReadSentIndex);
|
console.log("Incremental update received. View now has " + chatView.count + " messages, view is on index " + modelIndex + ", own messages were read before index " + lastReadSentIndex);
|
||||||
chatView.currentIndex = modelIndex;
|
|
||||||
chatView.lastReadSentIndex = lastReadSentIndex;
|
chatView.lastReadSentIndex = lastReadSentIndex;
|
||||||
chatViewCooldownTimer.start();
|
chatViewCooldownTimer.start();
|
||||||
}
|
}
|
||||||
|
@ -475,13 +469,34 @@ Page {
|
||||||
opacity: chatPage.loading ? 0 : 1
|
opacity: chatPage.loading ? 0 : 1
|
||||||
Behavior on opacity { NumberAnimation {} }
|
Behavior on opacity { NumberAnimation {} }
|
||||||
clip: true
|
clip: true
|
||||||
|
highlightMoveDuration: 0
|
||||||
|
highlightResizeDuration: 0
|
||||||
|
highlightRangeMode: ListView.ApplyRange
|
||||||
|
preferredHighlightBegin: 0
|
||||||
|
preferredHighlightEnd: height
|
||||||
|
highlight: Component {Item { } }
|
||||||
property int lastReadSentIndex: 0
|
property int lastReadSentIndex: 0
|
||||||
property bool inCooldown: false
|
property bool inCooldown: false
|
||||||
|
property bool manuallyScrolledToBottom
|
||||||
|
|
||||||
function handleScrollPositionChanged() {
|
function handleScrollPositionChanged() {
|
||||||
console.log("Current position: " + chatView.contentY);
|
console.log("Current position: " + chatView.contentY);
|
||||||
tdLibWrapper.viewMessage(chatInformation.id, chatView.itemAt(chatView.contentX, ( chatView.contentY + chatView.height - Theme.horizontalPageMargin )).myMessage.id, false);
|
if(chatInformation.unread_count > 0) {
|
||||||
|
var bottomItem = chatView.itemAt(chatView.contentX, ( chatView.contentY + chatView.height - Theme.horizontalPageMargin ));
|
||||||
|
if(typeof bottomItem !== "undefined") {
|
||||||
|
tdLibWrapper.viewMessage(chatInformation.id, bottomItem.myMessage.id, false);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
manuallyScrolledToBottom = chatView.atYEnd
|
||||||
|
}
|
||||||
|
|
||||||
|
function scrollToIndex(index) {
|
||||||
|
if(index > 0 && index < chatView.count) {
|
||||||
|
currentIndex = index;
|
||||||
|
if(index === chatView.count - 1) {
|
||||||
|
manuallyScrolledToBottom = true;
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
onContentYChanged: {
|
onContentYChanged: {
|
||||||
|
@ -499,6 +514,10 @@ Page {
|
||||||
onQuickScrollAnimatingChanged: {
|
onQuickScrollAnimatingChanged: {
|
||||||
if (!quickScrollAnimating) {
|
if (!quickScrollAnimating) {
|
||||||
handleScrollPositionChanged();
|
handleScrollPositionChanged();
|
||||||
|
if(atYEnd) { // handle some false guesses from quick scroll
|
||||||
|
chatView.scrollToIndex(chatView.count - 2)
|
||||||
|
chatView.scrollToIndex(chatView.count - 1)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -941,7 +960,7 @@ Page {
|
||||||
MouseArea {
|
MouseArea {
|
||||||
anchors.fill: parent
|
anchors.fill: parent
|
||||||
onClicked: {
|
onClicked: {
|
||||||
chatView.positionViewAtIndex(chatView.count - 1 - chatInformation.unread_count, ListView.Beginning);
|
chatView.scrollToIndex(chatView.count - 1 - chatInformation.unread_count)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue