2016-12-08 09:56:23 -05:00
|
|
|
import QtQuick 2.0
|
|
|
|
import QtQuick.Controls 1.4
|
|
|
|
import org.retroshare.qml_components.LibresapiLocalClient 1.0
|
|
|
|
|
|
|
|
Item
|
|
|
|
{
|
|
|
|
id: chatView
|
|
|
|
property string chatId
|
|
|
|
|
2016-12-10 14:23:30 -05:00
|
|
|
function refreshData() { rsApi.request("/chat/messages/"+ chatId, "", function(par) { chatModel.json = par.response }) }
|
2016-12-08 09:56:23 -05:00
|
|
|
|
|
|
|
onFocusChanged: focus && refreshData()
|
|
|
|
|
|
|
|
JSONListModel
|
|
|
|
{
|
|
|
|
id: chatModel
|
|
|
|
query: "$.data[*]"
|
|
|
|
}
|
|
|
|
|
|
|
|
Component
|
|
|
|
{
|
|
|
|
id: chatMessageDelegate
|
|
|
|
Item
|
|
|
|
{
|
|
|
|
height: 20
|
|
|
|
Row
|
|
|
|
{
|
|
|
|
Text { text: author_name }
|
|
|
|
Text { text: ": " + msg }
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
ListView
|
|
|
|
{
|
|
|
|
width: parent.width
|
|
|
|
height: 300
|
|
|
|
model: chatModel.model
|
|
|
|
delegate: chatMessageDelegate
|
|
|
|
}
|
|
|
|
|
|
|
|
Rectangle
|
|
|
|
{
|
|
|
|
color: "green"
|
|
|
|
anchors.bottom: parent.bottom
|
|
|
|
anchors.left: parent.left
|
|
|
|
width: chatView.width - sendButton.width
|
|
|
|
height: Math.max(20, msgComposer.height)
|
|
|
|
}
|
|
|
|
|
|
|
|
TextEdit
|
|
|
|
{
|
|
|
|
id: msgComposer
|
|
|
|
anchors.bottom: parent.bottom
|
|
|
|
anchors.left: parent.left
|
|
|
|
width: chatView.width - sendButton.width
|
|
|
|
}
|
|
|
|
|
|
|
|
Button
|
|
|
|
{
|
|
|
|
id: sendButton
|
|
|
|
text: "Send"
|
|
|
|
anchors.bottom: parent.bottom
|
|
|
|
anchors.right: parent.right
|
|
|
|
|
|
|
|
onClicked:
|
|
|
|
{
|
|
|
|
var jsonData = {"chat_id":chatView.chatId, "msg":msgComposer.text}
|
2016-12-22 07:49:13 -05:00
|
|
|
rsApi.request("/chat/send_message", JSON.stringify(jsonData), function(par) { msgComposer.text = ""; console.log(msg) })
|
2016-12-08 09:56:23 -05:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
Timer
|
|
|
|
{
|
|
|
|
id: refreshTimer
|
2016-12-10 14:23:30 -05:00
|
|
|
interval: 800
|
2016-12-08 09:56:23 -05:00
|
|
|
repeat: true
|
|
|
|
onTriggered: if(chatView.visible) chatView.refreshData()
|
|
|
|
Component.onCompleted: start()
|
|
|
|
}
|
|
|
|
}
|