mirror of
https://github.com/RetroShare/RetroShare.git
synced 2025-07-16 19:28:48 -04:00
ChatView.qml get rid of polling
Autoscroll to last message on update
This commit is contained in:
parent
2786cec76a
commit
7d9e89e3d2
1 changed files with 14 additions and 12 deletions
|
@ -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()
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue