mirror of
https://github.com/RetroShare/RetroShare.git
synced 2024-10-01 02:35:48 -04:00
ChatView.qml get rid of polling
Autoscroll to last message on update
This commit is contained in:
parent
2786cec76a
commit
7d9e89e3d2
@ -24,17 +24,28 @@ Item
|
|||||||
{
|
{
|
||||||
id: chatView
|
id: chatView
|
||||||
property string chatId
|
property string chatId
|
||||||
|
property int token: 0
|
||||||
|
|
||||||
function refreshData()
|
function refreshData()
|
||||||
{
|
{
|
||||||
|
console.log("chatView.refreshData()", visible)
|
||||||
|
if(!visible) return
|
||||||
|
|
||||||
rsApi.request( "/chat/messages/"+chatId, "", function(par)
|
rsApi.request( "/chat/messages/"+chatId, "", function(par)
|
||||||
{
|
{
|
||||||
chatModel.json = par.response
|
chatModel.json = par.response
|
||||||
if(visible) rsApi.request("/chat/mark_chat_as_read/"+chatId, "",
|
token = JSON.parse(par.response).statetoken
|
||||||
null)
|
mainWindow.registerToken(token, refreshData)
|
||||||
|
|
||||||
|
if(chatListView.visible)
|
||||||
|
{
|
||||||
|
chatListView.positionViewAtEnd()
|
||||||
|
rsApi.request("/chat/mark_chat_as_read/"+chatId)
|
||||||
|
}
|
||||||
} )
|
} )
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Component.onCompleted: refreshData()
|
||||||
onFocusChanged: focus && refreshData()
|
onFocusChanged: focus && refreshData()
|
||||||
|
|
||||||
JSONListModel
|
JSONListModel
|
||||||
@ -59,6 +70,7 @@ Item
|
|||||||
|
|
||||||
ListView
|
ListView
|
||||||
{
|
{
|
||||||
|
id: chatListView
|
||||||
width: parent.width
|
width: parent.width
|
||||||
height: 300
|
height: 300
|
||||||
model: chatModel.model
|
model: chatModel.model
|
||||||
@ -87,14 +99,4 @@ Item
|
|||||||
function(par) { msgComposer.text = ""; } )
|
function(par) { msgComposer.text = ""; } )
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
Timer
|
|
||||||
{
|
|
||||||
id: refreshTimer
|
|
||||||
interval: 800
|
|
||||||
repeat: true
|
|
||||||
triggeredOnStart: true
|
|
||||||
onTriggered: if(chatView.visible) chatView.refreshData()
|
|
||||||
Component.onCompleted: start()
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user