diff --git a/retroshare-qml-app/src/qml/ChatView.qml b/retroshare-qml-app/src/qml/ChatView.qml index 21d1eab22..27b40461b 100644 --- a/retroshare-qml-app/src/qml/ChatView.qml +++ b/retroshare-qml-app/src/qml/ChatView.qml @@ -24,17 +24,28 @@ Item { id: chatView property string chatId + property int token: 0 function refreshData() { + console.log("chatView.refreshData()", visible) + if(!visible) return + rsApi.request( "/chat/messages/"+chatId, "", function(par) { chatModel.json = par.response - if(visible) rsApi.request("/chat/mark_chat_as_read/"+chatId, "", - null) + token = JSON.parse(par.response).statetoken + mainWindow.registerToken(token, refreshData) + + if(chatListView.visible) + { + chatListView.positionViewAtEnd() + rsApi.request("/chat/mark_chat_as_read/"+chatId) + } } ) } + Component.onCompleted: refreshData() onFocusChanged: focus && refreshData() JSONListModel @@ -59,6 +70,7 @@ Item ListView { + id: chatListView width: parent.width height: 300 model: chatModel.model @@ -87,14 +99,4 @@ Item function(par) { msgComposer.text = ""; } ) } } - - Timer - { - id: refreshTimer - interval: 800 - repeat: true - triggeredOnStart: true - onTriggered: if(chatView.visible) chatView.refreshData() - Component.onCompleted: start() - } }